import { RegisterOptions } from "react-hook-form";

export type ExperienceItem = {
  jobType: {
    code: string;
    value: string;
    label: string;
    continent: string;
  } | null;
  designation: string;
  companyName: string;
  companyWebsiteLink: string;
  startDate: string;
  endDate: string;
  jobRes: string;
  currentJob: boolean;
  variant?: "experience";
};

export type Inputs = {
  experience: ExperienceItem[];
  [key: string]: any;
};
export type VariantType = "experience";

export const getGridCols = (cols?: number) => {
  switch (cols) {
    case 2:
      return "grid-cols-2";
    case 3:
      return "grid-cols-3";
    case 4:
      return "grid-cols-4";
    default:
      return "grid-cols-1";
  }
};

export type OptionType = {
  id: number;
  uuid?: number;
  label: string;
  value?: string;
  name?: string;
};

export type Field =
  | {
      type: "input";
      name: string;
      placeHolder: string;
      isNumber?: boolean;
      maxLength?: number;
      rules?: RegisterOptions; // ← add this
    }
  | {
      type: "select";
      name: string;
      options?: OptionType[];
    }
  | {
      type: "dropdown";
      name: string;
      placeHolder: string;
      prefixText?: string;
      isSearchable?: boolean;
      options?: OptionType[];
      rules?: RegisterOptions; // ← add this
    }
  | {
      type: "date";
      name: string;
      label: string;
      dependsOn?: string;
      disableWhen?: boolean;
      allowFuture?: boolean;
    }
  | {
      type: "checkbox";
      name: string;
      title: string;
    }
  | {
      type: "textarea";
      name: string;
      placeHolder: string;
      maxLength?: number;
      rules?: RegisterOptions; // ← add this
    }
  | {
      type: "group";
      layout: "grid" | "flex";
      gridCols?: number;
      fields: Field[]; // recursive 🔥
    }
  | {
      type: "rating";
      name: string;
      label: string;
    }
  | {
      type: "fileUpload";
      name: string;
      accept: string; // comma-separated MIME types e.g. "application/pdf,image/png,image/jpeg"
      label: string;
      rules?: RegisterOptions;
    };

export type FieldsLayout = Record<VariantType, Field[]>;
