import React from 'react';
import { Dropdown, Space } from 'antd';
import { HolderOutlined } from '@ant-design/icons';

export default function renderActions(children = []) {

  // children 小于，等于 2 个直接返回
  if (children.length <= 2) {
    return (
      <Space size={8}>
        {children}
      </Space>
    );
  }

  // 第一个拿出来
  const first = children.shift();
  const items = children.map((item, index) => {
    return ({
      key: index,
      label: item,
    });
  });

  return (
    <Space size={8}>
      {first}
      <Dropdown menu={{ items }}>
        <a onClick={(e) => e.preventDefault()}>
          更多
          <HolderOutlined />
        </a>
      </Dropdown>
    </Space>
  );
}
