"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 antd_1 = require("antd");
const ACTIONS = __importStar(require("@/actions/teams/list"));
const index_1 = require("@/components/index");
const system_1 = require("@/pages/system");
const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 18 },
};
const mapStateToProps = (store) => ({
    organizationId: store.system.user.organizationId,
    pageInfo: store.teams.list.pageInfo,
    editTeam: store.teams.list.editTeam,
    editDrawerOpen: store.teams.list.editDrawerOpen,
});
const mapDispatchToProps = {
    closeDrawer: ACTIONS.openDrawer,
    updateTeamValue: ACTIONS.updateEditTeamValue,
    saveTeam: ACTIONS.saveTeam,
    fetchList: ACTIONS.fetchTeamList,
};
const Drawer = (props) => {
    const { organizationId, pageInfo, editTeam, editDrawerOpen, closeDrawer, updateTeamValue, saveTeam, fetchList, } = props;
    // get multi-language
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { global, team } = locale.business;
    const handleApply = () => {
        if (organizationId) {
            saveTeam({ organizationId, team: editTeam }, () => {
                closeDrawer(false);
                // refresh team list
                fetchList({ organizationId, page: pageInfo.page, size: pageInfo.size });
            });
        }
    };
    return (react_1.default.createElement(index_1.OperationDrawer, { destroyOnClose: true, title: (editTeam === null || editTeam === void 0 ? void 0 : editTeam.id) ? team.edit : team.add, width: 480, open: editDrawerOpen, actions: react_1.default.createElement(antd_1.Button, { type: "primary", onClick: handleApply }, global.apply), onClose: () => closeDrawer(false) }, editTeam ? (react_1.default.createElement("div", { style: { padding: 12 } },
        react_1.default.createElement(antd_1.Form.Item, Object.assign({}, formItemLayout, { label: team.nameLabel }),
            react_1.default.createElement(antd_1.Input, { defaultValue: editTeam.name, placeholder: team.nameLabel, onChange: (e) => updateTeamValue('name', e.target.value) })))) : (react_1.default.createElement("div", null))));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(Drawer);
