import React, { useState, useEffect, useRef } from 'react';
import {  Divider, Table, Popconfirm, Card, Tooltip, Switch,Input,Button, } from 'antd';
import Highlighter from 'react-highlight-words';
import { EmployeesPaymentStatusDto, EmployeesPayments,EmployeesPaymentsRequest, EmployeePaymentsDto, EmployeePaymentsResponse,EmployeePaymentsStatusResponse } from '@gtpl/shared-models/gtpl';
import { ColumnProps } from 'antd/lib/table';
import { FormattedMessage } from 'react-intl';
import { AlertMessages } from '@gtpl/shared-utils/alert-messages';
import { useIntl } from 'react-intl';
import {RightSquareOutlined,EyeOutlined,EditOutlined,SearchOutlined} from '@ant-design/icons';

import './employees-payment-status-grid.css';

/* eslint-disable-next-line */
export interface EmployeesPaymentStatusGridProps {
  EmployeesPaymentStatusData: EmployeePaymentsDto[];
  AttendanceIds: EmployeePaymentsDto[];
  viewStatus: (Status: EmployeePaymentsDto, viewOnly: boolean) => void;
  makePayment: (Status: any) => void;
  // deleteStatus: (Status: EmployeesPaymentStatusDto) => void;
}

export function EmployeesPaymentStatusGrid(props: EmployeesPaymentStatusGridProps) {
  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 makePayment=()=>{
    props.makePayment(props.AttendanceIds);
  }
  const sampleTypeColumns: ColumnProps<any>[] = [
    {
      title: 'S No',
      key: 'sno',
      width: '70px',
      render: (text, object, index) => index+1
    
    },
    {
      title: 'Employee Name',
      dataIndex: 'empName',
      ...getColumnSearchProps('empName')
    },
    {
      title: 'Working Days',
      dataIndex: 'workingDays'

    },
    {
      title: 'OT Hours',
      dataIndex: 'otHrs'
    }, 
  ]
  
  return (
    <>
    
    <Button type='primary' onClick={makePayment} style={{ float: 'right', display: "block" }}>Make Payment</Button>
    <Table
      rowKey={record => record.Id}
      columns={sampleTypeColumns}
      dataSource={props.EmployeesPaymentStatusData}
      bordered
    />
    </>
  );

};
export default EmployeesPaymentStatusGrid;
