import styled from "@emotion/styled";
import axios from "axios";
import { useEffect, useState } from "react";
import { Col, Container, Row, Table, Tabs, Tab, Form, InputGroup, Button, Card } from "react-bootstrap";
import { RModalImages } from "react-modal-images";
import YearSelect from "./YearSelect";
const Wrapper = styled.div`
img{  
    width: 50px;
}
.react_modal_images__medium_img, .react_modal_images__large_img{
    position: absolute;
    top: 50%;
    left: 50%;
    overflow: hidden;
    max-width: 98%;
    max-height: 98%;
    transform: translate3d(-50%, -50%, 0px) rotate(0deg);
    background-color: black;
    width:auto !important;
}
.nav-link{
    padding:10px;
}
`

const  AllEmpITDList =()=>{
    const [empdata, setEmpData] = useState([]);
    const [empid, setEmpID] = useState("");
    const [fromyear, setFromYear] = useState("");
    const [filterData,setFilterData]=useState<any>([])  

        const fetchEmp = async () => {
          try {
            let emp_id = empid;
            let from_year= fromyear;
            let to_year=parseInt(fromyear) + 1;
            const res = await axios.get(`/api/user/itd_old_regime?&emp_id=${emp_id}&from_year=${from_year}&to_year=${to_year}`);
            setEmpData(res.data.results[0]);
          
            console.log("Employee ITD Data", res);
          } catch (error) {
            console.log(error, "Error Fetching Employee ITD Request Data");
          }
        };
      
        const itdData=async()=>{
            const res=await axios.get(`/api/user/itd_old_regime_all`)
            console.log(res.data.results[0],'jjjjjjjj');
            setFilterData(res.data.results[0])
            
         }
         useEffect(()=>{
           itdData()
         },[])

    //   const handleSearch=()=>{
    //     const resultData = empdata?.filter((item:any)=>{
    //      return item.emp_id?.toLowerCase().match(empid?.toLowerCase())
    //     })
    //     setempdata(resultData)
    //     console.log(resultData,"data");
        
    //   }
    //   console.log(empdata, "ITD Data");
    return(<>
    <Container>
        <Row>
            <Col lg="12" className="mb-3">
                <Card>
                    <Card.Body>
                <Form as={Row} className="d-flex justify-content-center">
                    <Col lg="6" sm="12">
                    <InputGroup>
                        <Form.Select name="emp_id"  onChange={(e)=>setEmpID(e.target.value)}>
                            <option>Select Emp. ID</option>
                            {Array.from(new Set(filterData.map((emp: any) => emp?.emp_id))).map((uniqueEmpID: any, i: any) => {
    return <option key={i} value={uniqueEmpID}>{uniqueEmpID}</option>
  })}

                        </Form.Select>

                        <Form.Select name="from_year"  placeholder="Starting Year" onChange={(e)=>setFromYear(e.target.value)}>
                            <option>Select Year</option>
                            <YearSelect/>
                            
                        </Form.Select>
                       
                        
                        {/* <Form.Control
                        type="text"
                        placeholder="Closing Year"
                        aria-describedby="basic-addon2"
                        name="to_year"
                        onChange={(e)=>setToYear(e.target.value)}
                        /> */}
                        <Button variant="outline-secondary"
                        onClick={  fetchEmp}
                        id="button-addon2">
                        Search
                        </Button>
                    </InputGroup>
                </Col>
                </Form>
                </Card.Body>
                </Card>
            </Col>
            <Col lg="12">
            <Wrapper>
            <Tabs
      defaultActiveKey="one"
      id="uncontrolled-tab-example"
    >
     
      <Tab eventKey="one" title="DEDUCTION U/S 10">
      <Table responsive bordered >
      {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
                <tbody key={index}>
                    <tr>
                    <th>Emp. PAN</th>
                    <td>{emp.emp_pan}</td>
                    </tr>
                    <tr>
                    <th>I am staying in a rented house and I agree to submit Leave &
                    Licence A&apos;ment when required.The Rent Paid is&#40;Rs.
                    _____________ X _______ months&#41;
                    </th>	
                    <td>{emp.house_rent}</td>
                    </tr>
                    <tr>
                    <th>Residence</th>
                    <td>{emp.residence}</td>	
                    </tr>
                    <tr>
                    <th>House Rent Bill</th>
                    <td>
                    <RModalImages
                    small={`/${emp.rent_file}`}
                    medium={`/${emp.rent_file}`}
                    large={`/${emp.rent_file}`}
                    alt={"80cc Bill"}
                    
                />
                    </td>	
                    </tr>
                </tbody>
                        )})}
            </Table>
                  </Tab>
      <Tab eventKey="two" title="CHAPTER - VI A">
        <Table responsive bordered>
        {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
                        
            <tbody key={index}>
                <tr>
                    <th>Sec 80D - Medical Insurance Premium &#40;If the policy covers a
senior citizen then exemption is Rs.50,000/-&#41;</th>	
                    <td>{emp.medic_insur_prem_80d}</td>
                </tr>
               
                <tr>    
                    <th>Sec 80DD - Handicapped Dependent</th>	
                    <td>{emp.handicap_depend_80dd}</td>
                </tr>
                      <tr>    
                    <th>Sec 80E - Repayment of Loan for higher education&#40;only Interest &#41;</th>	
                    <td>{emp.high_edu_loan_80e}</td>
                </tr>
                <tr>    
                    <th>Sec 80GG - Rent Paid</th>
                    <td>{emp.paid_rent_80gg}</td>
                </tr>
                <tr>    
                    <th>Sec 80U - Handicapped</th>
                    <td>{emp.handicap_80u}</td>
                </tr>
                <tr>    
                    <th>Sec 80CCG - Rajeev Gandhi Equity Saving Scheme
(Investment max upto Rs.50,000, would get a deduction of 50% on
the amount invested)</th>
                    <td>{emp.raj_gandhi_scheme_80ccg}</td>
                </tr>
                <tr>    
                    <th>Sec 80TTA / 80TTB - Interest on saving a/c</th>
                    <td>{emp.int_on_saving_80tta}</td>
                </tr>
                <tr>
                    <th>Any other Deduction&#40;Please specify &#41;</th>	
                    <td>{emp.other_deduct}</td>
                </tr>
                <tr>
                    <th>Chapter VI A Bill</th>	
                    <td>
                    <RModalImages
                    small={`/${emp.chapter_vi_a_file}`}
                    medium={`/${emp.chapter_vi_a_file}`}
                    large={`/${emp.chapter_vi_a_file}`}
                    alt={"80cc Bill"}
                /></td>
                </tr>
                </tbody>
                        )})}
        </Table>
      </Tab>
      <td>
