"use strict";
/**
 * @desc 操作列
 * @author 邓欢
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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 styled_components_1 = __importDefault(require("styled-components"));
const StyledOperation = styled_components_1.default.div `
    display: flex;

    justify-content:${props => props.operationNum > 1 ? 'space-between' : 'flex-end'}
  }
`;
const StyleOperationBtn = styled_components_1.default.span `
  cursor: ${props => (props.isEnable ? 'pointer' : 'not-allowed')};
  color: ${props => props.isEnable ? props.theme.main : props.theme.text.tertiary};
`;
function OperationCol(props) {
    const { operation } = props;
    return (react_1.default.createElement(StyledOperation, { className: "operation-wrapper", operationNum: operation.length }, operation.map((item, key) => {
        return react_1.default.createElement(OperationItem, { key: key, operationItem: item, props: props });
    })));
}
exports.default = OperationCol;
function OperationItem(operationProps) {
    const { operationItem, props } = operationProps;
    const { data } = props;
    const { operationText: title, operationFunc, hasLoadingNode: hasLoadingStatus = false, } = operationItem;
    // 操作项是否可用
    const isEnable = (operationItem.isEnable && operationItem.isEnable(data)) ||
        !operationItem.isEnable;
    const hidden = operationItem.hidden && operationItem.hidden(data);
    const [loadingFlag, setLoadingFlag] = react_1.useState(false);
    const opertor = () => {
        if (hasLoadingStatus) {
            setLoadingFlag(true);
            operationFunc && operationFunc(props, () => setLoadingFlag(false));
        }
        else {
            operationFunc && operationFunc(props);
        }
    };
    return (react_1.default.createElement(StyleOperationBtn, { style: {
            visibility: hidden ? 'hidden' : 'visible',
            display: 'flex',
            justifyContent: 'center',
            alignItems: 'center',
            minWidth: `${title.length * 14}px`,
        }, isEnable: isEnable, onClick: isEnable ? () => opertor() : undefined }, hasLoadingStatus && loadingFlag ? react_1.default.createElement(icons_1.LoadingOutlined, { spin: true }) : title));
}
