"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const react_router_dom_1 = require("react-router-dom");
const antd_1 = require("antd");
const ACTIONS = __importStar(require("@/actions/applications/detail/packages/list"));
const index_1 = require("@/components/index");
const system_1 = require("@/pages/system");
const fast_1 = require("../fast");
const components_1 = require("./components");
const { TabPane } = antd_1.Tabs;
const mapStateToProps = (store) => ({
    applicationId: store.applications.detail.settings.app.applicationId,
    selectPackage: store.applications.detail.packages.list.selectPackage,
});
const mapDispatchToProps = {
    updateListState: ACTIONS.updateListState,
    fetchComponentList: ACTIONS.fetchComponentsAction,
};
const Packages = (props) => {
    const { applicationId, selectPackage, updateListState, fetchComponentList } = props;
    const [registerModalState, setRegisterModalState] = (0, react_1.useState)(false);
    const location = (0, react_router_dom_1.useLocation)();
    const packageType = (new URLSearchParams(location.search).get('packageType') || 'component');
    // i18n
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { global, application, package: packageI18n } = locale.business;
    (0, react_1.useEffect)(() => {
        updateListState({
            applicationId,
            selectPackage: packageType,
        });
        if (applicationId)
            fetchComponentList({ applicationId });
    }, [applicationId]);
    const onChangeSelectedPackage = (val) => {
        updateListState({
            selectPackage: val,
        });
        if (applicationId)
            fetchComponentList({ applicationId });
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(index_1.Content, null,
            react_1.default.createElement(index_1.FoxPageContent, { breadcrumb: react_1.default.createElement(index_1.FoxPageBreadcrumb, { breadCrumb: [
                        { name: application.applicationList, link: '/#/workspace/applications' },
                        { name: global.packages },
                    ] }), style: {
                    overflow: 'hidden auto',
                } },
                react_1.default.createElement(react_1.default.Fragment, null,
                    react_1.default.createElement(antd_1.Tabs, { destroyInactiveTabPane: true, activeKey: selectPackage || packageType, onChange: onChangeSelectedPackage, type: "line" },
                        react_1.default.createElement(TabPane, { tab: react_1.default.createElement("span", null, packageI18n.component), key: "component" }),
                        react_1.default.createElement(TabPane, { tab: react_1.default.createElement("span", null, packageI18n.editor), key: "editor" }),
                        react_1.default.createElement(TabPane, { tab: react_1.default.createElement("span", null, packageI18n.systemComponent), key: "systemComponent" })),
                    react_1.default.createElement(components_1.List, { openQuicklyModal: setRegisterModalState })))),
        react_1.default.createElement(components_1.EditDrawer, null),
        react_1.default.createElement(fast_1.RegisterModal, { visible: registerModalState, onVisibleChange: setRegisterModalState })));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(Packages);
