// Libs
// -----------------------------------------------------------------------------
import { Button, Space, TableColumnProps } from 'antd';
import { DeleteOutlined, EditOutlined } from '@ant-design/icons';

// App
// -----------------------------------------------------------------------------
import { InterfaceWithIdNameDescription } from 'types/default';
import { GenericGroupsDashboardLocale } from './types';

export const makeGenericGroupsTableColumns = (
  locale: GenericGroupsDashboardLocale,
  actions: { onDelete: (id: number) => void; onEdit: () => void },
): Array<TableColumnProps<InterfaceWithIdNameDescription>> => {
  return [
    {
      title: locale.id,
      dataIndex: 'id',
      key: 'id',
      align: 'center',
      width: '10%',
      sorter: true,
    },
    {
      title: locale.name,
      dataIndex: 'name',
      key: 'name',
      align: 'center',
      width: '30%',
      sorter: true,
    },
    {
      title: locale.description,
      dataIndex: 'description',
      key: 'description',
      align: 'left',
      width: '50%',
    },
    {
      title: locale.actions,
      dataIndex: 'actions',
      key: 'actions',
      align: 'center',
      width: '10%',
      render: (_value, rule) => (
        <Space>
          <Button
            type="link"
            icon={<EditOutlined />}
            title={locale.edit}
            onClick={() => {
              actions.onEdit();
            }}
          />
          <Button
            onClick={(ev) => {
              ev.stopPropagation();
              actions.onDelete(rule.id);
            }}
            type="link"
            title={locale.delete}
            icon={<DeleteOutlined />}
          />
        </Space>
      ),
    },
  ];
};
