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EAAK,QAAEa,EAAO,MAAED,IAClC,OACE,iCAAOU,QAAS,IAAMV,EAAMZ,IAAM,YAChC,8BAAKI,WAAW,IAAAA,WAAU,qBAAsB,CAAES,aAAU,WAC1D,SAAC,IAAM,CAACU,QAAQ,4BAElB,0BACGvB,OAIT","sources":["webpack://empori-base/./src/controls/Forms/FormSelectorCheckboxes.tsx"],"sourcesContent":["import { className } from '@empori/util';\r\nimport * as React from 'react';\r\nimport { InputItem } from '../../empracoTypes';\r\nimport { FaIcon } from '../../generic/icon';\r\n\r\ninterface FormCheckboxesProps {\r\n input: InputItem;\r\n}\r\n\r\nexport default function FormCheckboxes({ input }: FormCheckboxesProps) {\r\n if (!input) {\r\n return null;\r\n }\r\n\r\n const { alternatives } = input;\r\n\r\n if (!alternatives || alternatives && alternatives.length < 1) {\r\n return null;\r\n }\r\n\r\n const [values, setValues] = React.useState(input?.values ?? []);\r\n const hiddenInput = React.useRef(null);\r\n\r\n const validationMessage = alternatives.length > 1\r\n ? 'At least one alternative is required.'\r\n : 'This check is required.';\r\n\r\n React.useEffect(() => {\r\n if (hiddenInput.current) {\r\n if (values.length) {\r\n hiddenInput.current.setCustomValidity('');\r\n } else {\r\n hiddenInput.current.setCustomValidity(validationMessage);\r\n }\r\n }\r\n }, [values]);\r\n\r\n const valuesToSend = () => {\r\n if (alternatives.length === 1 && values && values.length) {\r\n return 'Checked';\r\n }\r\n\r\n if (alternatives.length > 1 && values && values.length) {\r\n return values.join(', ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n const handleValues = (value: string) => {\r\n if (values.includes(value)) {\r\n setValues(values.filter(existingValue => existingValue !== value));\r\n return;\r\n }\r\n\r\n setValues([...values, value]);\r\n };\r\n\r\n return (\r\n <>\r\n

\r\n {input.label}\r\n {input.required &&\r\n *}\r\n

\r\n {alternatives.map((item, index) =>\r\n )}\r\n {input.description &&\r\n

\r\n \r\n {input.description}\r\n \r\n

}\r\n \r\n null} />\r\n \r\n );\r\n}\r\n\r\ninterface CheckboxProps {\r\n value: string;\r\n checked: boolean;\r\n click: (value: string) => void;\r\n}\r\n\r\nfunction Checkbox({ value, checked, click }: CheckboxProps) {\r\n return (\r\n \r\n );\r\n}"],"names":["FormCheckboxes","input","alternatives","length","values","setValues","hiddenInput","validationMessage","current","setCustomValidity","handleValues","value","includes","filter","existingValue","className","label","required","map","item","index","Checkbox","name","click","checked","description","hidden","ref","disabled","uniqueName","type","join","onChange","onClick","clsName"],"sourceRoot":""}