"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/workspace/applications/list"));
const system_1 = require("@/pages/system");
const index_1 = require("@/utils/index");
const Table = (0, styled_components_1.default)(antd_1.Table) `
  .ant-table-pagination.ant-pagination {
    margin: 36px 0 0;
  }
`;
const mapStateToProps = (state) => ({
    organizationId: state.system.user.organizationId,
    loading: state.workspace.applications.list.loading,
    pageInfo: state.workspace.applications.list.pageInfo,
    list: state.workspace.applications.list.applicationList,
});
const mapDispatchToProps = {
    fetchList: ACTIONS.fetchList,
    openDrawer: ACTIONS.openEditDrawer,
    openAuthDrawer: ACTIONS.updateAuthDrawerVisible,
};
const ApplicationList = (props) => {
    const { organizationId, loading, pageInfo, list, fetchList, openDrawer, openAuthDrawer } = props;
    // get multi-language
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { global } = locale.business;
    const handleEdit = (app) => {
        openDrawer(true, app);
    };
    const columns = [
        {
            title: global.nameLabel,
            dataIndex: 'name',
            render: (text, app) => {
                return react_1.default.createElement(react_router_dom_1.Link, { to: `/applications/${app.id}/file/pages/list` }, text);
            },
        },
        {
            title: global.creator,
            dataIndex: 'creator',
            render: (_text, record) => {
                var _a;
                return ((_a = record.creator) === null || _a === void 0 ? void 0 : _a.account) || '--';
            },
        },
        {
            title: global.createTime,
            dataIndex: 'createTime',
            width: 200,
            render: (text) => (0, index_1.periodFormat)(text, 'unknown'),
        },
        {
            title: global.actions,
            dataIndex: '',
            width: 100,
            render: (_text, record) => {
                return (react_1.default.createElement(react_1.default.Fragment, null,
                    react_1.default.createElement(antd_1.Button, { type: "default", size: "small", shape: "circle", title: global.edit, onClick: () => {
                            handleEdit(record);
                        } },
                        react_1.default.createElement(icons_1.EditOutlined, null)),
                    react_1.default.createElement(antd_1.Button, { type: "default", size: "small", shape: "circle", title: global.userPermission, onClick: () => openAuthDrawer(true, record), style: { marginLeft: 8 } },
                        react_1.default.createElement(icons_1.UserOutlined, null))));
            },
        },
    ];
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(Table, { rowKey: "id", loading: loading, columns: columns, dataSource: list, pagination: pageInfo.total > pageInfo.size
                ? {
                    position: ['bottomCenter'],
                    current: pageInfo.page,
                    pageSize: pageInfo.size,
                    total: pageInfo.total,
                }
                : false, onChange: (pagination) => {
                fetchList({
                    page: pagination.current,
                    search: '',
                    size: pagination.pageSize,
                    organizationId,
                    type: 'user',
                });
            } })));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(ApplicationList);