deduct_80c_file
</td> 
      <Tab eventKey="three" title="DEDUCTION U/S 80C" >
        <Table responsive bordered>
        {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
                        
                <tbody key={index}>
                        <tr>
                        <th>Contribution to Pension Fund&#40;Jeevan Suraksha &#41;</th>
                        <td>{emp.pf_jeevan_suraksha}</td>
                        </tr>
                        <tr>
                        <th>Life Insurance Premium on life of self/spouse/child only</th>
                        <td>{emp.lic}</td>
                        </tr>
                        <tr>
                        <th>Deferred Annuity</th>
                        <td>{emp.deferred_annuity}</td>	
                        </tr>
                        <tr>
                        <th>Public Provident Fund in own name/spouse/child only	</th>
                        <td>{emp.public_pf}</td>
                        </tr>
                        <tr>
                        <th>ULIP of UTI/LIC in own name or spouse and child only	</th>
                        <td>{emp.ulip_uti_lic}</td>
                        </tr>
                        <tr>
                        <th>Repayment of Housing Loan&#40;Only principal &#41;</th>
                        <td>{emp.housing_loan_repay}</td>
                        </tr>
                        <tr>
                        <th>Contribution to Pension Fund or UTI or Notified Mutual Fund	</th>
                        <td>{emp.pf_uti_mutual_fund}</td>
                        </tr>
                        <tr>
                        <th>Investment in ELSS made in units of Notified Mutual Fund</th>
                        <td>{emp.invest_elss}</td>
                        </tr>
                        <tr>
                            <th>Children Tuition Fee: Restricted to a max of 2 Children	</th>
                            <td>{emp.child_tution_fee}</td>
                        </tr>
                        <tr>
                        <th>Deposit in home loan account scheme of NHB/HDFC	</th>
                        <td>{emp.deposit_home_looan_sch}</td>
                        </tr>
                        <tr>
                        <th>5 yrs. Term deposit in a Sch.Bank	</th>	
                        <td>{emp.five_yrs_bank_deposit}</td>
                        </tr>
                        <tr>
                        <th>Others&#40;please specify &#41;</th>
                        <td>{emp.other}</td>
                        </tr>
                        <tr>
                        <th>Others&#40;please specify &#41;	</th>	
                        <td>{emp.others}</td>
                        </tr>
                        <tr>
                    <th>Bill</th>
                    <td><RModalImages
                    small={`/${emp.deduct_80c_file}`}
                    medium={`/${emp.deduct_80c_file}`}
                    large={`/${emp.deduct_80c_file}`}
                    alt={"80cc Bill"}
                /></td>
                </tr>
                    </tbody>
                        )})}
            </Table>
      </Tab>
      <Tab eventKey="four" title="DEDUCTION U/S 80CCC" >
        <Table responsive bordered>
        {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
        <tbody key={index}>
            <tr>
                <th>Annuity/Pension Plan</th>
                <td>{emp.annuity_pension_plan}</td>
            </tr>
            <tr>
                    <th>Bill</th>
                    <td><RModalImages
                    small={`/${emp.deduct_80ccc_file}`}
                    medium={`/${emp.deduct_80ccc_file}`}
                    large={`/${emp.deduct_80ccc_file}`}
                    alt={"80ccc Bill"}
                /></td>
                </tr>
        </tbody>
                        )})}
        </Table>
      </Tab>
      <Tab eventKey="five" title="DEDUCTION U/S 80CC(1b)" >
        <Table responsive bordered>
        {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
            <tbody key={index}>
                <tr>
                    <th>Employee Contribution</th>
                    <td>{emp.emp_contri}</td>
                </tr>
                <tr>
                    <th>Bill</th>
                    <td><RModalImages
                    small={`/${emp.deduct_80cc_file}`}
                    medium={`/${emp.deduct_80cc_file}`}
                    large={`/${emp.deduct_80cc_file}`}
                    alt={"80cc Bill"}
                /></td>
                </tr>
            </tbody>
                        )})}
        </Table>
      </Tab>
      <Tab eventKey="six" title="DEDUCTION U/S 80CCD	" >
      <Table responsive bordered>
      {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
                        
            <tbody key={index}>
                <tr>
                    <th>Notified Pension Scheme	</th>
                    <td>{emp.notif_pens_sch}</td>
                </tr>
                <tr>
                    <th>Bill</th>
                    <td><RModalImages
                    small={`/${emp.deduct_80ccd_file}`}
                    medium={`/${emp.deduct_80ccd_file}`}
                    large={`/${emp.deduct_80ccd_file}`}
                    alt={"80ccd Bill"}
                /></td>
                </tr>
            </tbody>
                        )})}
        </Table>
      </Tab>
      <Tab eventKey="seven" title="DEDUCTION U/S 24	" >
      <Table responsive bordered>
      {empdata &&
                    empdata.map((emp: any, index: any) => {
                        return(
            <tbody key={index}>
                <tr>
                    <th>Interest on Housing Loan on fully constructed accomodation only	</th>
                    <td>{emp.int_house_loaan}</td>
                </tr>
                <tr>
                    <th>Interest if the loan is taken before 01/04/99 on fully constructed accomodation only.	</th>
                    <td>{emp.int_loan_const_acco}</td>
                </tr>
                <tr>
                    <th>Bill</th>
                    <td><RModalImages
                    small={`/${emp.deduct_us24_file}`}
                    medium={`/${emp.deduct_us24_file}`}
                    large={`/${emp.deduct_us24_file}`}
                    alt={"US24 Bill"}
                /></td>
                </tr>
                
            </tbody>
              )})}
        </Table>
      </Tab>
               
    </Tabs>
    </Wrapper>
            </Col>
        </Row>
    </Container>
    </>)
}
export default AllEmpITDList;