{"version":3,"file":"Toast-DyCOed9b.js","sources":["../../Client/components/Modal.tsx","../../Client/components/FormErrorText.tsx","../../Client/components/Input.tsx","../../Client/shared/Toast.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport MicroModal from '../shared/Modal';\nimport { R } from '@/Resources.resx';\nimport classNames from 'classnames';\n\nconst containers: { [id: string]: HTMLElement } = {};\nlet _modalContainer: HTMLElement | null;\nfunction getModalContainer(id: string) {\n if (_modalContainer == null) {\n _modalContainer = document.createElement('div');\n document.body.appendChild(_modalContainer);\n }\n\n let container = containers[id];\n if (container == null) {\n container = document.createElement('div');\n container.id = id;\n container.className = 'modal';\n container.ariaHidden = 'true';\n containers[id] = container;\n _modalContainer.appendChild(container);\n }\n\n return container;\n}\n\ntype Props = {\n title?: string;\n hideCloseButton?: boolean;\n showCloseButtonInRightCorner?: boolean;\n onClose: () => void;\n children: React.ReactNode;\n containerClassName?: string;\n className?: string;\n};\nexport function Modal({\n title,\n hideCloseButton = false,\n showCloseButtonInRightCorner = false,\n containerClassName,\n className,\n onClose,\n children,\n}: Props) {\n const [id, setID] = useState(crypto.randomUUID());\n const container = getModalContainer(id);\n useEffect(() => {\n MicroModal.show(id, () => {\n onClose();\n setID(crypto.randomUUID());\n });\n return () => {\n MicroModal.close(id);\n container.remove();\n };\n }, [id]);\n\n const modal = (\n \n \n
\n {title && (\n

\n {title}\n

\n )}\n {hideCloseButton || (\n \n ✕\n \n )}\n
\n {children}\n \n \n );\n\n return createPortal(modal, container);\n}\n","export type FormErrorTextProps = {\n message: string;\n};\n\nexport function FormErrorText({ message }: FormErrorTextProps) {\n return
{message}
;\n}\n","import React, {\n ComponentPropsWithoutRef,\n ForwardedRef,\n forwardRef,\n} from 'react';\nimport { UseFormRegister } from 'react-hook-form';\nimport { FormErrorText } from '@/components/FormErrorText';\n\ntype InputProps = Omit<\n ComponentPropsWithoutRef<'input'>,\n 'name' | 'id'\n> & {\n label?: string;\n error?: string;\n inputClassName?: string;\n containerClassName?: string;\n} & (\n | UseFormRegister\n | {\n name: string;\n onChange?: (e: React.ChangeEvent) => void;\n }\n );\n\n/**\n * Input component. Use register if used together with React-hook-form. Use as a standalone input with use of onChange (and no register)\n * The generic type T is the type of the form state object in react hook form. A property name of this object is equal to a property name of the form object.\n *\n * @param name - The id of the input to bound op to label. Is also used as the property name in a form object of react-hook-form\n * @param label\n * @param error\n * @param inputClassName\n * @param containerClassName\n * @param rest - Other props passed to the native input.\n * @param ref\n */\nconst InputPlain = >(\n {\n name,\n label,\n error,\n inputClassName,\n containerClassName,\n ...rest\n }: InputProps,\n ref: ForwardedRef,\n) => {\n const classesInput = `form-control mb-1 ${inputClassName}`;\n const classesContainer = `flex flex-col ${containerClassName}`;\n\n return (\n
\n {label && (\n \n )}\n
\n \n {error && }\n
\n
\n );\n};\n\nexport const Input = forwardRef(InputPlain) as >(\n props: InputProps & { ref?: ForwardedRef },\n) => React.ReactNode;\n","import classNames from 'classnames';\n\ntype ToastElement = HTMLLIElement & {\n timeoutId?: number;\n closeCallback?: () => void;\n};\n\ntype ToastType = 'success' | 'info' | 'warning' | 'error' | 'default';\n\nconst iconPaths: Record = {\n default: '',\n success: '/images/icons/toast-icon-success.svg',\n info: '/images/icons/toast-icon-info.svg',\n warning: '/images/icons/toast-icon-warning.svg',\n error: '/images/icons/toast-icon-error.svg',\n};\n\nconst getCloseIconPath = (type: ToastType) => {\n return type === 'default'\n ? '/images/icons/close-toast-white.svg'\n : '/images/icons/close-toast-black.svg';\n};\n\n/**\n * Toasts - a class for creating and managing toast notifications.\n *\n * Toasts are small notifications that appear at the top of the screen.\n *\n * They are used to provide feedback to the user, such as when an action has been completed successfully, or when an error has occurred.\n *\n * @param {HTMLULElement} container - The container to which the toast message should be added. This should be a `
    ` element.\n */\n\ntype AddToastParams = {\n type: ToastType;\n message: string;\n autoClose?: boolean;\n closeCallback?: () => void;\n};\n\nclass Toasts {\n notifications: HTMLDivElement | null;\n\n constructor() {}\n\n initContainer() {\n const container = document.createElement('div');\n container.setAttribute('id', 'toast_container');\n container.className = classNames('grid justify-center');\n container.dataset.toasts = '';\n document.body.appendChild(container);\n this.notifications = container;\n return () => container.remove();\n }\n\n removeToast(toast: ToastElement) {\n toast.setAttribute('data-toast-hide', 'true');\n if (toast.timeoutId) clearTimeout(toast.timeoutId);\n return setTimeout(() => {\n toast.remove();\n toast.closeCallback();\n }, 600);\n }\n\n /**\n * Adds a toast notification to the UI.\n *\n * @param type - The ID of the toast ('success', 'info', 'warning', 'error', or 'default').\n * @param message - The message of the toast.\n * @param [autoClose=true] - An optional param that indicates whether the toast should automatically close after a certain duration. Default is true.\n * @param [closeCallback] - An optional callback function that will be called when the toast is closed.\n */\n addToast({\n type,\n message,\n autoClose = true,\n closeCallback,\n }: AddToastParams) {\n const removeContainer = this.initContainer();\n const toast = document.createElement('li') as ToastElement;\n toast.closeCallback = () => {\n closeCallback?.();\n removeContainer();\n };\n toast.className = classNames(\n `${type}`,\n 'data-toast',\n 'flex justify-between gap-5 items-center w-fit min-w-[335px]',\n 'overflow-hidden bg-white',\n 'animate-[toast-in_400ms_cubic-bezier(0.18,0.89,0.32,1.28)_forwards] data-[toast-hide=true]:animate-[toast-out_400ms_cubic-bezier(0.48,-0.26,0.87,0.03)_forwards]',\n ' rounded-lg p-4',\n autoClose\n ? ' before:absolute before:h-[var(--toast-progress-bar-height)] before:w-full before:bottom-0 before:left-0 before:animate-[progress_5s_linear_forwards]'\n : '',\n 'shadow-xl',\n );\n\n const closeButton = document.createElement('button');\n closeButton.classList.add('shrink-0', 'cursor-pointer');\n closeButton.dataset.toastClose = '';\n closeButton.innerHTML = `\"toast`;\n\n closeButton.addEventListener('click', removeContainer);\n\n toast.innerHTML = `
    \n ${\n iconPaths[type]\n ? ``\n : ''\n }\n
    \n ${message}\n
    \n
    `;\n\n toast.append(closeButton);\n this.notifications?.appendChild(toast);\n\n if (autoClose) {\n toast.timeoutId = setTimeout(() => {\n this.removeToast(toast);\n }, 5000) as unknown as number;\n }\n }\n}\n\nexport const toast = new Toasts();\n"],"names":["containers","_modalContainer","getModalContainer","id","container","Modal","title","hideCloseButton","showCloseButtonInRightCorner","containerClassName","className","onClose","children","setID","useState","useEffect","MicroModal","modal","jsx","classNames","jsxs","R","createPortal","FormErrorText","message","InputPlain","name","label","error","inputClassName","rest","ref","classesInput","classesContainer","Input","forwardRef","iconPaths","getCloseIconPath","type","Toasts","toast","autoClose","closeCallback","removeContainer","closeButton"],"mappings":"2MAMA,MAAMA,EAA4C,CAAC,EACnD,IAAIC,EACJ,SAASC,EAAkBC,EAAY,CAC/BF,GAAmB,OACDA,EAAA,SAAS,cAAc,KAAK,EACrC,SAAA,KAAK,YAAYA,CAAe,GAGzC,IAAAG,EAAYJ,EAAWG,CAAE,EAC7B,OAAIC,GAAa,OACDA,EAAA,SAAS,cAAc,KAAK,EACxCA,EAAU,GAAKD,EACfC,EAAU,UAAY,QACtBA,EAAU,WAAa,OACvBJ,EAAWG,CAAE,EAAIC,EACjBH,EAAgB,YAAYG,CAAS,GAGlCA,CACX,CAWO,SAASC,EAAM,CAClB,MAAAC,EACA,gBAAAC,EAAkB,GAClB,6BAAAC,EAA+B,GAC/B,mBAAAC,EACA,UAAAC,EACA,QAAAC,EACA,SAAAC,CACJ,EAAU,CACN,KAAM,CAACT,EAAIU,CAAK,EAAIC,EAAAA,SAAS,OAAO,YAAY,EAC1CV,EAAYF,EAAkBC,CAAE,EACtCY,EAAAA,UAAU,KACKC,EAAA,KAAKb,EAAI,IAAM,CACdQ,EAAA,EACFE,EAAA,OAAO,YAAY,CAAA,CAC5B,EACM,IAAM,CACTG,EAAW,MAAMb,CAAE,EACnBC,EAAU,OAAO,CACrB,GACD,CAACD,CAAE,CAAC,EAEP,MAAMc,EACFC,EAAA,IAAC,MAAA,CACG,UAAWC,EACP,2FACAT,CACJ,EACA,MAAO,CAAE,WAAY,iBAAkB,EACvC,SAAU,GAEV,SAAAU,EAAA,KAAC,MAAA,CACG,UAAWD,EACP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