/**
 * @desc 操作列
 * @author 邓欢
 */
import React, { useState } from 'react';
import { LoadingOutlined } from '@ant-design/icons';
import styled from 'styled-components';
const StyledOperation = styled.div `
    display: flex;

    justify-content:${props => props.operationNum > 1 ? 'space-between' : 'flex-end'}
  }
`;
const StyleOperationBtn = styled.span `
  cursor: ${props => (props.isEnable ? 'pointer' : 'not-allowed')};
  color: ${props => props.isEnable ? props.theme.main : props.theme.text.tertiary};
`;
export default function OperationCol(props) {
    const { operation } = props;
    return (React.createElement(StyledOperation, { className: "operation-wrapper", operationNum: operation.length }, operation.map((item, key) => {
        return React.createElement(OperationItem, { key: key, operationItem: item, props: props });
    })));
}
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] = useState(false);
    const opertor = () => {
        if (hasLoadingStatus) {
            setLoadingFlag(true);
            operationFunc && operationFunc(props, () => setLoadingFlag(false));
        }
        else {
            operationFunc && operationFunc(props);
        }
    };
    return (React.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.createElement(LoadingOutlined, { spin: true }) : title));
}
