{"version":3,"file":"InstallButton.cjs","names":[],"sources":["../../../src/components/InstallButton/InstallButton.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { Button, type ButtonProps } from \"@/components/Button\";\nimport { useInstallPrompt } from \"@/hooks/use-install-prompt\";\nimport { cn } from \"@/utils/cn\";\nimport { defaultInstallHint, type RenderInstallHint } from \"./install-hints\";\nimport styles from \"./InstallButton.module.css\";\n\nexport type InstallOutcome = \"accepted\" | \"dismissed\" | \"unsupported\";\n\nexport interface InstallButtonProps extends Omit<ButtonProps, \"onClick\" | \"children\"> {\n    /** Button label. Default `\"Instalar app\"`. */\n    label?: ReactNode;\n    /**\n     * Label used when the browser cannot be prompted and the button reveals the\n     * manual instruction instead. Default `\"Como instalar\"`.\n     */\n    hintLabel?: ReactNode;\n    /** Called with the user's choice after the install prompt resolves. */\n    onResult?: (outcome: InstallOutcome) => void;\n    /**\n     * Replaces the instruction shown for the `\"ios\"` and `\"manual\"` methods.\n     *\n     * The default copy is in PT-BR and names the real menu entries. Pass this to\n     * translate it, to shorten it, or to point at a screenshot of your own.\n     */\n    renderHint?: RenderInstallHint;\n    /**\n     * How long, in ms, to wait for `beforeinstallprompt` before falling back to\n     * the manual instruction. Forwarded to {@link useInstallPrompt}; defaults to\n     * 3000 there.\n     */\n    manualFallbackDelayMs?: number;\n    /** Class applied to the wrapper that holds the button and the instruction. */\n    wrapperClassName?: string;\n}\n\n/**\n * Button wired to PWA installation, through {@link useInstallPrompt}.\n *\n * Where the browser fires `beforeinstallprompt`, the click installs. Where it\n * does not — iOS Safari, and the Android Chromium forks (Mi Browser, UC, Opera\n * Mini, Huawei) that strip the API — the click reveals the instruction for that\n * platform instead of the button disappearing.\n *\n * That disappearance was the defect: the component was built on\n * `useBeforeInstallPrompt`, so it rendered `null` exactly where the user needs\n * the most help, and every app re-implemented the iOS and manual paths locally.\n * Nothing renders only when there is genuinely nothing to offer — already\n * installed, running standalone, or inside the decline cooldown.\n *\n * Inherits every {@link Button} prop (`variant`, `size`, `leftIcon`, …).\n *\n * @example\n * <InstallButton variant=\"primary\" leftIcon={<Download />} />\n *\n * @example\n * <InstallButton renderHint={({ method }) => (method === \"ios\" ? <IOSSteps /> : <MenuSteps />)} />\n */\nexport function InstallButton({\n    label = \"Instalar app\",\n    hintLabel = \"Como instalar\",\n    onResult,\n    renderHint = defaultInstallHint,\n    manualFallbackDelayMs,\n    wrapperClassName,\n    ...props\n}: InstallButtonProps) {\n    const { method, openInChromeIntent, install } = useInstallPrompt({ manualFallbackDelayMs });\n    const [hintOpen, setHintOpen] = useState(false);\n    const hintId = useId();\n\n    if (method === \"none\") return null;\n\n    if (method === \"native\") {\n        return (\n            <Button\n                onClick={async () => {\n                    const accepted = await install();\n                    onResult?.(accepted ? \"accepted\" : \"dismissed\");\n                }}\n                {...props}\n            >\n                {label}\n            </Button>\n        );\n    }\n\n    const hint = renderHint({ method, openInChromeIntent });\n\n    return (\n        <div className={cn(styles.wrapper, wrapperClassName)}>\n            <Button\n                aria-expanded={hintOpen}\n                aria-controls={hintOpen && hint ? hintId : undefined}\n                onClick={() => setHintOpen((open) => !open)}\n                {...props}\n            >\n                {hintLabel}\n            </Button>\n            {hintOpen && hint ? (\n                <p className={styles.hint} id={hintId}>\n                    {hint}\n                </p>\n            ) : null}\n        </div>\n    );\n}\n"],"mappings":"uPA2DA,SAAgB,EAAc,CAC1B,QAAQ,eACR,YAAY,gBACZ,WACA,aAAa,EAAA,mBACb,wBACA,mBACA,GAAG,GACgB,CACnB,GAAM,CAAE,SAAQ,qBAAoB,WAAY,EAAA,iBAAiB,CAAE,uBAAsB,CAAC,EACpF,CAAC,EAAU,IAAA,EAAe,EAAA,SAAA,CAAS,EAAK,EACxC,GAAA,EAAS,EAAA,MAAA,CAAM,EAErB,GAAI,IAAW,OAAQ,OAAO,KAE9B,GAAI,IAAW,SACX,OACI,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CACI,QAAS,SAAY,CACjB,IAAM,EAAW,MAAM,EAAQ,EAC/B,IAAW,EAAW,WAAa,WAAW,CAClD,EACA,GAAI,EAEH,SAAA,CACG,CAAA,EAIhB,IAAM,EAAO,EAAW,CAAE,SAAQ,oBAAmB,CAAC,EAEtD,OACI,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,QAAS,CAAgB,EAAnD,SAAA,EACI,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CACI,gBAAe,EACf,gBAAe,GAAY,EAAO,EAAS,IAAA,GAC3C,YAAe,EAAa,GAAS,CAAC,CAAI,EAC1C,GAAI,EAEH,SAAA,CACG,CAAA,EACP,GAAY,GACT,EAAA,EAAA,IAAA,CAAC,IAAD,CAAG,UAAW,EAAA,QAAO,KAAM,GAAI,EAC1B,SAAA,CACF,CAAA,EACH,IACH,GAEb"}