{"version":3,"file":"SelectAutocomplete-Bj1N-Cii.js","sources":["../../../frontend/src/Components/DesignSystem/SelectAutocomplete/SelectAutocomplete.tsx"],"sourcesContent":["import React from 'react';\nimport { Autocomplete, Checkbox } from '@mui/material';\nimport { UseFormReturn, Controller } from 'react-hook-form';\nimport { useIntl } from 'react-intl';\nimport { get, has } from 'lodash';\n\nimport TextFieldDefault from '../../Posts/Forms/TextFieldDefault';\nimport withOptional from '../../../Utils/Posts/Form/withOptional';\n\ninterface SelectAutocompleteProps extends Partial> {\n errors?: any;\n form: UseFormReturn;\n label?: string;\n name: string;\n placeholder: string;\n required?: boolean;\n valueFormatter?: (value: any) => any;\n inputProps?: any;\n}\n\nfunction SelectAutocomplete({\n errors, // sometimes errors from other field to show. pass errorMessage instead?\n form,\n getOptionLabel = (option: any) => option?.label || '',\n label,\n name,\n placeholder,\n required,\n isOptionEqualToValue = (option: any, value: any) => option === value,\n valueFormatter = (value: any) => value,\n multiple,\n inputProps,\n ...rest\n}: SelectAutocompleteProps) {\n const intl = useIntl();\n const { control, setValue } = form;\n const fullLabel = required === undefined ? label : withOptional(label, required, true);\n\n const validate = (value: any) => {\n return !value && required ? intl.formatMessage({ id: 'POST_FORM.ERRORS.FILL_FIELDS' }) : true;\n };\n\n return (\n (\n {\n // setting the full option object on the form\n // it means the option object need to be build to fit\n // the form data structure before being passed to the component\n setValue(name, valueFormatter(newValue));\n }}\n renderInput={(params) => (\n \n )}\n renderOption={(props, option, { selected }) => {\n const { key, ...optionProps } = props;\n return (\n
  • \n {multiple && }\n {getOptionLabel(option)}\n
  • \n );\n }}\n fullWidth\n multiple={multiple}\n {...rest}\n />\n )}\n />\n );\n}\n\nexport default SelectAutocomplete;\n"],"names":["SelectAutocomplete","_ref","errors","form","_ref$getOptionLabel","getOptionLabel","option","label","name","placeholder","required","_ref$isOptionEqualToV","isOptionEqualToValue","value","_ref$valueFormatter","valueFormatter","multiple","inputProps","rest","_objectWithoutProperties","_excluded","intl","useIntl","control","setValue","fullLabel","undefined","withOptional","validate","formatMessage","id","React","createElement","Controller","rules","render","_ref2","_ref2$field","field","ref","restRender","_excluded2","Autocomplete","_extends","autoHighlight","selectOnFocus","clearOnBlur","handleHomeEndKeys","onChange","_e","newValue","renderInput","params","_get","TextFieldDefault","_objectSpread","helperText","get","message","error","has","renderOption","props","_ref3","selected","key","optionProps","_excluded3","Checkbox","checked","disableRipple","fullWidth"],"mappings":"gpEAoBA,SAASA,GAAkBC,EAaC,CAAA,IAZ1BC,EAAMD,EAANC,OACAC,EAAIF,EAAJE,KAAIC,EAAAH,EACJI,eAAAA,EAAcD,IAAA,OAAG,SAACE,EAAW,CAAA,OAAKA,GAAAA,YAAAA,EAAQC,QAAS,EAAA,EAAEH,EACrDG,EAAKN,EAALM,MACAC,EAAIP,EAAJO,KACAC,EAAWR,EAAXQ,YACAC,EAAQT,EAARS,SAAQC,EAAAV,EACRW,qBAAAA,EAAoBD,IAAA,OAAG,SAACL,EAAaO,EAAU,CAAA,OAAKP,IAAWO,CAAAA,EAAKF,EAAAG,EAAAb,EACpEc,eAAAA,EAAcD,IAAA,OAAG,SAACD,EAAU,CAAKA,OAAAA,CAAK,EAAAC,EACtCE,EAAQf,EAARe,SACAC,EAAUhB,EAAVgB,WACGC,EAAIC,EAAAlB,EAAAmB,CAAA,EAEDC,EAAOC,EAAQ,EACbC,EAAsBpB,EAAtBoB,QAASC,EAAarB,EAAbqB,SACXC,EAAYf,IAAagB,OAAYnB,EAAQoB,EAAapB,EAAOG,EAAU,EAAI,EAE/EkB,EAAW,SAACf,EAAe,CAC/B,MAAO,CAACA,GAASH,EAAWW,EAAKQ,cAAc,CAAEC,GAAI,8BAAgC,CAAA,EAAI,EAC3F,EAGEC,OAAAA,EAAAC,cAACC,EAAU,CACTV,QAAAA,EACAf,KAAAA,EACA0B,MAAO,CAAEN,SAAAA,CAAS,EAClBO,OAAQ,SAAFC,EAAgD,CAAA,IAAAC,EAAAD,EAA3CE,MAASC,EAAGF,EAAHE,IAAK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