{"version":3,"file":"PixQRCode.cjs","names":[],"sources":["../../src/br/PixQRCode.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — `pix` and `payload` are the two ways to supply the\n * same code (build it, or bring one already built), `size`/`level` are the symbol,\n * and amountLabel/payeeLabel/labels exist so the surrounding copy can be translated\n * without wrapping the component.\n */\nimport type { HTMLAttributes } from \"react\";\nimport { useMemo } from \"react\";\n\nimport { CopyButton } from \"@/components/CopyButton\";\nimport { QRCode } from \"@/components/QRCode\";\nimport type { QRErrorCorrection } from \"@/components/QRCode\";\nimport { cn } from \"@/utils/cn\";\n\nimport { PixError, pixPayload } from \"./pix\";\nimport type { PixInput } from \"./pix\";\nimport styles from \"./PixQRCode.module.css\";\n\n/** Strings the component renders, so an app can translate them. */\nexport interface PixQRCodeLabels {\n    /** Accessible name of the symbol. */\n    qr: string;\n    /** Copy button, idle. */\n    copy: string;\n    /** Copy button, just clicked. */\n    copied: string;\n}\n\nconst DEFAULT_LABELS: PixQRCodeLabels = {\n    qr: \"QR code do Pix\",\n    copy: \"Copiar código\",\n    copied: \"Copiado\",\n};\n\nexport interface PixQRCodeProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n    /**\n     * Build the payload from its parts. Mutually exclusive with {@link payload}.\n     */\n    pix?: PixInput;\n    /**\n     * A payload your PSP already produced, used verbatim.\n     *\n     * Prefer this for a dynamic charge: the PSP signed that string, and rebuilding\n     * it here from parsed parts would only add a way to get it wrong.\n     */\n    payload?: string;\n    /** Rendered side of the symbol in px, quiet zone included. Default `192`. */\n    size?: number;\n    /**\n     * Error-correction level. Default `\"M\"`.\n     *\n     * A printed QR that will be photographed at an angle scans better at `\"Q\"` or\n     * `\"H\"`; the cost is a denser symbol, so raise the size with it.\n     */\n    level?: QRErrorCorrection;\n    /** Render the copia-e-cola line and its copy button. Default `true`. */\n    showCopy?: boolean;\n    /** Amount caption, e.g. `\"R$ 25,50\"`. Rendered above the symbol when set. */\n    amountLabel?: string;\n    /** Payee caption. Rendered under the amount when set. */\n    payeeLabel?: string;\n    labels?: Partial<PixQRCodeLabels>;\n    /** Called after the payload reaches the clipboard. */\n    onCopied?: () => void;\n}\n\n/**\n * A Pix QR code with the copia-e-cola string next to it.\n *\n * The two affordances belong together: a QR is unusable on the device that is\n * *showing* it, which is exactly where a mobile checkout puts it, so every real\n * Pix screen ends up needing the copyable string as well. Rendering only the\n * symbol is the single most common mistake in a Pix flow.\n *\n * Everything is computed locally — {@link pixPayload} builds the string and the\n * SDK's own encoder draws the symbol — so the key, the amount and the txid never\n * leave the page. A QR-image service would receive all three.\n *\n * @throws {PixError} When neither `pix` nor `payload` is given, when both are, or\n * when `pix` fails validation. A bad key is a programming or data error rather\n * than a state to render, so it surfaces; wrap the screen in `ErrorBoundary` when\n * the values come from user input.\n *\n * @example\n * <PixQRCode\n *   pix={{\n *     key: \"loja@tempest.dev\",\n *     merchantName: \"Loja Tempest\",\n *     merchantCity: \"São Paulo\",\n *     amount: 25.5,\n *     txid: \"PEDIDO123\",\n *   }}\n *   amountLabel=\"R$ 25,50\"\n *   payeeLabel=\"Loja Tempest\"\n * />\n *\n * @example\n * <PixQRCode payload={charge.brcode} level=\"Q\" size={220} />\n */\nexport function PixQRCode({\n    pix,\n    payload,\n    size = 192,\n    level = \"M\",\n    showCopy = true,\n    amountLabel,\n    payeeLabel,\n    labels,\n    onCopied,\n    className,\n    ...rest\n}: PixQRCodeProps) {\n    const value = useMemo(() => {\n        if (payload !== undefined && pix !== undefined) {\n            throw new PixError(\"Pass either `pix` or `payload` to PixQRCode, not both.\");\n        }\n        if (payload !== undefined) return payload.trim();\n        if (pix !== undefined) return pixPayload(pix);\n        throw new PixError(\"PixQRCode needs either `pix` or `payload`.\");\n    }, [pix, payload]);\n\n    const text = { ...DEFAULT_LABELS, ...labels };\n\n    return (\n        <div className={cn(styles.pix, className)} {...rest}>\n            {amountLabel !== undefined && <span className={styles.amount}>{amountLabel}</span>}\n            {payeeLabel !== undefined && <span className={styles.payee}>{payeeLabel}</span>}\n            <div className={styles.symbol}>\n                <QRCode value={value} size={size} level={level} label={text.qr} margin={2} />\n            </div>\n            {showCopy && (\n                <div className={styles.copy}>\n                    <code className={styles.payload} data-testid=\"pix-payload\">\n                        {value}\n                    </code>\n                    <CopyButton value={value} onCopied={onCopied}>\n                        <span className={styles.copyIdle}>{text.copy}</span>\n                        <span className={styles.copyDone}>{text.copied}</span>\n                    </CopyButton>\n                </div>\n            )}\n        </div>\n    );\n}\n"],"mappings":"sPA4BA,IAAM,EAAkC,CACpC,GAAI,iBACJ,KAAM,gBACN,OAAQ,SACZ,EAmEA,SAAgB,EAAU,CACtB,MACA,UACA,OAAO,IACP,QAAQ,IACR,WAAW,GACX,cACA,aACA,SACA,WACA,YACA,GAAG,GACY,CACf,IAAM,GAAA,EAAQ,EAAA,QAAA,KAAc,CACxB,GAAI,IAAY,IAAA,IAAa,IAAQ,IAAA,GACjC,MAAM,IAAI,EAAA,SAAS,wDAAwD,EAE/E,GAAI,IAAY,IAAA,GAAW,OAAO,EAAQ,KAAK,EAC/C,GAAI,IAAQ,IAAA,GAAW,OAAO,EAAA,WAAW,CAAG,EAC5C,MAAM,IAAI,EAAA,SAAS,4CAA4C,CACnE,EAAG,CAAC,EAAK,CAAO,CAAC,EAEX,EAAO,CAAE,GAAG,EAAgB,GAAG,CAAO,EAE5C,OACI,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,IAAK,CAAS,EAAG,GAAI,EAA/C,SAAA,CACK,IAAgB,IAAA,KAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,OAAS,SAAA,CAAkB,CAAA,EAChF,IAAe,IAAA,KAAa,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,MAAQ,SAAA,CAAiB,CAAA,GAC9E,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,OACnB,UAAA,EAAA,EAAA,IAA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