{"version":3,"file":"index-B473ERzb.mjs","sources":["../../admin/src/components/CountrySelect/index.tsx"],"sourcesContent":["import React from 'react';\nimport { Field, Flex, Combobox, ComboboxOption } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { getTranslation } from '../../utils/getTrad';\n\nimport { type InputProps, type FieldValue } from '@strapi/strapi/admin';\n\ntype CountrySelectProps = InputProps &\n  FieldValue & {\n    labelAction?: React.ReactNode;\n    attribute: {\n        options: {\n            default?: string\n        }\n    }\n};\n\nconst CountrySelect = React.forwardRef<HTMLButtonElement, CountrySelectProps>(({\n    value,\n    onChange,\n    name,\n    label,\n    labelAction,\n    required,\n    hint,\n    placeholder,\n    disabled,\n    error,\n    attribute\n}, forwardedRef) => {\n    useField\n    const { formatMessage, messages } = useIntl();\n    const countries = messages[getTranslation('countries')] as string || '{}';\n    const defaultValue = attribute?.options?.default;\n    \n    const parsedOptions: {[key: string]: string} = JSON.parse(countries);\n    const isValidValue = !value || parsedOptions.hasOwnProperty(value);\n    \n    console.log(value, isValidValue);\n\n    return (\n        <Field.Root\n            name={name}\n            id={name}\n            error={!isValidValue ? formatMessage({ id: getTranslation('country-select.unsupported-country-code') }, { countryCode: value }) : error}\n            required={required}\n            hint={hint}\n        >\n            <Flex direction=\"column\" alignItems=\"stretch\" gap={1}>\n                <Field.Label action={labelAction}>{label}</Field.Label>\n\n                <Combobox\n                    ref={forwardedRef}\n                    placeholder={placeholder} \n                    aria-label={label}\n                    aria-disabled={disabled}\n                    disabled={disabled}\n                    value={isValidValue ? value : null}\n                    onChange={(countryCode: string) => onChange(name, countryCode)}\n                    onClear={() => onChange(name, null)}\n                >\n                    {Object.entries(parsedOptions).sort(([, n1], [, n2]) => n1.localeCompare(n2)).map(([countryCode, countryName]) => (\n                        <ComboboxOption value={countryCode} key={countryCode}>{countryName}</ComboboxOption>\n                    ))}\n                </Combobox>\n\n                <Field.Hint />\n                <Field.Error />\n            </Flex>\n        </Field.Root>\n    )\n})\n\nexport default CountrySelect;\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