"use client";

import { Field } from "formik";
import type { FormikErrors, FormikProps, FormikTouched } from "formik";

import Input from "@/components/ui/Input";
import RichTextEditor from "@/components/ui/RichTextEditor";
import TagsCheckbox from "@/components/ui/TagsCheckbox";
import type { EventFormValues } from "./eventFormTypes";
import type { useEventForm } from "./useEventForm";

/** Single description, interests and external registration link when required. */
export default function EventDetailsFields({
  screen,
  values,
  errors,
  touched,
  setFieldValue,
  setFieldTouched,
}: {
  screen: ReturnType<typeof useEventForm>;
  values: EventFormValues;
  errors: FormikErrors<EventFormValues>;
  touched: FormikTouched<EventFormValues>;
  setFieldValue: FormikProps<EventFormValues>["setFieldValue"];
  setFieldTouched: FormikProps<EventFormValues>["setFieldTouched"];
}) {
  const { t, tagOptions, tagsLoading } = screen;

  return (
    <>
      {values.participation_type &&
        values.participation_type_value_en !== "Free Event" && (
          <div className="w-full">
            <Input
              name="registration_link"
              label={t("COMMON.REGISTRATION_LINK")}
              type="text"
            />
          </div>
        )}

      <div className="descritpionitm descritpionitm-ar">
        <Field
          name="description_ar"
          label={t("COMMON.DESCRIPTION")}
          placeholder={t("COMMON.DESCRIPTION")}
          component={RichTextEditor}
        />
      </div>

      {/* No English description field (client, 2026-10-15): the Arabic
          one is sent as both — see `handleSubmit` in `useEventForm`. */}

      <TagsCheckbox
        name="_interests"
        label={t("COMMON.ENTER_TAGS")}
        setFieldValue={setFieldValue}
        setFieldTouched={setFieldTouched}
        values={values._interests}
        errors={errors._interests as string | undefined}
        touched={touched._interests as boolean | undefined}
        options={tagOptions}
        disabled={tagsLoading}
      />
    </>
  );
}
