{"version":3,"sources":["../../src/components/SnackbarContext.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from 'react';\n\nexport type AnchorOrigin =\n    | 'topLeft'\n    | 'topCenter'\n    | 'topRight'\n    | 'bottomLeft'\n    | 'bottomCenter'\n    | 'bottomRight';\n\nexport interface SnackbarNotification {\n    id: string;\n    message: string;\n    variant?: 'default' | 'success' | 'error' | 'warning' | 'info';\n    autoHideDuration?: number;\n    action?: ReactNode;\n}\n\nexport interface SnackbarNotificationContextValue {\n    notifications: Record<AnchorOrigin, SnackbarNotification[]>;\n    addNotification: (anchor: AnchorOrigin, notification: Omit<SnackbarNotification, 'id'>) => void;\n    removeNotification: (anchor: AnchorOrigin, id: string) => void;\n    clearAll: (anchor: AnchorOrigin) => void;\n}\n\nfunction createEmptyNotifications(): Record<AnchorOrigin, SnackbarNotification[]> {\n    return {\n        topLeft: [],\n        topCenter: [],\n        topRight: [],\n        bottomLeft: [],\n        bottomCenter: [],\n        bottomRight: [],\n    };\n}\n\nconst SnackbarNotificationContext = createContext<SnackbarNotificationContextValue | null>(null);\n\ninterface SnackbarNotificationProviderProps {\n    maxStack?: number;\n    children: ReactNode;\n}\n\nexport function SnackbarNotificationProvider({\n    maxStack = 4,\n    children,\n}: SnackbarNotificationProviderProps) {\n    const [notifications, setNotifications] =\n        useState<Record<AnchorOrigin, SnackbarNotification[]>>(createEmptyNotifications);\n\n    const removeNotification = useCallback((anchor: AnchorOrigin, id: string) => {\n        setNotifications((prev) => ({\n            ...prev,\n            [anchor]: prev[anchor].filter((n) => n.id !== id),\n        }));\n    }, []);\n\n    const addNotification = useCallback(\n        (anchor: AnchorOrigin, notification: Omit<SnackbarNotification, 'id'>) => {\n            const id = crypto.randomUUID();\n            const entry: SnackbarNotification = { ...notification, id };\n\n            setNotifications((prev) => {\n                let list = [...prev[anchor], entry];\n                if (list.length > maxStack) {\n                    list = list.slice(list.length - maxStack);\n                }\n                return { ...prev, [anchor]: list };\n            });\n\n            if (notification.autoHideDuration) {\n                setTimeout(() => {\n                    removeNotification(anchor, id);\n                }, notification.autoHideDuration);\n            }\n        },\n        [maxStack, removeNotification]\n    );\n\n    const clearAll = useCallback((anchor: AnchorOrigin) => {\n        setNotifications((prev) => ({ ...prev, [anchor]: [] }));\n    }, []);\n\n    const value = useMemo<SnackbarNotificationContextValue>(\n        () => ({ notifications, addNotification, removeNotification, clearAll }),\n        [notifications, addNotification, removeNotification, clearAll]\n    );\n\n    return (\n        <SnackbarNotificationContext.Provider value={value}>\n            {children}\n        </SnackbarNotificationContext.Provider>\n    );\n}\n\nexport function useSnackbarNotification(): SnackbarNotificationContextValue {\n    const ctx = useContext(SnackbarNotificationContext);\n    if (!ctx) {\n        throw new Error(\n            'useSnackbarNotification must be used within a SnackbarNotificationProvider'\n        );\n    }\n    return ctx;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0F;AAyFlF;AAhER,SAAS,2BAAyE;AAC9E,SAAO;AAAA,IACH,SAAS,CAAC;AAAA,IACV,WAAW,CAAC;AAAA,IACZ,UAAU,CAAC;AAAA,IACX,YAAY,CAAC;AAAA,IACb,cAAc,CAAC;AAAA,IACf,aAAa,CAAC;AAAA,EAClB;AACJ;AAEA,IAAM,kCAA8B,4BAAuD,IAAI;AAOxF,SAAS,6BAA6B;AAAA,EACzC,WAAW;AAAA,EACX;AACJ,GAAsC;AAClC,QAAM,CAAC,eAAe,gBAAgB,QAClC,uBAAuD,wBAAwB;AAEnF,QAAM,yBAAqB,0BAAY,CAAC,QAAsB,OAAe;AACzE,qBAAiB,CAAC,UAAU;AAAA,MACxB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;AAAA,IACpD,EAAE;AAAA,EACN,GAAG,CAAC,CAAC;AAEL,QAAM,sBAAkB;AAAA,IACpB,CAAC,QA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