"use client";

import Image from "next/image";
import { useTranslation } from "react-i18next";
import Input from "@/components/ui/Input";
import PhoneInput from "@/components/ui/PhoneInput";
import CountryCodeSelect from "./CountryCodeSelectLazy";
import { asset } from "./volunteerAccountConstants";
import type { OrganizerSectionProps } from "./organizerSectionProps";


/**
 * The account half: logo, organization name, nickname, contact and email.
 *
 * Saved through `updateAccountInfo`; everything below goes to the profile and\n * documents endpoints.
 */
export default function OrganizerAccountSection(props: OrganizerSectionProps) {
  const { t } = useTranslation();
  const {
    values,
    setFieldValue,
    profilePic,
    uploadError,
    handleFileSelection,
    fileInputRef,
    accountData,
  } = props;

  return (
    <>
                      {/* Account Information Section */}
                      <div>
                        <div className="relative w-[168px] h-[168px] mx-auto">
                          <Image
                            src={profilePic || asset("profile/org_profile.svg")}
                            alt={t("COMMON.PROFILE_PICTURE")}
                            fill
                            unoptimized
                            className="rounded-full border-[5px] border-[#29246D] object-cover"
                          />
                          <div className="absolute bottom-2 right-2">
                            <input
                              type="file"
                              id="fileUpload"
                              name="profile_pic_file"
                              className="hidden"
                              accept="image/png,image/jpeg,image/webp"
                              ref={fileInputRef}
                              onChange={handleFileSelection}
                            />
                            <label htmlFor="fileUpload" className="cursor-pointer">
                              <Image
                                src={asset("profile/uploadicon1.svg")}
                                alt={t("COMMON.UPLOAD_IMAGE")}
                                width={30}
                                height={30}
                                className="w-[30px] h-[30px]"
                              />
                            </label>
                            {uploadError && (
                              <p className="text-red-500 text-sm mt-2">
                                {uploadError}
                              </p>
                            )}
                          </div>
                        </div>

                        <div className="text-center pt-5 2xl:pb-[50px] lg:pb-[10px] pb-[20px]">
                          <Input
                            name="company_name"
                            type="text"
                            className="text-center text-primary-5 font-bold text-[25px] border-none focus:ring-0 bg-transparent p-0"
                            placeholder={t("COMMON.ENTER.FULL.NAME")}
                          />
                        </div>

                        <div className="flex mobilescreen:gap-2 mobilescreen:flex-col gap-4">
                          <div className="relative flex-1">
                            <Input
                              name="email"
                              type="text"
                              label={t("COMMON.EMAIL")}
                              value={accountData?.data?.email || ""}
                              disabled
                              className="pr-10"
                            />
                          </div>
                          <div className="relative flex-1">
                            <div className="flex gap-2">
                              <div>
                                <CountryCodeSelect
                                  name="country_code"
                                  className="w-full"
                                  onChange={(value: string) =>
                                    setFieldValue("country_code", value)
                                  }
                                />
                              </div>
                              <div className="w-full">
                                <PhoneInput
                                  name="phone_number"
                                  label={t("COMMON.PHONE_NUMBER")}
                                  className="pr-10"
                                  countryCode={values.country_code}
                                />
                              </div>
                            </div>
                          </div>
                        </div>

                        <div className="flex mobilescreen:gap-0 mobilescreen:flex-col gap-4">
                          <div className="relative flex-1">
                            <Input
                              name="license_number"
                              digitsOnly
                              inputMode="numeric"
                              maxLength={100}
                              type="text"
                              label={t("COMMON.ENTER_LICENSE_NUMBER")}
                            />
                          </div>
                        </div>
                      </div>
    </>
  );
}
