"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 styled_components_1 = __importDefault(require("styled-components"));
const system_1 = require("@/pages/system");
const login_user_1 = require("@/utils/login-user");
const applications_1 = require("./applications");
const dynamics_1 = require("./dynamics");
const projects_1 = require("./projects");
const { Sider } = antd_1.Layout;
const Location = styled_components_1.default.div `
  line-height: 48px;
  height: 48px;
  display: inline-block;
  width: 100%;
  color: rgba(0, 0, 0, 0.54);
  border-bottom: 1px solid rgb(221, 221, 221);
  background: #fff;
  border-right: 1px solid #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
`;
const MenuItemGroupTitle = styled_components_1.default.div `
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
`;
const WorkSpace = () => {
    const [selectedKeys, setSelectedKeys] = (0, react_1.useState)(['project']);
    const [siderCollapsed, setSiderCollapsed] = (0, react_1.useState)(false);
    // route info
    const history = (0, react_router_dom_1.useHistory)();
    const location = (0, react_router_dom_1.useLocation)();
    const routeMatch = (0, react_router_dom_1.useRouteMatch)();
    // get multi-language
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { workspace, project, application, dynamic } = locale.business;
    // get user info
    const { userInfo } = (0, login_user_1.getLoginUser)();
    const organizationId = userInfo === null || userInfo === void 0 ? void 0 : userInfo.organizationId;
    // if organization id empty, back to login page
    if (!organizationId) {
        history.push({
            pathname: '/login',
        });
        return null;
    }
    (0, react_1.useEffect)(() => {
        const newKey = location.pathname
            .replace(routeMatch.url, '')
            .replace('/', '')
            .split('/');
        setSelectedKeys(newKey);
    }, [location]);
    const handleClick = (0, react_1.useCallback)((e) => {
        const pathname = `/workspace/${e.keyPath.reverse().join('/')}`;
        history.push({
            pathname,
        });
    }, []);
    const handleBreakPoint = (0, react_1.useCallback)((broken) => {
        setSiderCollapsed(broken);
    }, []);
    return (react_1.default.createElement(antd_1.Layout, { hasSider: true, style: { height: '100%' } },
        react_1.default.createElement(Sider, { theme: "light", breakpoint: "xl", width: 250, collapsedWidth: 60, onBreakpoint: handleBreakPoint, style: { height: '100%', overflow: 'auto' } },
            react_1.default.createElement(antd_1.Tooltip, { title: workspace.name, placement: "right" },
                react_1.default.createElement(Location, { style: { paddingLeft: siderCollapsed ? 8 : 24 } }, workspace.name)),
            react_1.default.createElement(antd_1.Menu, { mode: "inline", theme: "light", defaultOpenKeys: ['projects', 'applications', 'dynamics'], selectedKeys: selectedKeys, onClick: handleClick },
                react_1.default.createElement(antd_1.Menu.ItemGroup, { key: "projects", title: react_1.default.createElement(MenuItemGroupTitle, { style: { textAlign: siderCollapsed ? 'center' : 'left' } }, project.name) },
                    react_1.default.createElement(antd_1.Menu.Item, { key: "projects", icon: react_1.default.createElement(icons_1.ProjectOutlined, null) }, project.myProject),
                    react_1.default.createElement(antd_1.Menu.Item, { key: "team-projects", icon: react_1.default.createElement(icons_1.ProfileOutlined, null) }, project.teamProject),
                    react_1.default.createElement(antd_1.Menu.Item, { key: "recycle-bin", icon: react_1.default.createElement(icons_1.RestOutlined, null) }, project.recycleBin)),
                react_1.default.createElement(antd_1.Menu.ItemGroup, { key: "applications", title: react_1.default.createElement(MenuItemGroupTitle, { style: { textAlign: siderCollapsed ? 'center' : 'left' } }, application.name) },
                    react_1.default.createElement(antd_1.Menu.Item, { key: "applications", icon: react_1.default.createElement(icons_1.AppstoreOutlined, null) }, application.myApplication)),
                react_1.default.createElement(antd_1.Menu.ItemGroup, { key: "dynamics", title: react_1.default.createElement(MenuItemGroupTitle, { style: { textAlign: siderCollapsed ? 'center' : 'left' } }, dynamic.name) },
                    react_1.default.createElement(antd_1.Menu.Item, { key: "dynamics", icon: react_1.default.createElement(icons_1.SwitcherOutlined, null) }, dynamic.myDynamic)))),
        react_1.default.createElement(react_router_dom_1.Switch, null,
            react_1.default.createElement(react_router_dom_1.Route, { path: "/workspace/applications", component: applications_1.Applications }),
            react_1.default.createElement(react_router_dom_1.Route, { path: "/workspace/projects", component: projects_1.PersonalProjects }),
            react_1.default.createElement(react_router_dom_1.Route, { path: "/workspace/team-projects", component: projects_1.TeamProjects }),
            react_1.default.createElement(react_router_dom_1.Route, { path: "/workspace/recycle-bin", component: projects_1.RecycleBin }),
            react_1.default.createElement(react_router_dom_1.Route, { path: "/workspace/dynamics", component: dynamics_1.Dynamics }),
            react_1.default.createElement(react_router_dom_1.Redirect, { from: "/*", to: "/workspace/projects" }))));
};
exports.default = WorkSpace;
