"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.headerStatusSubject = exports.useHeaderStatus = void 0;
const react_1 = __importDefault(require("react"));
const prefix_classname_1 = __importDefault(require("prefix-classname"));
const antd_1 = require("antd");
const use_behaviorsubject_1 = require("@rcp/use.behaviorsubject");
const const_1 = require("../../../config/const");
require("./style.scss");
const utils_1 = require("../../utils/utils");
const cn = (0, prefix_classname_1.default)('');
const c = (0, prefix_classname_1.default)(`${const_1.CLS_PREFIX}-header`);
function createReactBehaviorSubjectStored(d, _a) {
    var { storeKey } = _a, opts = __rest(_a, ["storeKey"]);
    try {
        const prev = JSON.parse(localStorage.getItem(storeKey));
        if (prev && typeof prev === 'object') {
            d = Object.assign(Object.assign({}, d), prev);
        }
    }
    catch (e) { }
    const { useSubject, subject } = (0, use_behaviorsubject_1.createReactBehaviorSubject)(d, opts);
    subject.subscribe((value) => {
        localStorage.setItem(storeKey, JSON.stringify(value));
    });
    return {
        subject,
        useSubject
    };
}
const { useSubject, subject } = createReactBehaviorSubjectStored({
    canSelect: false,
    showLocation: true
}, { storeKey: (0, utils_1.symbol)(`headerStatus`) });
exports.useHeaderStatus = useSubject;
exports.headerStatusSubject = subject;
const Header = react_1.default.memo(({ className, bundlerURL }) => {
    const [{ canSelect, showLocation }, setValue] = (0, exports.useHeaderStatus)();
    return (react_1.default.createElement("div", { className: cn(c(), className) },
        react_1.default.createElement("div", { className: c('__logo') },
            react_1.default.createElement("a", { target: '_blank', href: 'https://github.com/imcuttle/mometa', style: { color: 'inherit' } }, "mometa")),
        react_1.default.createElement(antd_1.Divider, { type: 'vertical' }),
        react_1.default.createElement("div", { className: c('__switch') },
            react_1.default.createElement(antd_1.Switch, { unCheckedChildren: '预览', checked: canSelect, onChange: (checked) => setValue((x) => (Object.assign(Object.assign({}, x), { canSelect: checked }))), checkedChildren: '编辑' }),
            react_1.default.createElement(antd_1.Switch, { checked: showLocation, onChange: (checked) => setValue((x) => (Object.assign(Object.assign({}, x), { showLocation: checked }))), unCheckedChildren: '隐藏路由', checkedChildren: '展示路由' })),
        react_1.default.createElement(antd_1.Divider, { type: 'vertical' }),
        react_1.default.createElement(antd_1.Button, { type: "link", href: bundlerURL, target: '_blank' }, "\u5728\u65B0\u7A97\u53E3\u9884\u89C8")));
});
Header.defaultProps = {};
exports.default = Header;
//# sourceMappingURL=index.js.map