{"version":3,"file":"utils.cjs","sources":["../../../../src/components/select/utils.ts"],"sourcesContent":["import { type ReactNode, isValidElement } from \"react\";\nimport type { ValuePair } from \"../../utilities/valuePair.js\";\n\nexport function getReactNodeText(node: ReactNode): string {\n    if (typeof node === \"string\" || typeof node === \"number\")\n        return String(node);\n    if (Array.isArray(node)) return node.map(getReactNodeText).join(\"\");\n    if (isValidElement(node)) return getReactNodeText(node.props.children);\n    return \"\";\n}\n\nexport const getButtonText = (\n    selected: Set<string>,\n    valuePairs: ValuePair[],\n    placeholderText: string,\n): string => {\n    if (selected.size === 1) {\n        return (\n            valuePairs.find((p) => selected.has(p.value))?.label ??\n            placeholderText\n        );\n    }\n    return `${selected.size} valgt`;\n};\n\nexport const autofocus =\n    (active: boolean | (() => boolean)) => (el: HTMLElement | null) => {\n        if (el) el.autofocus = typeof active === \"boolean\" ? active : active();\n    };\n"],"names":["active","el","autofocus","selected","valuePairs","placeholderText","size","find","p","has","value","label","getReactNodeText","node","String","Array","isArray","map","join","isValidElement","props","children"],"mappings":"2HA0BKA,GAAuCC,IAChCA,IAAIA,EAAGC,UAA8B,kBAAXF,EAAuBA,EAASA,4BAhBzC,CACzBG,EACAC,EACAC,IAEsB,IAAlBF,EAASG,KAELF,EAAWG,KAAMC,GAAML,EAASM,IAAID,EAAEE,SAASC,OAC/CN,EAGD,GAAGF,EAASG,sCAnBhB,SAASM,EAAiBC,GAC7B,MAAoB,iBAATA,GAAqC,iBAATA,EAC5BC,OAAOD,GACdE,MAAMC,QAAQH,GAAcA,EAAKI,IAAIL,GAAkBM,KAAK,IAC5DC,EAAAA,eAAeN,GAAcD,EAAiBC,EAAKO,MAAMC,UACtD,EACX"}