"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_redux_1 = require("react-redux");
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 ACTIONS = __importStar(require("@/actions/applications/list"));
const global_1 = require("@/constants/global");
const components_1 = require("@/pages/components");
const system_1 = require("@/pages/system");
const components_2 = require("./components");
const Title = styled_components_1.default.span `
  width: 100%;
  display: inline-block;
  padding: 16px 0;
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
`;
const Card = (0, styled_components_1.default)(antd_1.Card) `
  .ant-card-head {
    .ant-card-head-title {
      span {
        padding: 24px 0;
      }
    }
  }
`;
const mapStateToProps = (state) => ({
    organizationId: state.system.user.organizationId,
    loading: state.applications.list.loading,
    pageInfo: state.applications.list.pageInfo,
    list: state.applications.list.applicationList,
    editDrawerVisible: state.applications.list.editDrawerVisible,
});
const mapDispatchToProps = {
    clearAll: ACTIONS.clearAll,
    fetchList: ACTIONS.fetchList,
    saveApp: ACTIONS.saveApp,
    openDrawer: ACTIONS.openEditDrawer,
};
const Applications = (props) => {
    const { organizationId, loading, list, pageInfo, clearAll, fetchList, openDrawer } = props;
    // get multi-language
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { application, global } = locale.business;
    const history = (0, react_router_dom_1.useHistory)();
    if (!organizationId) {
        history.push({
            pathname: '/login',
        });
        return null;
    }
    (0, react_1.useEffect)(() => {
        return () => {
            clearAll();
        };
    }, []);
    (0, react_1.useEffect)(() => {
        fetchList({
            organizationId,
            page: pageInfo.page,
            size: pageInfo.size,
        });
    }, [fetchList, organizationId, clearAll]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(components_1.Content, null,
            react_1.default.createElement(components_1.FoxPageContent, { breadcrumb: react_1.default.createElement(components_1.FoxPageBreadcrumb, { breadCrumb: [
                        {
                            name: application.name,
                        },
                    ] }), style: { maxWidth: global_1.WIDTH_DEFAULT, overflow: 'unset' } },
                react_1.default.createElement("div", { style: { marginBottom: 12, display: 'flex', justifyContent: 'flex-end' } },
                    react_1.default.createElement(antd_1.Button, { type: "primary", onClick: () => openDrawer(true) },
                        react_1.default.createElement(icons_1.PlusOutlined, null),
                        " ",
                        application.add)),
                react_1.default.createElement(antd_1.Spin, { spinning: loading },
                    react_1.default.createElement(antd_1.Row, { gutter: 16, style: { maxWidth: global_1.WIDTH_DEFAULT, minHeight: 24, paddingBottom: 24, margin: '0 auto' } },
                        list.map((application) => {
                            return (react_1.default.createElement(antd_1.Col, { span: 6, key: application.id },
                                react_1.default.createElement(Card, { key: application.id, bordered: true, hoverable: true, title: react_1.default.createElement(Title, null, application.name), onClick: () => {
                                        history.push(`/applications/${application.id}/file/pages/list`);
                                    }, style: { marginBottom: 12 } },
                                    react_1.default.createElement("p", null,
                                        global.idLabel,
                                        ": ",
                                        application.id))));
                        }),
                        !loading && (list === null || list === void 0 ? void 0 : list.length) === 0 && (react_1.default.createElement(antd_1.Empty, { image: antd_1.Empty.PRESENTED_IMAGE_SIMPLE, style: { margin: '48px auto' } }))),
                    react_1.default.createElement(antd_1.Pagination, { style: { textAlign: 'center' }, current: pageInfo.page, total: pageInfo.total, pageSize: pageInfo.size, hideOnSinglePage: true, onChange: (page, pageSize) => fetchList({ organizationId, page, size: pageSize }) })))),
        react_1.default.createElement(components_2.EditDrawer, null)));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(Applications);
