"use client";
import RegistrationDeadlineFields from "./RegistrationDeadlineFields";

import { Field, type FieldProps } from "formik";
import { useTranslation } from "react-i18next";

import LearnServeDateRangeField from "./LearnServeDateRangeField";
import TimepickerInput from "@/components/ui/TimePicker";
import type { LearnServeFormValues } from "./learnServeFormTypes";

interface LearnServeScheduleFieldsProps {
  /** Clicking a time field opens the picker rather than typing into it. */
  autoSetTimeOnClick: boolean;
}

/**
 * Column 2 of the field grid: when the opportunity runs.
 *
 * Due date, start and end, and the from/to time pair — which shares one column
 * because the two together answer a single question.
 */
export default function LearnServeScheduleFields({
  autoSetTimeOnClick,
}: LearnServeScheduleFieldsProps) {
  const { t } = useTranslation();

  return (
    <>
    {/* ---- Row 2: when it runs ---- */}
    {/* BE-122 — there is no close button any more, so the rule is said
        where the organizer sets the date that drives it. */}
    <RegistrationDeadlineFields />
    <LearnServeDateRangeField />
    <div className="flex gap-2">
      <Field name="startTime">
        {({
          field,
        }: FieldProps<string, LearnServeFormValues>) => (
          <TimepickerInput
            label={t("COMMON.START_TIME")}
            className="w-full"
            autoSetTime={autoSetTimeOnClick}
            {...field}
          />
        )}
      </Field>
      <Field name="endTime">
        {({
          field,
        }: FieldProps<string, LearnServeFormValues>) => (
          <TimepickerInput
            label={t("COMMON.END_TIME")}
            className="w-full"
            autoSetTime={autoSetTimeOnClick}
            {...field}
          />
        )}
      </Field>
    </div>

    </>
  );
}
