{"version":3,"file":"InternalLocaleSelector.cjs","names":[],"sources":["../../../src/components/helpers/InternalLocaleSelector.tsx"],"sourcesContent":["import React from 'react';\nimport { CustomMapping, LocaleProperties } from 'generaltranslation/types';\n\n/**\n * Capitalizes the first letter of a string if applicable.\n * For strings that do not use capitalization, it returns the string unchanged.\n * @param {string} str - The string to capitalize.\n * @returns {string} The string with the first letter capitalized if applicable.\n */\nfunction capitalizeName(str: string): string {\n  if (!str) return '';\n  return str.charAt(0).toUpperCase() + (str.length > 1 ? str.slice(1) : '');\n}\n\n/**\n * Internal helper to convert deprecated customNames prop to the new customMapping format.\n * Used for backward compatibility with previous LocaleSelector API.\n * @param {object} customNames - Mapping of locale to display name.\n * @returns {CustomMapping | undefined} The converted mapping or undefined.\n * @internal\n */\nfunction _convertCustomNamesToMapping(\n  customNames?: { [key: string]: string } | undefined\n): CustomMapping | undefined {\n  if (!customNames) return undefined;\n  const result: CustomMapping = {};\n  for (const locale in customNames) {\n    result[locale] = { name: customNames[locale] };\n  }\n  return result;\n}\n\n/**\n * A dropdown component that allows users to select a locale.\n * @param {string} locale - The currently selected locale.\n * @param {string[]} locales - The list of all available locales.\n * @param {function} setLocale - Function to update the current locale.\n * @param {function} getLocaleProperties - Function to retrieve properties for a given locale.\n * @param {object} [customNames] - (deprecated) An optional object to map locales to custom names. Use `customMapping` instead.\n * @param {CustomMapping} [customMapping] - An optional object to map locales to custom display names, emojis, or other properties.\n * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.\n *\n * @internal\n */\nexport function InternalLocaleSelector({\n  locale,\n  locales,\n  customNames,\n  customMapping = _convertCustomNamesToMapping(customNames),\n  setLocale,\n  getLocaleProperties,\n  ...props\n}: {\n  locale: string;\n  locales: string[];\n  customNames?: { [key: string]: string };\n  customMapping?: CustomMapping;\n  setLocale: (locale: string) => void;\n  getLocaleProperties: (locale: string) => LocaleProperties;\n  [key: string]: any;\n}): React.JSX.Element | null {\n  // Get display name\n  const getDisplayName = (locale: string) => {\n    if (customMapping && customMapping[locale]) {\n      if (typeof customMapping[locale] === 'string')\n        return customMapping[locale];\n      if (customMapping[locale].name) return customMapping[locale].name;\n    }\n    return capitalizeName(getLocaleProperties(locale).nativeNameWithRegionCode);\n  };\n\n  // If no locales are returned, just render nothing or handle gracefully\n  if (!locales || locales.length === 0 || !setLocale) {\n    return null;\n  }\n\n  return (\n    <select\n      name='generaltranslation-locale'\n      aria-label='General Translation locale selector'\n      {...props}\n      // Fallback to an empty string if currentLocale is undefined\n      value={locale || ''}\n      onChange={(e) => setLocale(e.target.value)}\n    >\n      {/* Optional fallback for when no locale is set */}\n      {!locale && <option value='' />}\n\n      {locales.map((locale) => (\n        <option key={locale} value={locale} suppressHydrationWarning>\n          {getDisplayName(locale)}\n        </option>\n      ))}\n    </select>\n  );\n}\n"],"mappings":"6HASA,SAAS,EAAe,EAAqB,CAE3C,OADK,EACE,EAAI,OAAO,EAAE,CAAC,aAAa,EAAI,EAAI,OAAS,EAAI,EAAI,MAAM,EAAE,CAAG,IADrD,GAWnB,SAAS,EACP,EAC2B,CAC3B,GAAI,CAAC,EAAa,OAClB,IAAM,EAAwB,EAAE,CAChC,IAAK,IAAM,KAAU,EACnB,EAAO,GAAU,CAAE,KAAM,EAAY,GAAS,CAEhD,OAAO,EAeT,SAAgB,EAAuB,CACrC,SACA,UACA,cACA,gBAAgB,EAA6B,EAAY,CACzD,YACA,sBACA,GAAG,GASwB,CAE3B,IAAM,EAAkB,GAAmB,CACzC,GAAI,GAAiB,EAAc,GAAS,CAC1C,GAAI,OAAO,EAAc,IAAY,SACnC,OAAO,EAAc,GACvB,GAAI,EAAc,GAAQ,KAAM,OAAO,EAAc,GAAQ,KAE/D,OAAO,EAAe,EAAoB,EAAO,CAAC,yBAAyB,EAQ7E,MAJI,CAAC,GAAW,EAAQ,SAAW,GAAK,CAAC,EAChC,MAIP,EAAA,EAAA,MAAC,SAAD,CACE,KAAK,4BACL,aAAW,sCACX,GAAI,EAEJ,MAAO,GAAU,GACjB,SAAW,GAAM,EAAU,EAAE,OAAO,MAAM,UAN5C,CASG,CAAC,IAAU,EAAA,EAAA,KAAC,SAAD,CAAQ,MAAM,GAAK,CAAA,CAE9B,EAAQ,IAAK,IACZ,EAAA,EAAA,KAAC,SAAD,CAAqB,MAAO,EAAQ,yBAAA,YACjC,EAAe,EAAO,CAChB,CAFI,EAEJ,CACT,CACK"}