import { PayrollProcessServices } from "@gtpl/shared-services/hrms";
import { Button, Card, Col, Descriptions, Form, Row, Select } from "antd";
import logo from 'apps/ui/masters-ui/src/app/BMRpayslip.jpg';
import { PayslipGenerationReq } from "libs/shared-models/hrms/src/lib/payroll-process/payslip-generation-req";
import moment from "moment";
import React, { useEffect, useState } from "react";
import { useParams } from 'react-router-dom';

const { Option } = Select

// export const getCssFromComponent = (fromDoc, toDoc) => {
//     Array.from(fromDoc.styleSheets).forEach((styleSheet: any) => {
//         if (styleSheet.cssRules) {
//             // true for inline styles
//             const newStyleElement = toDoc.createElement("style");
//             Array.from(styleSheet.cssRules).forEach((cssRule: any) => {
//                 newStyleElement.appendChild(toDoc.createTextNode(cssRule.cssText));
//             });
//             toDoc.head.appendChild(newStyleElement);
//         }
//     });
// };

export const getCssFromComponent = (fromDoc: Document, toDoc: Document) => {
    Array.from(fromDoc.styleSheets).forEach((styleSheet: CSSStyleSheet) => {
      try {
        if (styleSheet?.cssRules) { // true for inline styles and same-origin stylesheets
          const newStyleElement = toDoc.createElement("style");
          Array.from(styleSheet.cssRules).forEach((cssRule: CSSRule) => {
            newStyleElement.appendChild(toDoc.createTextNode(cssRule.cssText));
          });
          toDoc.head.appendChild(newStyleElement);
        }
      } catch (e) {
        console.warn("Could not access stylesheet rules for", styleSheet.href, e);
      }
    });
  };

enum EmployeeMode {
    InHouse = 'In-House',
    NMR = 'NMR',
}



