"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTheme = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const prism_react_renderer_1 = tslib_1.__importStar(require("prism-react-renderer"));
const react_core_1 = require("@patternfly/react-core");
const t_global_color_nonstatus_purple_300_1 = require("@patternfly/react-tokens/dist/js/t_global_color_nonstatus_purple_300");
const t_global_color_nonstatus_blue_default_1 = require("@patternfly/react-tokens/dist/js/t_global_color_nonstatus_blue_default");
const github_1 = tslib_1.__importDefault(require("prism-react-renderer/themes/github"));
const okaidia_1 = tslib_1.__importDefault(require("prism-react-renderer/themes/okaidia"));
require("./PrismCode.css");
const getTheme = (styles) => {
    let prefersTheme = window.localStorage.getItem('bridge/theme');
    if (prefersTheme === 'systemDefault') {
        prefersTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    }
    const theme = prefersTheme === 'dark' ? okaidia_1.default : github_1.default;
    return {
        plain: {
            color: theme.plain.color,
            backgroundColor: theme.plain.backgroundColor,
            fontSize: '.93em',
        },
        styles: styles || [
            {
                types: ['variable'],
                style: {
                    color: t_global_color_nonstatus_blue_default_1.t_global_color_nonstatus_blue_default.value,
                },
            },
            {
                types: ['class-name', 'function', 'tag', 'attr-name'],
                style: {
                    color: t_global_color_nonstatus_purple_300_1.t_global_color_nonstatus_purple_300.value,
                },
            },
        ],
    };
};
exports.getTheme = getTheme;
const PrismCode = ({ code, styles, language = 'bash', copiable = false, }) => (react_1.default.createElement(prism_react_renderer_1.default, Object.assign({}, prism_react_renderer_1.defaultProps, { code: code, language: language, theme: (0, exports.getTheme)(styles) }), ({ className, style, tokens, getLineProps, getTokenProps }) => (react_1.default.createElement(react_core_1.Content, { component: "pre", className: className, style: style },
    copiable && (react_1.default.createElement(react_core_1.ClipboardCopy, { isReadOnly: true, variant: 'inline-compact', onCopy: (e) => (0, react_core_1.clipboardCopyFunc)(e, code), style: { float: 'right', background: 'inherit' } }, '')),
    tokens.map((line, i) => (react_1.default.createElement("div", Object.assign({ key: i }, getLineProps({ line, key: i })), line.map((token, key) => (react_1.default.createElement("span", Object.assign({ key: key }, getTokenProps({ token, key }))))))))))));
exports.default = PrismCode;
//# sourceMappingURL=PrismCode.js.map