import { useGetInputData } from "../hooks/useGetInputData";
import { Option } from "../types";

export const useInputOptions = (
  keys: string[]
): { key: string; options: Option[]; rawValue?: any }[] => {
  return keys.map((key) => {
    const { data } = useGetInputData(key);

    // if nationality → we handle it specially
    if (key === "nationality" && data?.payload?.value) {
      return {
        key,
        options: Object.keys(data.payload.value).map((countryName) => ({
          label: countryName,
          value: countryName.toLowerCase(),
        })),
        rawValue: data.payload.value, // pass raw country object
      };
    }

    if (key === "religion" && data?.payload?.value) {
      return {
        key,
        options: Object.keys(data.payload.value).map((religionName) => ({
          label: religionName,
          value: religionName.toLowerCase(),
          subcategories: data.payload.value[religionName].denominations.map(
            (denomination: any) => ({
              label: denomination,
              value: denomination.toLowerCase(),
            })
          ),
        })),
        rawValue: data.payload.value, // Pass full religion data
      };
    }

    // other keys → normal options
    const options: Option[] =
      data?.payload?.value.map((item: string) => ({
        label: item,
        value: item.toLowerCase(),
      })) || [];

    return { key, options };
  });
};
