"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const qrcode_1 = require("qrcode");
const ShowQRCodeComponent = ({ activityDetails, onSubmit, }) => {
    var _a, _b, _c, _d;
    const url = (_b = (_a = activityDetails.fields.find((field) => field.id === 'url')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
    const label = (_d = (_c = activityDetails.fields.find((field) => field.id === 'label')) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '';
    const [qrCodeImageUrl, setQrCodeImageUrl] = (0, react_1.useState)();
    (0, react_1.useEffect)(() => {
        if (url !== '') {
            void (0, qrcode_1.toDataURL)(url, { scale: 7 }).then((dataUrl) => {
                setQrCodeImageUrl(dataUrl);
            });
        }
    }, [url]);
    return ((0, jsx_runtime_1.jsxs)("div", { style: {
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            gap: '24px',
            padding: '32px 16px',
            textAlign: 'center',
        }, children: [label !== '' && ((0, jsx_runtime_1.jsx)("p", { style: { margin: 0, fontSize: '16px', maxWidth: '320px' }, children: label })), qrCodeImageUrl !== undefined ? ((0, jsx_runtime_1.jsx)("img", { src: qrCodeImageUrl, alt: "QR code" })) : ((0, jsx_runtime_1.jsx)("div", { style: { width: 224, height: 224, background: '#f0f0f0', borderRadius: '8px' } })), (0, jsx_runtime_1.jsx)("button", { onClick: () => {
                    void onSubmit({});
                }, style: {
                    marginTop: '8px',
                    padding: '10px 24px',
                    fontSize: '15px',
                    cursor: 'pointer',
                    borderRadius: '6px',
                    border: '1px solid #ccc',
                    background: '#fff',
                }, children: "Done \u2014 nurse has scanned the code" })] }));
};
exports.default = ShowQRCodeComponent;
//# sourceMappingURL=index.js.map