export const PayslipMail = ({ employeeType, yearMonth, year, employeeId }) => {
    const [form] = Form.useForm()
    const service = new PayrollProcessServices()
    const [data, setData] = useState<any[]>([])
    const [modalOpen, setModalOpen] = useState<boolean>(false)
    const [empDetails, setEmpDetails] = useState<any[]>([])
    const monthNames = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];
    // const { employeeType, yearMonth, year, employeeId } = useParams<any>();
    const [loading, setLoading] = useState(true);
    const [error, setError] = useState(null);

    
    useEffect(()=>{
        onGenerate()
    },[employeeId])
    

    const onGenerate = async () => {
        try {
            setLoading(true);
            const employeeIds = employeeId?.split(',')?.map(id => Number(id?.trim()));
            const req = new PayslipGenerationReq(employeeIds, yearMonth, employeeType, year);
            const res = await service.getPayrollLogByEmployeeId(req);
            
            if (res.status) {
                setData(res.data);
            } else {
                setError("Failed to fetch data");
            }
        } catch (err) {
            console.error("Error fetching data:", err);
            setError("An error occurred while fetching data");
        } finally {
            setLoading(false);
        }
    };

    if (loading) return <div>Loading...</div>;
    if (error) return <div>Error: {error}</div>;

    const handlePrint = () => {
        const invoiceContent = document.getElementById("print");
        if (invoiceContent) {
            const devContent = invoiceContent.innerHTML;
            const printWindow = window.open("", "PRINT", "height=900,width=1600");

            printWindow.document.write(`
                <html>
                    <head>
                        <style>
                            @page {
                                size: legal;
                                margin: 20;
                            }
                            body {
                                margin: 0;
                                transform: scale(1);
                                transform-origin: top center;
                                width:100%;
                            }
                            /* Additional styles for your content */
                        </style>
                    </head>
                    <body>${devContent}</body>
                </html>
            `);

            getCssFromComponent(document, printWindow.document);

            printWindow.document.close();
            setTimeout(function () {
                printWindow.print();
                printWindow.close();
            }, 1000); // Add a delay to ensure all content is loaded
        }
    };

    const totalAmount = (data) => {
        let totalOFRows: any = []

        const earnings = [
            parseFloat(data.basic) || 0,
            parseFloat(data.hraAmount) || 0,
            parseFloat(data.eduAmount) || 0,
            parseFloat(data.medicalAmount) || 0,
            parseFloat(data.splAmount) || 0,
            parseFloat(data.conveyanceAmount) || 0,
            parseFloat(data.petrolAmount) || 0,
            parseFloat(data.shoeAmount) || 0,
            parseFloat(data.washingAmount) || 0,
            parseFloat(data.uniformAmount) || 0,
            parseFloat(data.helperAmount) || 0,
            parseFloat(data.productionAmount) || 0,
            parseFloat(data.taAmount) || 0,
            parseFloat(data.bonusAmount) || 0,
        ];
    
        const totalEarnings = earnings.reduce((acc, curr) => acc + curr, 0);

        totalOFRows.push(totalEarnings.toFixed(2).toLocaleString());
        
        return totalOFRows
    };

    const totalGross = (data) => {
        let totalOFRows: any = []

        const earnings = [
            parseFloat(data.calBasic) || 0,
            parseFloat(data.calHra) || 0,
            parseFloat(data.calEdu) || 0,
            parseFloat(data.calMedical) || 0,
            parseFloat(data.calSpl) || 0,
            parseFloat(data.calConveyance) || 0,
            parseFloat(data.calPetrol) || 0,
            parseFloat(data.calShoe) || 0,
            parseFloat(data.calWashing) || 0,
            parseFloat(data.calHelper) || 0,
            parseFloat(data.calProduction) || 0,
            parseFloat(data.calTa) || 0,
            parseFloat(data.calBonus) || 0,
        ];
    
        const totalEarnings = earnings.reduce((acc, curr) => acc + curr, 0);
        
        totalOFRows.push(totalEarnings.toFixed(2).toLocaleString());

        return totalOFRows
    };

    const totalDeduction = (data) => {
        let totalRows: any = []
        const deductions = [
            parseFloat(data.epfAmount) || 0,
            parseFloat(data.esicAmount) || 0,
            parseFloat(data.messAmount) || 0,
            parseFloat(data.professionalTax) || 0,
            parseFloat(data.othersAmount) || 0,
            parseFloat(data.tds) || 0,
        ];
    
        const totalDeductions = deductions.reduce((acc, curr) => acc + curr, 0);

        totalRows.push(totalDeductions.toFixed(2).toLocaleString());
        
        return totalRows
    };

    const calculateNetAmount = (data) => {
        const totalEarnings = totalAmount(data);
        const totalDeductions = totalDeduction(data);
        const netAmountFromEarnings = totalEarnings - totalDeductions;
        
        return netAmountFromEarnings.toFixed(2).toLocaleString();
    };
    
    const calculateNetGross = (data) => {
        const totalGrossAmount = totalGross(data);
        const totalDeductions = totalDeduction(data);
        const netAmountFromGross = totalGrossAmount - totalDeductions;
        return netAmountFromGross.toFixed(2).toLocaleString();
    };
    
    
    const renderEarningsRow = (data) => {
        const earningsRows = [];

        if (parseFloat(data.basic) > 0) {
            earningsRows.push(
                <tr key="basic">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Basic Salary</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.basic}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calBasic}</td>
                </tr>
            );
        }
        if (parseFloat(data.hraAmount) > 0) {
            earningsRows.push(
                <tr key="hra">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>House Rent Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.hraAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calHra}</td>
                </tr>
            );
        }

        if (parseFloat(data.eduAmount) > 0) {
            earningsRows.push(
                <tr key="edu">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Education Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.eduAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calEdu}</td>
                </tr>
            );
        }

        if (parseFloat(data.medicalAmount) > 0) {
            earningsRows.push(
                <tr key="medical">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Medical Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.medicalAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calMedical}</td>
                </tr>
            );
        }
        if (parseFloat(data.splAmount) > 0) {
            earningsRows.push(
                <tr key="spl">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Special Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.splAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calSpl}</td>
                </tr>
            );
        }
        if (parseFloat(data.conveyanceAmount) > 0) {
            earningsRows.push(
                <tr key="conveyanceAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Conveyance Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.conveyanceAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calConveyance}</td>
                </tr>
            );
        }
        if (parseFloat(data.petrolAmount) > 0) {
            earningsRows.push(
                <tr key="petrolAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Petrol Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.petrolAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calPetrol}</td>
                </tr>
            );
        }
        if (parseFloat(data.shoeAmount) > 0) {
            earningsRows.push(
                <tr key="shoeAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Shoe Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.shoeAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calShoe}</td>
                </tr>
            );
        }
        if (parseFloat(data.washingAmount) > 0) {
            earningsRows.push(
                <tr key="washingAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Washing Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.washingAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calWashing}</td>
                </tr>
            );
        }
        if (parseFloat(data.uniformAmount) > 0) {
            earningsRows.push(
                <tr key="uniformAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Uniform Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.uniformAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calUniform}</td>
                </tr>
            );
        }
        if (parseFloat(data.helperAmount) > 0) {
            earningsRows.push(
                <tr key="helperAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Helper Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.helperAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calHelper}</td>
                </tr>
            );
        }
        if (parseFloat(data.productionAmount) > 0) {
            earningsRows.push(
                <tr key="productionAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Production Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.productionAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calProduction}</td>
                </tr>
            );
        }
        if (parseFloat(data.taAmount) > 0) {
            earningsRows.push(
                <tr key="taAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>TA Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.taAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calTa}</td>
                </tr>
            );
        }
        if (parseFloat(data.bonusAmount) > 0) {
            earningsRows.push(
                <tr key="bonusAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>Bonus Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.bonusAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black' }} colSpan={1}>{data.calBonus}</td>
                </tr>
            );
        }
        return earningsRows;
    };
    const renderDeductionsRow = (data) => {
        const deductionsRows = [];

        if (parseFloat(data.epfAmount) > 0) {
            deductionsRows.push(
                <tr key="epfAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>EPF </td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.epfAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.epfAmount}</td>
                </tr>
            );
        }
        if (parseFloat(data.esicAmount) > 0) {
            deductionsRows.push(
                <tr key="ESIC">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>ESIC Allowance</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.esicAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.esicAmount}</td>
                </tr>
            );
        }

        if (parseFloat(data.messAmount) > 0) {
            deductionsRows.push(
                <tr key="mess">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>Mess Deduction</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.messAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.messAmount}</td>
                </tr>
            );
        }

        if (parseFloat(data.professionalTax) > 0) {
            deductionsRows.push(
                <tr key="professionalTax">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>Professional Tax</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.professionalTax}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.professionalTax}</td>
                </tr>
            );
        }
        if (parseFloat(data.othersAmount) > 0) {
            deductionsRows.push(
                <tr key="othersAmount">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>Other Deduction</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.othersAmount}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.othersAmount}</td>
                </tr>
            );
        }
        if (parseFloat(data.tds) > 0) {
            deductionsRows.push(
                <tr key="tds">
                    <td style={{ textAlign: 'left', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>TDS</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.tds}</td>
                    <td style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{data.tds}</td>
                </tr>
            );
        }
        return deductionsRows;
    };
    
    const getMonthName = (monthData) => {
        // Extract the last two digits from monthData
        const monthIndex = parseInt(monthData?.slice(-2), 10) - 1;
        
        // Ensure the index is within the valid range
        if (monthIndex >= 0 && monthIndex < monthNames.length) {
            return monthNames[monthIndex];
        } else {
            return "Invalid Month"; // Handle invalid month data
        }
    };

    const monthName = getMonthName(yearMonth);


    return (
        <Card title={<span style={{ color: 'white', fontSize: 18 }}>Payslip Generation</span>}
            style={{ textAlign: 'center' }} headStyle={{ backgroundColor: '#45c8f6', border: 0, paddingTop: "1%", paddingBottom: "1%" }}>
            {/* <Modal visible={modalOpen} width={'80%'} footer={[]} onCancel={() => setModalOpen(false)}> */}
                <Button style={{ marginLeft: '95%' }} type='primary' onClick={handlePrint}>Print</Button>
                <br /><br />
                <div id='print'>
                    {data?.map(e => {
                        const indexRecord = empDetails?.find(rec => {
                            return (rec?.employeeId === e?.employeeId)
                        })
                        const index = indexRecord?.index

                        return (
                            <div>

                                <div style={{ marginTop: '1%' }}>
                                    {/* <b style={{ fontSize: '20px', marginLeft: '90%' }}>S.NO :-{index}</b> */}
                                    <Row style={{ border: '2px solid black' }} >
                                        <Col span={7}> <div className="logo" >
                                            <img src={logo} width={100} height={70} style={{ marginBottom: '10px', marginLeft: '20px' }}></img>
                                        </div></Col>
                                        <Col span={13} style={{ marginTop: '1%' }}>
                                            <b style={{ textAlign: 'center', fontSize: '15px' }}>BMR Industries Private Limited</b><br /><b style={{ fontSize: '13px', marginLeft: '15%' }}>PAYSLIP FOR THE MONTH OF {monthName}-{year}</b>
                                        </Col>
                                    </Row>

                                    <Row gutter={24}>
                                        <Col span={11}>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}>Employee Name </b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.employeeName}</b>
                                                </Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}>Employee No </b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.employeeCode}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}>Function </b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.department}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}>Designation </b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.designation}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}>Location</b>}><b style={{ color: 'black', fontSize: '15px' }}>Damavaram</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}
                                                >Bank</b>}><b style={{ color: 'black', fontSize: '15px' }}>{`${e?.bank ?? ''} ${e?.bankAcNo ?? ''} ${e?.ifsc ?? ''}`}</b>
                                                </Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '130px' }}>Date Of Join</b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.doj ? moment(e.doj).format('YYYY-MM-DD') : 'N/A'}</b></Descriptions.Item>
                                            </Descriptions>
                                        </Col>
                                        <Col span={12}>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '190px' }}>Tax Regime </b>}><b style={{ color: 'black', fontSize: '15px' }}>Regular Tax Regime</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '190px' }}>Income Tax Number(PAN)</b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.pan}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '190px' }}>Universal Account No </b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.uan}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '190px' }}>PF Account No </b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.pfNo}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item label={<b style={{ color: 'black', fontSize: '15px', width: '190px' }}>ESI Number</b>}><b style={{ color: 'black', fontSize: '15px' }}>{e?.esi ? e.esi : ''}</b></Descriptions.Item>
                                            </Descriptions>
                                            <Descriptions>
                                                <Descriptions.Item
                                                    label={<b style={{ color: 'black', fontSize: '15px', width: '190px' }}>PR Account No (PRAN)</b>}
                                                >
                                                    <b style={{ color: 'black', fontSize: '15px', width: '190px' }}>
                                                        {''}
                                                    </b>
                                                </Descriptions.Item>
                                            </Descriptions>
                                        </Col>
                                    </Row>
                                    <div>
                                        <table style={{ borderCollapse: 'collapse', borderBlockColor: 'black', width: '100%' }}>
                                            <thead>
                                                <tr>
                                                    <th style={{ textAlign: 'center', fontSize: '15px', border: '1px solid black', width: "153px" }} colSpan={2}>Attendance</th>
                                                    <th style={{ textAlign: 'center', fontSize: '15px', border: '1px solid black' }} colSpan={1}>Value</th>
                                                    <th colSpan={3} rowSpan={2}></th>
                                                </tr>
                                                <tr>
                                                    <td style={{ textAlign: 'left', fontSize: '15px', border: '1px solid black', paddingLeft: '10px', color: 'black' }} colSpan={2}>Attendance</td>
                                                    <td style={{ textAlign: 'right', fontSize: '15px', border: '1px solid black', paddingRight: '10px', color: 'black' }} colSpan={1}>
                                                        {Math.round(e?.attendance)} Days
                                                    </td>
                                                </tr>

                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td style={{ verticalAlign: 'top', border: '1px solid black' }} colSpan={3}>
                                                        <table style={{ width: '100%', borderCollapse: 'collapse' }}>
                                                            <tr>
                                                                <th style={{ textAlign: 'center', fontSize: '15px', borderBottom: '1px solid black', borderRight: '1px solid black' }} colSpan={1}>Earnings</th>
                                                                <th style={{ textAlign: 'center', fontSize: '15px', borderBottom: '1px solid black', borderRight: '1px solid black' }} colSpan={1}>Amount</th>
                                                                <th style={{ textAlign: 'center', fontSize: '15px', borderBottom: '1px solid black', borderRight: '1px solid black' }} colSpan={1}>Gross Salary</th>
                                                            </tr>
                                                            {renderEarningsRow(e)}
                                                        </table>
                                                    </td>
                                                    <td style={{ verticalAlign: 'top', border: '1px solid black' }} colSpan={3}>
                                                        {/* Deductions Section */}
                                                        <table style={{ width: '100%', borderCollapse: 'collapse' }}>
                                                            <tr>
                                                                <th style={{ textAlign: 'center', fontSize: '15px', borderBottom: '1px solid black', borderRight: '1px solid black' }} colSpan={1}>Deduction</th>
                                                                <th style={{ textAlign: 'center', fontSize: '15px', borderBottom: '1px solid black', borderRight: '1px solid black' }} colSpan={1}>Amount</th>
                                                                <th style={{ textAlign: 'center', fontSize: '15px', borderBottom: '1px solid black', borderRight: '1px solid black' }} colSpan={1}>Gross Salary</th>
                                                            </tr>
                                                            {renderDeductionsRow(e)}
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style={{ verticalAlign: 'top', }} colSpan={3}>
                                                        <table style={{ width: '100%', borderCollapse: 'collapse' }}>
                                                            <th style={{ textAlign: 'left', fontSize: '15px', borderLeft: '1px solid black', borderBottom: '1px solid black', width: '58%' }} colSpan={1}>Total Earnings</th>
                                                            <th style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black', width: '81px' }} colSpan={1}>{totalAmount(e)}</th>
                                                            <th style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{totalGross(e)}</th>
                                                        </table>
                                                    </td>
                                                    <td style={{ verticalAlign: 'top', }} colSpan={3}>
                                                        <table style={{ width: '100%', borderCollapse: 'collapse' }}>
                                                            <tr>
                                                                <th style={{ textAlign: 'left', fontSize: '15px', borderLeft: '1px solid black', borderBottom: '1px solid black', width: '41%' }} colSpan={1}>Total Deductions</th>
                                                                <th style={{ textAlign: 'right', fontSize: '15px', border: '1px solid black', width: '38px',borderRight: '1px solid black', borderBottom: '1px solid black' }} colSpan={1}>{totalDeduction(e)}</th>
                                                                <th style={{ textAlign: 'right', fontSize: '15px', border: '1px solid black', width: '68px' }} colSpan={1}>{totalDeduction(e)}</th>
                                                            </tr>
                                                            <tr>
                                                                <th style={{ textAlign: 'left', fontSize: '15px', borderLeft: '1px solid black', borderBottom: '1px solid black', width: '41%' }} colSpan={1}>Net Amount</th>
                                                                <th style={{ textAlign: 'right', fontSize: '15px', borderRight: '1px solid black', borderBottom: '1px solid black', width: '38px' }} colSpan={1}>{calculateNetAmount(e)}</th>
                                                                <th style={{ textAlign: 'right', fontSize: '15px', border: '1px solid black', width: '68px' }} colSpan={1}>{calculateNetGross(e)}</th>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>

                                            </tbody>
                                        </table>

                                    </div>

                                </div>

                            </div>
                        )
                    })}
                </div>
            {/* </Modal> */}
        </Card >
    )

}

export default PayslipMail