"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (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.prototype.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 });
const react_1 = __importStar(require("react"));
const react_router_dom_1 = require("react-router-dom");
const icons_1 = require("@ant-design/icons");
const antd_1 = require("antd");
const en_US_1 = __importDefault(require("antd/lib/locale/en_US"));
const zh_CN_1 = __importDefault(require("antd/lib/locale/zh_CN"));
const styled_components_1 = __importDefault(require("styled-components"));
const index_1 = require("@/components/index");
const index_2 = require("@/constants/index");
const index_3 = __importDefault(require("@/foxI18n/index"));
const index_4 = require("@/pages/system/index");
const index_5 = require("@/utils/index");
const { Header } = antd_1.Layout;
const StyledLink = (0, styled_components_1.default)(react_router_dom_1.Link) `
  color: #fff;
  text-decoration: none;
  user-select: none;
  display: contents;
`;
const Logo = styled_components_1.default.div `
  justify-content: center;
  align-items: center;
  display: inline-flex;
  color: #fff;
  padding: 10px 0 10px 16px;
  flex: 0 0;
`;
const MainNav = styled_components_1.default.ul `
  list-style: none;
  padding: 7px 0;
  color: #757575;
  margin-left: 20px;
  margin-bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
`;
const NavItem = styled_components_1.default.li `
  float: left;
  font-size: 14px;
`;
const NavLinkContent = (0, styled_components_1.default)(react_router_dom_1.NavLink) `
  border-radius: 4px;
  margin-right: 10px;
  color: #616161;
  display: block;
  line-height: 34px;
  padding: 0 16px;
  text-decoration: none;
  :hover {
    color: #212121;
    text-decoration: none;
  }
`;
const User = styled_components_1.default.div `
  position: absolute;
  right: 16px;
  height: 48px;
  display: flex;
  align-items: center;
`;
const UserName = styled_components_1.default.div `
  display: inline-flex;
  line-height: normal;
  cursor: pointer;
  align-items: center;
  > .user-account {
    margin-left: 12px;
    margin-right: 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    max-width: 120px;
    overflow: hidden;
    vertical-align: middle;
  }
`;
const LocaleItem = styled_components_1.default.div `
  cursor: pointer;
  display: inline-flex;
  margin-right: 24px;
  color: #000000d9;
  border: 1px solid #d9d9d9;
  line-height: 16px;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.3s;
  &:hover {
    border-color: #1890ff;
  }
`;
const FoxPageHeader = () => {
    const { userInfo } = (0, index_5.getLoginUser)();
    const history = (0, react_router_dom_1.useHistory)();
    const { locale, setLocale } = (0, react_1.useContext)(index_4.GlobalContext);
    const { global, workspace, store, login } = locale.business || index_3.default[index_2.LOCALE_ZH_CN];
    const handleLogout = (0, react_1.useCallback)(() => {
        // clear local storage
        (0, index_5.setLoginUser)();
        // back to login page
        history.push('/login');
    }, []);
    const handleLocaleChange = () => {
        const newLocale = Object.assign(Object.assign({}, (locale.locale === index_2.LOCALE_ZH_CN ? en_US_1.default : zh_CN_1.default)), { business: locale.locale === index_2.LOCALE_ZH_CN ? index_3.default[index_2.LOCALE_EN] : index_3.default[index_2.LOCALE_ZH_CN] });
        setLocale(newLocale);
        // sync language prefer data to local storage
        const loginUserInfo = (0, index_5.getLoginUser)();
        (0, index_5.setLoginUser)(Object.assign(Object.assign({}, loginUserInfo), { languagePrefer: locale.locale === index_2.LOCALE_ZH_CN ? index_2.LOCALE_EN : index_2.LOCALE_ZH_CN }));
    };
    return (react_1.default.createElement(Header, { key: "1", style: {
            backgroundColor: '#Fff',
            display: 'flex',
            boxShadow: 'rgb(100 100 100 / 20%) 0px 2px 3px 0px',
            zIndex: 500,
            padding: 0,
            height: 48,
            position: 'fixed',
            width: '100%',
        } },
        react_1.default.createElement(Logo, { key: "foxpage-logo" },
            react_1.default.createElement(StyledLink, { to: "/workspace" },
                react_1.default.createElement("img", { key: "foxpage-logo-img", height: 28, width: 140, src: (0, index_5.getImageUrlByEnv)('/images/header-logo.png'), alt: "foxpage logo" }))),
        react_1.default.createElement(MainNav, null,
            react_1.default.createElement(NavItem, null,
                react_1.default.createElement(index_1.OrganizationSelector, null)),
            react_1.default.createElement(NavItem, null,
                react_1.default.createElement(NavLinkContent, { activeStyle: {
                        fontWeight: 'bold',
                    }, to: "/workspace" }, workspace.name)),
            react_1.default.createElement(NavItem, null,
                react_1.default.createElement(NavLinkContent, { activeStyle: {
                        fontWeight: 'bold',
                    }, to: "/projects" }, global.project)),
            react_1.default.createElement(NavItem, null,
                react_1.default.createElement(NavLinkContent, { activeStyle: {
                        fontWeight: 'bold',
                    }, to: "/applications" }, global.application)),
            react_1.default.createElement(NavItem, null,
                react_1.default.createElement(NavLinkContent, { activeStyle: {
                        fontWeight: 'bold',
                    }, to: "/teams" }, global.team)),
            react_1.default.createElement(NavItem, null,
                react_1.default.createElement(NavLinkContent, { activeStyle: {
                        fontWeight: 'bold',
                    }, to: "/store" }, store.name))),
        react_1.default.createElement(User, null,
            react_1.default.createElement(LocaleItem, { onClick: handleLocaleChange }, locale.locale === index_2.LOCALE_EN ? 'English' : '简体中文'),
            react_1.default.createElement(antd_1.Avatar, { size: 28, icon: react_1.default.createElement(icons_1.UserOutlined, null) }),
            react_1.default.createElement(antd_1.Dropdown, { trigger: ['click'], overlay: react_1.default.createElement(antd_1.Menu, null,
                    react_1.default.createElement(antd_1.Menu.Item, { key: "0", onClick: handleLogout },
                        react_1.default.createElement(icons_1.LogoutOutlined, { style: { marginRight: 8 } }),
                        login.loginOut)) },
                react_1.default.createElement(UserName, null,
                    react_1.default.createElement("span", { className: "user-account" }, userInfo === null || userInfo === void 0 ? void 0 : userInfo.account),
                    react_1.default.createElement(icons_1.DownOutlined, null))))));
};
exports.default = FoxPageHeader;
