{"version":3,"file":"MainQuestion.cjs","sources":["../../../../../src/components/feedback/main-question/MainQuestion.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, {\n    type ComponentProps,\n    type FC,\n    type ReactNode,\n    useEffect,\n} from \"react\";\nimport { useAnimatedHeight } from \"../../../hooks/useAnimatedHeight/useAnimatedHeight.js\";\nimport { PrimaryButton, TertiaryButton } from \"../../button/Button.js\";\nimport type { Feedback } from \"../Feedback.js\";\nimport { FeedbackSuccess } from \"../FeedbackSuccess.js\";\nimport { useFeedbackContext } from \"../feedbackContext.js\";\nimport { AddonQuestion } from \"../questions/AddonQuestion.js\";\nimport type { FeedbackOption, FeedbackType } from \"../types.js\";\nimport { getQuestionFromType } from \"../utils.js\";\nimport { MainQuestionContextProvider } from \"./mainQuestionContext.js\";\nimport { useMainQuestion } from \"./useMainQuestion.js\";\n\nconst defaultSuccessMessage = {\n    title: \"Takk for tilbakemeldingen!\",\n    children:\n        \"Husk at vi ikke kan besvare meldinger fra dette skjemaet. Kontakt gjerne din forsikringsrådgiver om du har flere spørsmål.\",\n};\n\ntype Props = Pick<ComponentProps<typeof Feedback>, \"addOnQuestion\"> & {\n    type: \"radio\" | \"smiley\";\n    label: string;\n    helpLabel?: string;\n    options: FeedbackOption[];\n    successMessage?: {\n        title: string;\n        children: ReactNode;\n    };\n    onSubmit: (value: FeedbackType) => void;\n};\n\nexport const MainQuestion: FC<Props> = ({\n    label,\n    options,\n    type,\n    addOnQuestion,\n    successMessage = defaultSuccessMessage,\n    helpLabel,\n    onSubmit,\n}) => {\n    const mainQuestionState = useMainQuestion(onSubmit);\n\n    const { setFeedbackSubmitted, contactSubmitted, landmarkLabel } =\n        useFeedbackContext();\n    const { handleSubmit, currentValue, setCurrentValue, submitted } =\n        mainQuestionState;\n    const [submitWrapperRef] = useAnimatedHeight<HTMLDivElement>(\n        currentValue !== undefined,\n    );\n\n    useEffect(() => {\n        setFeedbackSubmitted(submitted);\n    }, [submitted, setFeedbackSubmitted]);\n\n    const MainQuestionComp = getQuestionFromType(type);\n\n    return (\n        <>\n            {!submitted && (\n                <MainQuestionContextProvider state={mainQuestionState}>\n                    <form onSubmit={handleSubmit} aria-label={landmarkLabel}>\n                        <MainQuestionComp\n                            label={label}\n                            options={options}\n                            helpLabel={helpLabel}\n                        />\n                        <div\n                            ref={submitWrapperRef}\n                            className={clsx({\n                                \"jkl-feedback__submit-wrapper\": true,\n                                \"jkl-feedback__submit-wrapper--hidden\":\n                                    currentValue === undefined,\n                            })}\n                        >\n                            {addOnQuestion && (\n                                <AddonQuestion\n                                    helpLabel={\n                                        typeof addOnQuestion === \"object\"\n                                            ? addOnQuestion.helpLabel\n                                            : undefined\n                                    }\n                                    label={\n                                        typeof addOnQuestion === \"object\"\n                                            ? addOnQuestion.label\n                                            : undefined\n                                    }\n                                />\n                            )}\n                            <div className=\"jkl-feedback__buttons jkl-spacing-40--top\">\n                                <PrimaryButton className=\"jkl-spacing-40--right\">\n                                    Send\n                                </PrimaryButton>\n                                <TertiaryButton\n                                    type=\"button\"\n                                    onClick={() => setCurrentValue(undefined)}\n                                >\n                                    Avbryt\n                                </TertiaryButton>\n                            </div>\n                        </div>\n                    </form>\n                </MainQuestionContextProvider>\n            )}\n            {submitted && !contactSubmitted && (\n                <FeedbackSuccess {...successMessage} />\n            )}\n        </>\n    );\n};\n"],"names":["defaultSuccessMessage","title","children","label","options","type","addOnQuestion","successMessage","helpLabel","onSubmit","mainQuestionState","useMainQuestion","setFeedbackSubmitted","contactSubmitted","landmarkLabel","useFeedbackContext","handleSubmit","currentValue","setCurrentValue","submitted","submitWrapperRef","useAnimatedHeight","useEffect","MainQuestionComp","getQuestionFromType","jsxs","Fragment","jsx","MainQuestionContextProvider","state","ref","className","clsx","AddonQuestion","PrimaryButton","TertiaryButton","onClick","FeedbackSuccess"],"mappings":"ofAkBMA,EAAwB,CAC1BC,MAAO,6BACPC,SACI,mJAe+B,EACnCC,MAAAA,EACAC,QAAAA,EACAC,KAAAA,EACAC,cAAAA,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