/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { DefaultSetupValues } from "@/Constant/enums"; import React, { useState, useEffect } from "react"; import PhoneInput from "react-phone-number-input"; import "react-phone-number-input/style.css"; // Import styles import flags from "react-phone-number-input/flags"; import { getCountryCallingCode } from "react-phone-number-input/input"; import { getCountries } from "react-phone-number-input/input"; import en from "react-phone-number-input/locale/en.json"; import type { CountryCode } from "libphonenumber-js/core"; import Select from "react-select"; import type { Props as SelectProps } from "react-select"; interface PhoneInputFieldProps { value?: string; onChange?: (value: string) => void; placeholder?: string; error?: string; className?: string; country?: string; // Optional country ISO2 code onCountryChange?: (country: string) => void; // Optional handler for country change noBorder?: boolean; hideError?: boolean; } const isCountryCode = (value?: string): value is CountryCode => { return !!value && getCountries().includes(value as CountryCode); }; const customLabels = getCountries().reduce( (acc, country) => { const countryName = en[country]; const callingCode = getCountryCallingCode(country); if (countryName && callingCode) { acc[country] = `${countryName} (+${callingCode})`; } return acc; }, { ...en } as Record, ); // 1. Custom country select component interface CountrySelectOption { value: string | undefined; label: string; } interface CustomCountrySelectProps extends Omit< SelectProps, "value" | "onChange" | "options" > { value?: string; onChange: (value?: string) => void; options: CountrySelectOption[]; } const CustomCountrySelect: React.FC = ({ value, onChange, options, ...rest }) => { // Find the selected option object const selectedOption = options.find((opt) => opt.value === value); // Custom styles for react-select (compact, transparent) const customStyles = { container: (provided: any) => ({ ...provided, width: "60px", // Compact and consistent height: "100%", }), control: (provided: any) => ({ ...provided, height: "100%", minHeight: "100%", border: "none", borderRadius: 0, boxShadow: "none", backgroundColor: "transparent", display: "flex", flexWrap: "nowrap", alignItems: "center", cursor: "pointer", }), indicatorsContainer: (provided: any) => ({ ...provided, padding: 0, }), dropdownIndicator: (provided: any) => ({ ...provided, padding: "0 2px 0 0", color: "#6c757d", }), indicatorSeparator: () => ({ display: "none", }), valueContainer: (provided: any) => ({ ...provided, padding: "0 0 0 4px", display: "flex", alignItems: "center", justifyContent: "center", }), input: (provided: any) => ({ ...provided, margin: 0, padding: 0, }), menu: (provided: any) => ({ ...provided, width: "300px", zIndex: 9999, }), menuPortal: (base: any) => ({ ...base, zIndex: 9999 }), option: (provided: any, state: any) => ({ ...provided, padding: "8px 12px", fontSize: "14px", backgroundColor: state.isFocused ? "#f8f9fa" : "#fff", color: "#222", cursor: "pointer", }), }; // Custom SingleValue component to show only the flag const SingleValue = (props: any) => { const countryCode = props.data.value as CountryCode; const Flag = countryCode ? flags[countryCode] : null; if (props.selectProps.inputValue) { return null; } return (
{Flag ? : "🌐"}
); }; return (