"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Header = void 0;
const react_1 = __importStar(require("react"));
const react_copy_to_clipboard_1 = __importDefault(require("react-copy-to-clipboard"));
const shared_1 = require("../../shared");
const sc = __importStar(require("./styles"));
const PageWrap_1 = require("../PageWrap");
const Box_1 = require("../Box");
const Text_1 = require("../Text");
const Block_1 = require("../Block");
const Icon_1 = require("../Icon");
const IconCircled_1 = require("../IconCircled");
const Link_1 = require("../Link");
const List_1 = require("../List");
const IconText_1 = require("../IconText");
const InlineFlex_1 = require("../InlineFlex");
const logo_svg_1 = __importDefault(require("../../assets/images/logo.svg"));
const icons_1 = require("../../assets/images/icons");
exports.Header = (props) => {
    const [copied, setCopied] = react_1.useState(false);
    const { balance, walletAddress, network, symbol, logo, variant, RouterLink, children, right, logoLink = '/', } = props;
    const formattedBalance = balance
        ? typeof balance === 'string'
            ? balance
            : shared_1.formatters.toTokens(balance)
        : '...';
    const handleCopyClick = () => {
        setCopied(true);
        setTimeout(() => {
            setCopied(false);
        }, 2000);
    };
    const networkIndicator = (networkName) => (react_1.default.createElement(IconText_1.IconText, { as: "li", key: networkName },
        react_1.default.createElement(Icon_1.Icon, { Asset: icons_1.SvgDot, "aria-label": "Active network", color: "success", width: 26, height: 26 }),
        react_1.default.createElement(Text_1.Text, { variant: "b3m", color: "gray.2" }, networkName)));
    return (react_1.default.createElement(sc.Wrapper, { className: "pui-header", variant: variant },
        react_1.default.createElement(PageWrap_1.PageWrap, null,
            react_1.default.createElement(sc.Inner, null,
                react_1.default.createElement(Link_1.Link, Object.assign({}, (RouterLink
                    ? { as: RouterLink, to: logoLink }
                    : { href: logoLink })), logo ? (react_1.default.createElement(Block_1.Block, { as: "img", src: logo, alt: "Company Logo", width: "188" })) : (react_1.default.createElement(Block_1.Block, { as: "img", src: logo_svg_1.default, alt: "Polymath", width: "188" }))),
                children && react_1.default.createElement(InlineFlex_1.InlineFlex, null, children),
                react_1.default.createElement(Box_1.Box, { ml: "auto" },
                    react_1.default.createElement(List_1.List, { horizontal: true, className: "pui-header-menu" },
                        Array.isArray(network)
                            ? network.map((entry) => networkIndicator(entry))
                            : networkIndicator(network),
                        walletAddress && balance && (react_1.default.createElement(IconText_1.IconText, { as: "li" },
                            react_1.default.createElement(IconCircled_1.IconCircled, { Asset: icons_1.SvgPolyX, "aria-label": "Your POLYX balance", bg: "brandLightest", color: "brandMain", width: 26, height: 26, scale: 0.85 }),
                            react_1.default.createElement(InlineFlex_1.InlineFlex, { ml: "s" },
                                react_1.default.createElement(sc.Balance, null, formattedBalance),
                                " POLYX"))),
                        walletAddress && (react_1.default.createElement(IconText_1.IconText, { as: "li" },
                            react_1.default.createElement(IconCircled_1.IconCircled, { Asset: icons_1.SvgAccount, "aria-label": "Wallet address", bg: "brandLightest", color: "brandMain", width: 26, height: 26, scale: 0.75 }),
                            react_1.default.createElement(InlineFlex_1.InlineFlex, { ml: "s" },
                                react_1.default.createElement(react_copy_to_clipboard_1.default, { text: walletAddress },
                                    react_1.default.createElement(sc.CopyText, { variant: "b2m", color: "gray.2", onClick: handleCopyClick, copied: copied }, shared_1.formatters.toShortAddress(walletAddress, {
                                        size: 14,
                                    })))))),
                        symbol ? (react_1.default.createElement(IconText_1.IconText, { as: "li" },
                            react_1.default.createElement(IconCircled_1.IconCircled, { Asset: icons_1.SvgToken, "aria-label": "Token", bg: "brandLightest", color: "brandMain", width: 26, height: 26, scale: 0.85 }),
                            react_1.default.createElement(InlineFlex_1.InlineFlex, { ml: "s" }, symbol))) : (''))),
                right))));
};
exports.Header.defaultProps = {
    variant: 'default',
};
//# sourceMappingURL=Header.js.map