import React, { useRef, useState } from 'react';
import {  Divider, Table, Popconfirm, Card, Tooltip, Switch,Input,Button, Radio, } from 'antd';
import Highlighter from 'react-highlight-words';
import { LibSubContractorsPaymentsDto } from '@gtpl/shared-models/gtpl';
import { ColumnProps } from 'antd/lib/table';
import './sub-contractors-payments-grid.css';
import {RightSquareOutlined,EyeOutlined,EditOutlined,SearchOutlined} from '@ant-design/icons';

/* eslint-disable-next-line */
export interface SubContractorsPaymentsGridProps {
  SubContractotsPaymentsData: LibSubContractorsPaymentsDto[];
}

export function SubContractorsPaymentsGrid(
  props: SubContractorsPaymentsGridProps
) {
  const [searchText, setSearchText] = useState('');
  const [searchedColumn, setSearchedColumn] = useState('');
  const searchInput = useRef(null);

  const getColumnSearchProps = dataIndex => ({
    filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
      <div style={{ padding: 8 }}>
        <Input
          ref={ searchInput }
          placeholder={`Search ${dataIndex}`}
          value={selectedKeys[0]}
          onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
          onPressEnter={() => handleSearch(selectedKeys, confirm, dataIndex)}
          style={{ width: 188, marginBottom: 8, display: 'block' }}
        />
        <Button
          type="primary"
          onClick={() => handleSearch(selectedKeys, confirm, dataIndex)}
          icon={<SearchOutlined />}
          size="small"
          style={{ width: 90, marginRight: 8 }}
        >
          Search
        </Button>
        <Button onClick={() => handleReset(clearFilters)} size="small" style={{ width: 90 }}>
          Reset
        </Button>
      </div>
    ),
    filterIcon: filtered => (
      <SearchOutlined type="search" style={{ color: filtered ? '#1890ff' : undefined }} />
    ),
    onFilter: (value, record) =>
      record[dataIndex]
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
    onFilterDropdownVisibleChange: visible => {
      if (visible) {    setTimeout(() => searchInput.current.select());   }
    },
    render: text =>
      searchedColumn === dataIndex ? (
        <Highlighter
          highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
          searchWords={[searchText]}
          autoEscape
          textToHighlight={text.toString()}
        />
      ) : (
        text
      ),
  });
  function handleSearch(selectedKeys, confirm, dataIndex) {
    confirm();
    setSearchText(selectedKeys[0]);
    setSearchedColumn(dataIndex);
  };

  function handleReset(clearFilters) {
    clearFilters();
    setSearchText('');
  };
  const sampleTypeColumns: ColumnProps<any>[] = [
    {
      title: 'Sub Contractor',
      dataIndex: 'subContractor',
      ...getColumnSearchProps('subContractor')
    },
    {
      title: 'Payment Date',
      dataIndex: 'paymentDate',
      ...getColumnSearchProps('paymentDate')
    },
    {
      title: 'Paid Date',
      dataIndex: 'paidDate',
      ...getColumnSearchProps('paidDate')
    }
  ];
  return (
    <Table
      rowKey={record => record.Id}
      columns={sampleTypeColumns}
      dataSource={props.SubContractotsPaymentsData}
      bordered
    />
  );
}

export default SubContractorsPaymentsGrid;
