{"version":3,"file":"OfflineIndicator.cjs","names":[],"sources":["../../../src/components/OfflineIndicator/OfflineIndicator.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport type { HTMLAttributes, ReactNode } from \"react\";\nimport { CloudOff, Wifi } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport { useOnline } from \"@/hooks\";\nimport styles from \"./OfflineIndicator.module.css\";\n\nexport type OfflineIndicatorPosition = \"top\" | \"bottom\";\n\nexport interface OfflineIndicatorProps extends HTMLAttributes<HTMLDivElement> {\n    /** Where to pin the fixed bar. Default `\"bottom\"`. */\n    position?: OfflineIndicatorPosition;\n    /** Message shown while offline. */\n    offlineLabel?: ReactNode;\n    /** Message flashed briefly when connectivity returns. */\n    onlineLabel?: ReactNode;\n    /**\n     * How long (ms) to keep the \"back online\" flash visible. `0` hides it\n     * entirely. Default `3000`.\n     */\n    onlineFlashMs?: number;\n    /** Override the offline body entirely (icon + label ignored). */\n    children?: ReactNode;\n}\n\n/**\n * Fixed bar that appears while the browser is offline and, by default, flashes\n * a brief confirmation when the connection returns. Backed by {@link useOnline}\n * — no props needed for the common case.\n *\n * Renders nothing while online (after any flash has elapsed), so it is safe to\n * mount unconditionally at the app root.\n *\n * @example\n * <OfflineIndicator position=\"top\" />\n */\nexport function OfflineIndicator({\n    position = \"bottom\",\n    offlineLabel = \"Você está offline. As alterações serão sincronizadas ao reconectar.\",\n    onlineLabel = \"Conexão restabelecida.\",\n    onlineFlashMs = 3000,\n    className,\n    children,\n    ...props\n}: OfflineIndicatorProps) {\n    const online = useOnline();\n    const [flashOnline, setFlashOnline] = useState<boolean>(false);\n    const wasOfflineRef = useRef<boolean>(false);\n\n    useEffect(() => {\n        if (!online) {\n            wasOfflineRef.current = true;\n            setFlashOnline(false);\n            return;\n        }\n        if (!wasOfflineRef.current || onlineFlashMs <= 0) return;\n        wasOfflineRef.current = false;\n        setFlashOnline(true);\n        const id = window.setTimeout(() => setFlashOnline(false), onlineFlashMs);\n        return () => window.clearTimeout(id);\n    }, [online, onlineFlashMs]);\n\n    if (online && !flashOnline) return null;\n\n    const showingOnline = online && flashOnline;\n    return (\n        <div\n            className={cn(\n                styles.bar,\n                styles[position],\n                showingOnline ? styles.online : styles.offline,\n                className,\n            )}\n            role=\"status\"\n            aria-live=\"polite\"\n            {...props}\n        >\n            {children ?? (\n                <>\n                    {showingOnline ? (\n                        <Wifi className={styles.icon} size={16} aria-hidden=\"true\" />\n                    ) : (\n                        <CloudOff className={styles.icon} size={16} aria-hidden=\"true\" />\n                    )}\n                    <span>{showingOnline ? onlineLabel : offlineLabel}</span>\n                </>\n            )}\n        </div>\n    );\n}\n"],"mappings":"yMAoCA,SAAgB,EAAiB,CAC7B,WAAW,SACX,eAAe,sEACf,cAAc,yBACd,gBAAgB,IAChB,YACA,WACA,GAAG,GACmB,CACtB,IAAM,EAAS,EAAA,UAAU,EACnB,CAAC,EAAa,IAAA,EAAkB,EAAA,SAAA,CAAkB,EAAK,EACvD,GAAA,EAAgB,EAAA,OAAA,CAAgB,EAAK,EAe3C,IAbA,EAAA,EAAA,UAAA,KAAgB,CACZ,GAAI,CAAC,EAAQ,CACT,EAAc,QAAU,GACxB,EAAe,EAAK,EACpB,MACJ,CACA,GAAI,CAAC,EAAc,SAAW,GAAiB,EAAG,OAClD,EAAc,QAAU,GACxB,EAAe,EAAI,EACnB,IAAM,EAAK,OAAO,eAAiB,EAAe,EAAK,EAAG,CAAa,EACvE,UAAa,OAAO,aAAa,CAAE,CACvC,EAAG,CAAC,EAAQ,CAAa,CAAC,EAEtB,GAAU,CAAC,EAAa,OAAO,KAEnC,IAAM,EAAgB,GAAU,EAChC,OACI,EAAA,EAAA,IAAA,CAAC,MAAD,CACI,UAAW,EAAA,GACP,EAAA,QAAO,IACP,EAAA,QAAO,GACP,EAAgB,EAAA,QAAO,OAAS,EAAA,QAAO,QACvC,CACJ,EACA,KAAK,SACL,YAAU,SACV,GAAI,EAEH,SAAA,IACG,EAAA,EAAA,KAAA,C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