/**
 * Japanese Prefectures for address forms
 * Uses English names to match WHMCS state field expectations
 */

export interface PrefectureOption {
  value: string;
  label: string;
}

/**
 * All 47 Japanese prefectures
 * Values are English names as expected by WHMCS
 */
export const JAPAN_PREFECTURES: PrefectureOption[] = [
  { value: "Hokkaido", label: "Hokkaido" },
  { value: "Aomori", label: "Aomori" },
  { value: "Iwate", label: "Iwate" },
  { value: "Miyagi", label: "Miyagi" },
  { value: "Akita", label: "Akita" },
  { value: "Yamagata", label: "Yamagata" },
  { value: "Fukushima", label: "Fukushima" },
  { value: "Ibaraki", label: "Ibaraki" },
  { value: "Tochigi", label: "Tochigi" },
  { value: "Gunma", label: "Gunma" },
  { value: "Saitama", label: "Saitama" },
  { value: "Chiba", label: "Chiba" },
  { value: "Tokyo", label: "Tokyo" },
  { value: "Kanagawa", label: "Kanagawa" },
  { value: "Niigata", label: "Niigata" },
  { value: "Toyama", label: "Toyama" },
  { value: "Ishikawa", label: "Ishikawa" },
  { value: "Fukui", label: "Fukui" },
  { value: "Yamanashi", label: "Yamanashi" },
  { value: "Nagano", label: "Nagano" },
  { value: "Gifu", label: "Gifu" },
  { value: "Shizuoka", label: "Shizuoka" },
  { value: "Aichi", label: "Aichi" },
  { value: "Mie", label: "Mie" },
  { value: "Shiga", label: "Shiga" },
  { value: "Kyoto", label: "Kyoto" },
  { value: "Osaka", label: "Osaka" },
  { value: "Hyogo", label: "Hyogo" },
  { value: "Nara", label: "Nara" },
  { value: "Wakayama", label: "Wakayama" },
  { value: "Tottori", label: "Tottori" },
  { value: "Shimane", label: "Shimane" },
  { value: "Okayama", label: "Okayama" },
  { value: "Hiroshima", label: "Hiroshima" },
  { value: "Yamaguchi", label: "Yamaguchi" },
  { value: "Tokushima", label: "Tokushima" },
  { value: "Kagawa", label: "Kagawa" },
  { value: "Ehime", label: "Ehime" },
  { value: "Kochi", label: "Kochi" },
  { value: "Fukuoka", label: "Fukuoka" },
  { value: "Saga", label: "Saga" },
  { value: "Nagasaki", label: "Nagasaki" },
  { value: "Kumamoto", label: "Kumamoto" },
  { value: "Oita", label: "Oita" },
  { value: "Miyazaki", label: "Miyazaki" },
  { value: "Kagoshima", label: "Kagoshima" },
  { value: "Okinawa", label: "Okinawa" },
];

/**
 * Format Japanese postal code with hyphen
 * Input: "1234567" or "123-4567" or "1234" → Output: formatted string
 */
export function formatJapanesePostalCode(value: string): string {
  const digits = value.replace(/\D/g, "");

  if (digits.length <= 3) {
    return digits;
  }

  if (digits.length <= 7) {
    return `${digits.slice(0, 3)}-${digits.slice(3)}`;
  }

  return `${digits.slice(0, 3)}-${digits.slice(3, 7)}`;
}
