"use client";
import { kuwaitDatePickerMinimum } from "@/features/shared/opportunityFormRules";

import EventLocationFields from "./EventLocationFields";

import React from "react";
import {
  Field,
  FieldProps,
} from "formik";
import SelectInput from "@/components/ui/SelectInput";
import DatePickerInput from "@/components/ui/DateField";
import TimepickerInput from "@/components/ui/TimePicker";
import AgeRange from "@/components/ui/AgeRange";
import type { FormikProps } from "formik";
import type { EventFormValues } from "./eventFormTypes";
import type { useEventForm } from "./useEventForm";

/** A field group lifted out of the form of the same family. */
export default function EventDesktopScheduleFields({
  screen,
  values,
  setFieldValue,
  autoSetTimeOnClick,
}: {
  screen: ReturnType<typeof useEventForm>;
  values: EventFormValues;
  setFieldValue: FormikProps<EventFormValues>["setFieldValue"];
  autoSetTimeOnClick: boolean;
}) {
  const {
    t,
    genderLoading,
    genderOptions,
  } = screen;

  return (
  <div className="lg:block md:hidden mobilescreen:hidden mediumscreen1:block">
    <div className="flex gap-6 mobilescreen:gap-0 mobilescreen:flex-col miniscreen:flex-col miniscreen:gap-0 xss:pt-0">
      <DatePickerInput
        name="startDate"
        label={t("COMMON.START_DATE")}
        rmdpClassname="placeholder-primary-5"
        minDate={kuwaitDatePickerMinimum()}
      />
      <DatePickerInput
        name="endDate"
        label={t("COMMON.END_DATE")}
        rmdpClassname="placeholder-primary-5"
        minDate={kuwaitDatePickerMinimum()}
      />
      <Field name="startTime">
        {({ field }: FieldProps<string, EventFormValues>) => (
          <TimepickerInput
            label={t("COMMON.START_TIME")}
            className="w-full"
            autoSetTime={autoSetTimeOnClick}
            {...field}
          />
        )}
      </Field>
      <Field name="endTime">
        {({ field }: FieldProps<string, EventFormValues>) => (
          <TimepickerInput
            label={t("COMMON.END_TIME")}
            className="w-full"
            autoSetTime={autoSetTimeOnClick}
            {...field}
          />
        )}
      </Field>
    </div>
    <div className="flex gap-6 mobilescreen:gap-0 mobilescreen:flex-col miniscreen:flex-col miniscreen:gap-0">
      <AgeRange name="age" label={t("COMMON.AGE")} />
      <SelectInput
        name="gender"
        label={t("COMMON.GENDERPLACEHOLDER")}
        options={genderOptions}
        onChange={(selectedOption) =>
          setFieldValue("gender", selectedOption?.value || "")
        }
        disabled={genderLoading}
      />
    </div>
    <div className="flex gap-6 mobilescreen:gap-0 mobilescreen:flex-col miniscreen:flex-col miniscreen:gap-0">
      <div className="flex-1">
        <EventLocationFields
          screen={screen}
          values={values}
          setFieldValue={setFieldValue}
        />
      </div>
    </div>
  </div>
  );
}
