"use client";

import React from "react";
import Input from "@/components/ui/Input";
import SelectInput from "@/components/ui/SelectInput";
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 EventTitleTypeFields({
  screen,
  setFieldValue,
}: {
  screen: ReturnType<typeof useEventForm>;
  setFieldValue: FormikProps<EventFormValues>["setFieldValue"];
  setFieldTouched: FormikProps<EventFormValues>["setFieldTouched"];
}) {
  const {
    t,
    eventTypeLoading,
    participationTypeLoading,
    eventTypeOptions,
    participationTypeOptions,
  } = screen;

  return (
  <div className="flex gap-6 mobilescreen:gap-0 mobilescreen:flex-col miniscreen:flex-col miniscreen:gap-0">
    {/* Same as the opportunity form: one title, with the English one as
        an optional second answer behind a link. */}
    <div className="w-full">
      <Input
        name="title_ar"
        label={t("COMMON.ENTER_TITLE")}
        type="text"
        maxLength={100}
        dir="auto"
      />
    </div>
    <div className="flex w-full xss:flex-col gap-6 xss:gap-0">
      <SelectInput
        name="event_type"
        label={t("COMMON.EVENT.TYPE")}
        options={eventTypeOptions}
        onChange={(selectedOption) =>
          setFieldValue(
            "event_type",
            selectedOption?.value || ""
          )
        }
        disabled={eventTypeLoading}
      />
      <SelectInput
        name="participation_type"
        label={t("COMMON.PARTICIPATION_TYPE")}
        options={participationTypeOptions}
        onChange={(selectedOption) => {
          setFieldValue(
            "participation_type",
            selectedOption?.value || ""
          );
          setFieldValue(
            "participation_type_value_en",
            selectedOption?.value_en || ""
          );
        }}
        disabled={participationTypeLoading}
      />
    </div>
  </div>
  );
}
