"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 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 select_1 = require("../select");
const Toolbar = styled_components_1.default.div `
  position: relative;
`;
const Main = (props) => {
    const { conditions, updateComponentCondition } = props;
    const [selectDrawerShow, setSelectDrawerShow] = (0, react_1.useState)(false);
    // i18n
    const { locale: i18n } = (0, react_1.useContext)(system_1.GlobalContext);
    const { global } = i18n.business;
    const columns = [
        {
            title: global.nameLabel,
            dataIndex: 'name',
            key: 'id',
            render: (_text, record) => record.content.schemas[0].name,
        },
        {
            title: global.actions,
            dataIndex: '',
            key: '',
            width: 60,
            render: (_text, record) => (react_1.default.createElement(antd_1.Popconfirm, { title: `${global.deleteMsg}${record.name}`, okText: global.yes, cancelText: global.no, onConfirm: () => updateComponentCondition(conditions.filter((condition) => condition.content.id !== record.content.id)) },
                react_1.default.createElement(antd_1.Button, { size: "small", shape: "circle", icon: react_1.default.createElement(icons_1.DeleteOutlined, null) }))),
        },
    ];
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(Toolbar, null,
            react_1.default.createElement(antd_1.Button, { type: "default", size: "small", icon: react_1.default.createElement(icons_1.PlusOutlined, null), style: { position: 'absolute', right: 0, top: -30 }, onClick: () => {
                    setSelectDrawerShow(true);
                } }, global.select)),
        react_1.default.createElement(antd_1.Table, { columns: columns, bordered: true, rowKey: (record) => record.id, pagination: false, dataSource: conditions, size: "small" }),
        react_1.default.createElement(select_1.ConditionSelect, { visible: selectDrawerShow, conditions: conditions, onChange: (selectedConditions) => {
                updateComponentCondition(selectedConditions);
            }, onClose: () => setSelectDrawerShow(false) })));
};
exports.default = Main;
