/* eslint-disable import/prefer-default-export */
import type { ColumnsType } from 'antd/lib/table';
import { MAX_INSURANCE } from 'constants/values';
import { formatter, parser } from 'tools/number';
import InputNumber from 'ui/elements/InputNumber';
import Select from 'ui/elements/Select';
import { buildOptionComponent, buildValueComponent } from './builders';
import type * as Insurance from './types';

export const columns: ColumnsType<Insurance.RowValues> = [
  {
    key: 'policyType',
    dataIndex: 'policyType',
    title: 'Тип полиса',
  },
  {
    key: 'insuranceCompany',
    dataIndex: 'insuranceCompany',
    title: 'Страховая компания',
    width: 300,
    render: (_, record) => {
      const Component = buildOptionComponent(record.key, Select, 'insuranceCompany');

      return <Component showSearch optionFilterProp="label" />;
    },
  },
  {
    key: 'insured',
    dataIndex: 'insured',
    title: 'Плательщик',
    render: (_, record) => {
      const Component = buildOptionComponent(record.key, Select, 'insured');

      return <Component />;
    },
  },
  {
    key: 'insCost',
    dataIndex: 'insCost',
    title: 'Стоимость за 1-й период',
    render: (_, record) => {
      const Component = buildValueComponent(record.key, InputNumber, 'insCost');

      return (
        <Component
          min={0}
          max={MAX_INSURANCE}
          step={1000}
          precision={2}
          parser={parser}
          formatter={formatter}
          addonAfter="₽"
        />
      );
    },
  },
  {
    key: 'insTerm',
    dataIndex: 'insTerm',
    title: 'Срок страхования',
    render: (_, record) => {
      const Component = buildOptionComponent(record.key, Select, 'insTerm');

      return <Component />;
    },
  },
];
