

import React, { useEffect, useState } from 'react';
import { extractLastNumber, extractLastNumberOrderId, getSession } from '../../../Services/Others';

import { printDiv } from "../../../Services/Others";

import '../../../Styles/BookingScreen/PrintTemplates/A4/PrintA4Style11.scss'
import { useSelector } from 'react-redux';
import { GloabalFieldDetails, GlobalBillName, Globalnotes, GlobalprintAmount, GlobalprintDiscount, GlobalprintHsnCode, GlobalprintItem, GlobalprintMRP, GlobalprintQrcodet, GlobalprintQuantity, GlobalprintRate, GlobalprintSignature, GlobalprintSlNo, GlobalprinttermsAndConditions, GlobalPritdummyData, GlobalSignatureImage, GlobalthemeFormat } from '../../../Features/ThemeChange/ThemeChange';
import signature from "../../../Images/signatureimage.jpg"
import QRCode from 'react-qr-code';
import { isMobile } from 'react-device-detect';


const PurPrintStyleA4 = ({ index, ExtraChargeTotal, UpiId, Date1, base64Image, totalQuantityFilter = 6, BranchCity, BranchZip, CashierName, totalQuantity,
    OrderDetailGST, OrderDetailIGST, OrderDetailVAT, table2Data, PaymentStatus, PrintGreeting, printDatas }) => {
    const GlobalthemeFormatr = useSelector(GlobalthemeFormat)
    const GlobalSignature = useSelector(GlobalprintSignature);
    const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions);
    // const FieldDetails = useSelector(GloabalFieldDetails);
    const FieldDetails = printDatas?.FieldDetails?.reduce((acc, item) => {
        acc[item.ConfigName] = true;
        return acc;
    }, {});
    const GlobalIsnotes = useSelector(Globalnotes);
    const GlobalSignatureImages = useSelector(GlobalSignatureImage);
    console.log(FieldDetails, "FieldDetails")
    const SLNO = FieldDetails?.["Sl.No"];
    const Item = FieldDetails?.["Item"];
    const MRP = FieldDetails?.["MRP"];
    const Discount = FieldDetails?.["Discount"];
    const Quantity = FieldDetails?.["Quantity"];
    const Rate = FieldDetails?.["Rate"];
    const Amount = FieldDetails?.["Amount"];
    const HsnCode = FieldDetails?.["HsnCode"];
    const Qrcodet = FieldDetails?.["Qrcode"];
    const Signature = FieldDetails?.["signature"];
    const TermsnAdCondition = FieldDetails?.["terms&conditions"];
    const GlobalQrcodet = useSelector(GlobalprintQrcodet);
    const GlobaldummyData = useSelector(GlobalPritdummyData);
    const GlobalBilltext = useSelector(GlobalBillName)
    const currentDate = new Date();
    const day = currentDate.getDate().toString().padStart(2, "0");
    const monthNames = [
        "Jan",
        "Feb",
        "Mar",
        "Apr",
        "May",
        "Jun",
        "Jul",
        "Aug",
        "Sep",
        "Oct",
        "Nov",
        "Dec",
    ];
    const monthIndex = currentDate.getMonth();
    const year = currentDate.getFullYear().toString().slice(-2);

    const formattedDate = `${day}-${monthNames[monthIndex]}-${year}`;

    const TakeawayData = table2Data?.[0]?.ProductDetails


    let TermsAndConditions = printDatas?.TermsandConditions
    let SignatureImg = printDatas?.Signature
    let Notestext = printDatas?.Notes
    let BillName = printDatas?.PrintHdrName
    let FormatTheme = printDatas?.PrintType == "S" ? true : false
    console.log(FormatTheme, "TermsAndConditions")
    const productsData = table2Data?.productDetails || [];
    const offers = table2Data?.OrderOfferDetails || [];

    let TotalOfferAmount = 0;


    let dataSource = table2Data?.[0]?.ProductDetails;
    console.log(table2Data, 'table2Datatable2Data');


    const chunkSize = 11;
    const paginatedChunks = [];
    for (let i = 0; i < dataSource.length; i += chunkSize) {
        paginatedChunks.push(dataSource.slice(i, i + chunkSize));
    }
    const lastChunkRows = paginatedChunks.length > 0 ? paginatedChunks[paginatedChunks.length - 1].length : 0;
    const shouldFooterBeOnNewPage = lastChunkRows > 6;

    return (
        <div style={{
            display: "flex",
            flexDirection: "column",
            minHeight: "297mm",
            pageBreakInside: "avoid",
        }}>

            <div className="PrintA4Style11-MasterDiv" style={{ position: "relative", width: "100%", minHeight: isMobile ? '297mm' : "257mm" }} id={`SQPrintStyleA4`}>
                {paginatedChunks.map((dataChunk, chunkIndex) => (
                    <div style={{ display: "flex", flexDirection: "column", justifyContent: "space-between", height: isMobile ? (FormatTheme ? "297mm" : "auto") : '257mm' }} className="print-page" key={chunkIndex}>
                        <div className="page-headerA4Style11" style={{ textAlign: "center" }}>

                            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', textAlign: 'left' }}>

                                <div style={{
                                    display: 'flex',
                                    justifyContent: 'space-between',
                                    alignItems: 'center',
                                    padding: '12px 0',
                                    borderBottom: '1px solid black'
                                }}>
                                    <div style={{
                                        textAlign: 'center',
                                        flex: 1,
                                        fontFamily: 'Lemon, Arial, sans-serif',
                                        fontWeight: 600
                                    }}>
                                        <div style={{
                                            fontSize: 'clamp(1.5rem, 2.5vw, 2rem)',
                                            marginBottom: '4px'
                                        }}>
                                            {table2Data?.[0]?.BranchName}
                                        </div>
                                        <div style={{
                                            fontSize: '12px',
                                            fontWeight: 400,
                                            fontFamily: 'Arial, sans-serif',
                                            lineHeight: 1.4
                                        }}>
                                            {table2Data?.[0]?.AddressDetails?.map((addr, index) => {
                                                const { Address1, City, Zip } = addr;
                                                const parts = [Address1, City, Zip].filter(Boolean).join(' - ');
                                                return <div key={index}>{parts}</div>;
                                            })}
                                            <br />
                                            Mobile: +91 {table2Data?.customerMobile}
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0rem 1rem', width: "100%" }}>
                                <div style={{ fontWeight: '600', textAlign: 'left' }}>Bill No :{table2Data?.[0]?.QuotationNo && extractLastNumber(table2Data?.[0]?.QuotationNo)}</div>
                                <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0rem 1rem', fontSize: "clamp(0.7rem, 2.5vw, 0.8rem)", }}>  <div>{Date1}</div>  </div>
                            </div>
                            <hr className="PrintA4Style11-print-dottline" />
                            < br />
                        </div>
                        <div className="print-body">
                            {TakeawayData?.length > 0 && (
                                <>
                                    <div
                                        style={{
                                            display: "flex",
                                            width: "100%",
                                            justifyContent: "center",
                                            alignItems: "center",
                                            fontSize: "12px",
                                            fontWeight: "600",
                                        }}
                                    >
                                        Take Away
                                    </div>
                                    <table className="A4TableStyle11" style={{ width: '100%' }}>
                                        <thead>
                                            <tr>
                                                <td>
                                                    <div className="page-headerA4Style11-space">  </div>
                                                </td>
                                            </tr>
                                        </thead >

                                        <tbody>
                                            <tr>
                                                <td style={{ width: '100%', }}>

                                                    <div className={FormatTheme ? "page" : ""} style={{ lineHeight: "1", fontSize: "13px" }}>
                                                        <table style={{ width: "99%", margin: "auto" }} className='A4TableA4Style11'>
                                                            <thead>
                                                                <tr style={{ background: '#373B44', color: '#fff', }}>
                                                                    {SLNO == true && <th style={{ width: '10%', textAlign: "center" }}>S.No</th>}
                                                                    {Item == true && <th>Item</th>}
                                                                    {HsnCode == true && (
                                                                        <th style={{ width: '10%', textAlign: "center" }}>HSN</th>
                                                                    )}
                                                                    {Quantity == true && (
                                                                        <th style={{ width: '10%', textAlign: "center" }}>Qty</th>
                                                                    )}
                                                                    {MRP == true && <th style={{ width: '10%', textAlign: "center" }}>MRP</th>}
                                                                    {Rate == true && <th style={{ width: '10%', textAlign: "center" }}>Rate</th>}
                                                                    {Discount == true && (
                                                                        <th style={{ width: '10%', textAlign: "center" }}>Dis </th>
                                                                    )}
                                                                    {Amount == true && (
                                                                        <th style={{ width: '10%', textAlign: "center", textAlign: "right" }}>
                                                                            Amt
                                                                        </th>
                                                                    )}
                                                                </tr>
                                                            </thead>

                                                            <tbody>
                                                                {dataChunk?.map((item, index) => (
                                                                    <tr key={index}>
                                                                        {SLNO == true && (
                                                                            <td style={{ textAlign: "center" }}>
                                                                                {chunkIndex * chunkSize + index + 1}
                                                                            </td>
                                                                        )}
                                                                        {Item == true && (
                                                                            <td style={{ display: "flex", flexDirection: "column" }}>
                                                                                <div>{item?.ProdName}</div>
                                                                                <div>
                                                                                    ({item?.Size ? item?.Size : "1"} {item?.SinglePc == "Y" ? "PCS" : item?.Type != "C" ? item?.UomName : "COMBO"})
                                                                                </div>
                                                                                &nbsp;{item?.BrandName !== null ? item?.BrandName : ""}
                                                                                &nbsp;
                                                                                {item?.ProductIdentifierDtls?.length > 0
                                                                                    ? item?.ProductIdentifierDtls?.filter(
                                                                                        (items) =>
                                                                                            !(
                                                                                                items.SerialNumber == "" ||
                                                                                                items.SerialNumber == null
                                                                                            )
                                                                                    )?.map((a) => {
                                                                                        return <div>{a.SerialNumber}</div>;
                                                                                    })
                                                                                    : ""}
                                                                                {item?.ProductIdentifierDtls?.length > 0
                                                                                    ? item?.ProductIdentifierDtls.filter(
                                                                                        (item1) =>
                                                                                            item1.IMEI1 !== "" || item1.IMEI2 !== ""
                                                                                    )?.map((item2) => {
                                                                                        const imei1 = item2.IMEI1 || "";
                                                                                        const imei2 = item2.IMEI2 || "";
                                                                                        return (
                                                                                            <div>
                                                                                                {[imei1, imei2]
                                                                                                    .filter(Boolean)
                                                                                                    .join(",")}
                                                                                            </div>
                                                                                        );
                                                                                    })
                                                                                    : ""}
                                                                            </td>
                                                                        )}
                                                                        {HsnCode == true && (
                                                                            <td style={{ textAlign: "center" }}>
                                                                                {item?.HSN}
                                                                            </td>
                                                                        )}
                                                                        {Quantity == true && (
                                                                            <td style={{ textAlign: "center" }}>
                                                                                {item?.Qty}
                                                                            </td>
                                                                        )}
                                                                        {MRP == true && (
                                                                            <td style={{ textAlign: "right" }}>
                                                                                {item?.SinglePc === "Y"
                                                                                    ? item?.Rate
                                                                                    : item?.MRP}
                                                                            </td>
                                                                        )}
                                                                        {Rate == true && (
                                                                            <td style={{ textAlign: "right" }}>
                                                                                {item?.Rate}
                                                                            </td>
                                                                        )}
                                                                        {Discount == true && (
                                                                            <td style={{ textAlign: "right" }}>
                                                                                {item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}
                                                                            </td>
                                                                        )}
                                                                        {Amount == true && (
                                                                            <td style={{ textAlign: "right" }}>
                                                                                {item?.NetAmt?.toFixed(2)}
                                                                            </td>
                                                                        )}
                                                                    </tr>
                                                                ))}
                                                            </tbody>
                                                        </table>

                                                        {((!FormatTheme) && (chunkIndex === paginatedChunks.length - 1)) && <div className="page-footerA4Style11"
                                                            style={{
                                                                marginTop: "auto",
                                                                pageBreakBefore: "avoid",
                                                                pageBreakInside: "avoid",
                                                                minHeight: "auto",
                                                            }}
                                                        >
                                                            <>
                                                                <div className='PrintA4Style11-print-ThirdDiv'>
                                                                    <div>
                                                                        <div style={{ display: 'flex', gap: '1rem', justifyContent: 'right', margin: '0.5rem 0rem', paddingRight: "1rem" }}>
                                                                            <div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                                                                                <div>ITEMS</div>
                                                                                <div>Qty</div>
                                                                                {(TotalOfferAmount > 0 || table2Data?.OverallDisc) ? (<div>OFFER</div>) : ""}
                                                                            </div>
                                                                            <div style={{ textAlign: 'right', display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                                                                                <div>{totalQuantityFilter?.length}</div>
                                                                                <div>{totalQuantity}</div>
                                                                                {(TotalOfferAmount > 0 || table2Data?.OverallDisc) ? (<div>{Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>) : ""}
                                                                            </div>
                                                                        </div>
                                                                        <div className='total-Amount' style={{ fontSize: "25px", fontWeight: "600", padding: "10px", backgroundColor: "#fdc716", textAlign: "center" }}>Amount :{Number(dataSource?.[0]?.NetAmt).toFixed(2)}</div>
                                                                    </div>
                                                                </div>
                                                                <hr className="PrintA4Style11-print-dottline" />

                                                                {OrderDetailGST?.length > 0 &&
                                                                    OrderDetailGST?.[0]?.TaxAmt > 0 && <table className="PrintA4Style11-print-table">
                                                                        <thead>
                                                                            <tr>
                                                                                <th style={{ width: '10px', textAlign: 'right' }}>CGST%</th>
                                                                                <th style={{ width: '10px', textAlign: 'right' }} >CGST Amt</th>
                                                                                <th style={{ width: '10px', textAlign: 'right' }}>SGST%</th>
                                                                                <th style={{ width: '10px', textAlign: 'right' }}>IGST%</th>
                                                                                <th style={{ width: '10px', textAlign: 'right' }}>IGST Amt</th>
                                                                            </tr>
                                                                        </thead>
                                                                        <tbody>

                                                                            {OrderDetailGST?.map((item) => (<tr  >
                                                                                <td style={{ textAlign: 'right' }}>{OrderDetailGST?.[0]?.TaxPercentage / 2}% </td>
                                                                                <td style={{ textAlign: 'right' }}> {Number(item.CGST).toFixed(2)} </td>
                                                                                <td style={{ textAlign: 'right' }}> {OrderDetailGST?.[0]?.TaxPercentage / 2}%</td>
                                                                                <td style={{ textAlign: 'right' }} >  {OrderDetailIGST?.[0]?.TaxPercentage}%</td>
                                                                                <td style={{ textAlign: 'right' }} >  {Number(item.SGST).toFixed(2)}</td>
                                                                            </tr>))}

                                                                        </tbody>
                                                                    </table>}

                                                                <div className='PrintA4Style11-print-ThirdDiv2'>
                                                                    <div style={{ display: 'flex', justifyContent: 'right', flexDirection: 'column' }}>
                                                                        <span style={{ margin: '0.5rem 0rem' }} />
                                                                    </div>
                                                                </div>

                                                                <div style={{ display: 'flex', justifyContent: "space-between", alignItems: 'center' }}>


                                                                    <div style={{ display: 'flex', alignItems: 'center', gap: '0.3rem' }}>


                                                                    </div>



                                                                </div>

                                                                <div style={{ margin: '0.5rem 0.5rem', display: 'flex', flexDirection: 'column', alignItems: "flex-start", gap: '0.5rem', height: GlobalthemeFormatr ? "13vh" : "5vh" }}>
                                                                    <div className='PrintA4Style11-print-InfoDivsub'>CASHIER : {table2Data?.customerName}</div>
                                                                    <div className='PrintA4Style11-print-InfoDivsub' style={{ textTransform: 'capitalize' }}>{Date1}</div>
                                                                </div>
                                                            </>
                                                            {GlobaldummyData ? GlobalIsnotes &&
                                                                (<div>
                                                                    <p style={{ padding: "0rem 1rem" }}>Notes : 10 days Return policy</p>

                                                                    <hr className="PrintA4Style11-print-dottline" />
                                                                </div>) :
                                                                Notestext && (<div>
                                                                    <p style={{ padding: "0rem 1rem", textAlign: "center" }}>{Notestext}</p>

                                                                    <hr className="PrintA4Style11-print-dottline" />
                                                                </div>)
                                                            }


                                                            <div style={{ display: "flex", width: "90%", padding: "0 1rem", justifyContent: GlobaltermsAndConditions ? "space-between" : "flex-end", alignItems: "center" }}>
                                                                {GlobaldummyData ? GlobaltermsAndConditions &&
                                                                    (<div style={{ margin: "8px 0", padding: "8px", fontFamily: "sans-serif", width: "100%" }}>
                                                                        <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                                                            Terms & Conditions
                                                                        </p>
                                                                        <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                                                            <li>Once goods are sold, they are not exchangeable or refundable.</li>
                                                                            <li>Please check the product before leaving the counter.</li>
                                                                        </ol>
                                                                    </div>)
                                                                    :
                                                                    (TermsnAdCondition == true && TermsAndConditions?.length > 0) && (<div style={{ margin: "8px 0", fontFamily: "sans-serif", width: "100%", display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
                                                                        <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                                                            Terms & Conditions
                                                                        </p>
                                                                        <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                                                            {TermsAndConditions?.map(item => (<li style={{ textAlign: "start" }}>{item?.TermsandConditions}</li>))}
                                                                            {/* <li>Please check the product before leaving the counter.</li> */}
                                                                        </ol>
                                                                    </div>)
                                                                }

                                                                {GlobaldummyData ? GlobalSignature && (<div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", paddingBottom: "1rem" }}>
                                                                    <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                                                    <img style={{ width: "70px", height: "40px" }} src={GlobalSignatureImages ? GlobalSignatureImages : signature} alt="" />
                                                                </div>) : Signature == true && (<div style={{ display: "flex", flexDirection: "column", alignItems: "center", marginTop: "1rem", paddingBottom: "1rem" }}>
                                                                    <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                                                    <img style={{ width: "100px", height: "60px" }} src={SignatureImg} alt="" />
                                                                </div>)}

                                                            </div>
                                                        </div>}
                                                        <hr className="PrintA4Style11-print-dottline" />
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <td>
                                                    <div className="page-footerA4Style11-space"></div>
                                                </td>
                                            </tr>
                                        </tfoot>
                                    </table >
                                </>
                            )}
                        </div>

                        {((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme && (
                            <div className="page-footerA4Style11"
                                style={{
                                    marginTop: "auto",
                                    pageBreakBefore: "avoid",
                                    pageBreakInside: "avoid",
                                    minHeight: "auto",
                                }}
                            >
                                <>
                                    <div className='PrintA4Style11-print-ThirdDiv'>
                                        <div>
                                            <div style={{ display: 'flex', gap: '1rem', justifyContent: 'right', margin: '0.5rem 0rem', paddingRight: "1rem" }}>
                                                <div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                                                    <div>ITEMS</div>
                                                    <div>Qty</div>
                                                    {(TotalOfferAmount > 0 || table2Data?.OverallDisc) ? (<div>OFFER</div>) : ""}
                                                    {/* <div className='total-Amount' style={{ fontSize: "15px", fontWeight: "600" }}>Amount</div> */}
                                                </div>
                                                <div style={{ textAlign: 'right', display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                                                    <div>{GlobaldummyData ? "7" : totalQuantityFilter?.length}</div>
                                                    <div>{GlobaldummyData ? "9" : totalQuantity}</div>
                                                    {(TotalOfferAmount > 0 || table2Data?.OverallDisc) ? (<div>{Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>) : ""}
                                                    {/* <div className='total-Amount' style={{ fontSize: "15px", fontWeight: "600" }}>{GlobaldummyData ? "1066" : Number(table2Data?.NetAmount).toFixed(2)}</div> */}
                                                </div>

                                            </div>
                                            <div className='total-Amount' style={{ fontSize: "25px", fontWeight: "600", padding: "10px", backgroundColor: "#fdc716", textAlign: "center" }}>Amount :{GlobaldummyData ? "1066" : Number(dataSource?.[0]?.NetAmt).toFixed(2)}</div>
                                        </div>
                                    </div>

                                    <hr className="PrintA4Style11-print-dottline" />

                                    {OrderDetailGST?.length > 0 &&
                                        OrderDetailGST?.[0]?.TaxAmt > 0 && <table className="PrintA4Style11-print-table">
                                            <thead>
                                                <tr>
                                                    <th style={{ width: '10px', textAlign: 'right' }}>CGST%</th>
                                                    <th style={{ width: '10px', textAlign: 'right' }} >CGST Amt</th>
                                                    <th style={{ width: '10px', textAlign: 'right' }}>SGST%</th>
                                                    <th style={{ width: '10px', textAlign: 'right' }}>IGST%</th>
                                                    <th style={{ width: '10px', textAlign: 'right' }}>IGST Amt</th>
                                                </tr>
                                            </thead>
                                            <tbody>

                                                {OrderDetailGST?.map((item) => (<tr  >
                                                    <td style={{ textAlign: 'right' }}>{OrderDetailGST?.[0]?.TaxPercentage / 2}% </td>
                                                    <td style={{ textAlign: 'right' }}> {Number(item.CGST).toFixed(2)} </td>
                                                    <td style={{ textAlign: 'right' }}> {OrderDetailGST?.[0]?.TaxPercentage / 2}%</td>
                                                    <td style={{ textAlign: 'right' }} >  {OrderDetailIGST?.[0]?.TaxPercentage}%</td>
                                                    <td style={{ textAlign: 'right' }} >  {Number(item.SGST).toFixed(2)}</td>
                                                </tr>))}

                                            </tbody>
                                        </table>}

                                    <div className='PrintA4Style11-print-ThirdDiv2'>
                                        <div style={{ display: 'flex', justifyContent: 'right', flexDirection: 'column' }}>
                                            <hr style={{ margin: '0.5rem 0rem' }} />
                                        </div>
                                    </div>

                                    <div style={{ display: 'flex', justifyContent: "space-between", alignItems: 'center' }}>


                                        <div style={{ display: 'flex', alignItems: 'center', gap: '0.3rem' }}>


                                        </div>

                                        {GlobaldummyData
                                            ? GlobalQrcodet && (
                                                <div
                                                    style={{
                                                        display: "flex",
                                                        flexDirection: "column",
                                                        justifyContent: "center",
                                                        alignItems: "center",
                                                    }}
                                                >
                                                    <QRCode
                                                        value={`upi://pay?pa=${UpiId}&pn=Merchant&am=${table2Data?.NetAmount}&cu=INR`}
                                                        size={80}
                                                    />
                                                    <div style={{ fontSize: "12px" }}>Scan to Pay </div>
                                                    <div style={{ fontSize: "12px" }}>
                                                        ₹
                                                        {GlobaldummyData
                                                            ? "1,066"
                                                            : Number(table2Data?.NetAmount).toFixed(2)}
                                                    </div>
                                                </div>
                                            )
                                            : Qrcodet &&
                                            table2Data?.PaymentTypeName == "UPI" && (
                                                <div
                                                    style={{
                                                        display: "flex",
                                                        flexDirection: "column",
                                                        justifyContent: "center",
                                                        alignItems: "center",
                                                    }}
                                                >
                                                    <QRCode
                                                        value={`upi://pay?pa=${GlobalUpiID}&pn=Merchant&am=${table2Data?.NetAmount}&cu=INR`}
                                                        size={80}
                                                    />
                                                    <div style={{ fontSize: "10px" }}>Scan to Pay </div>
                                                    <div style={{ fontSize: "10px" }}>
                                                        ₹
                                                        {GlobaldummyData
                                                            ? "1,066"
                                                            : Number(table2Data?.NetAmount).toFixed(2)}
                                                    </div>
                                                </div>
                                            )}

                                    </div>

                                    <div style={{ margin: '0.5rem 0.5rem', display: 'flex', flexDirection: 'column', alignItems: "flex-start", gap: '0.5rem', height: GlobalthemeFormatr ? "13vh" : "5vh" }}>
                                        <div className='PrintA4Style11-print-InfoDivsub'>CASHIER : {table2Data?.customerName}</div>
                                        <div className='PrintA4Style11-print-InfoDivsub' style={{ textTransform: 'capitalize' }}>{Date1}</div>
                                    </div>
                                </>
                                {GlobaldummyData ? GlobalIsnotes &&
                                    (<div>
                                        <p style={{ padding: "0rem 1rem" }}>Notes : 10 days Return policy</p>

                                        <hr className="PrintA4Style11-print-dottline" />
                                    </div>) :
                                    Notestext && (<div>
                                        <p style={{ padding: "0rem 1rem", textAlign: "center" }}>{Notestext}</p>

                                        <hr className="PrintA4Style11-print-dottline" />
                                    </div>)
                                }


                                <div style={{ display: "flex", width: "90%", padding: "0 1rem", justifyContent: GlobaltermsAndConditions ? "space-between" : "flex-end", alignItems: "center" }}>
                                    {GlobaldummyData ? GlobaltermsAndConditions &&
                                        (<div style={{ margin: "8px 0", padding: "8px", fontFamily: "sans-serif", width: "100%" }}>
                                            <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                                Terms & Conditions
                                            </p>
                                            <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                                <li>Once goods are sold, they are not exchangeable or refundable.</li>
                                                <li>Please check the product before leaving the counter.</li>
                                            </ol>
                                        </div>)
                                        :
                                        (TermsnAdCondition == true && TermsAndConditions?.length > 0) && (<div style={{ margin: "8px 0", fontFamily: "sans-serif", width: "100%", display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
                                            <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                                Terms & Conditions
                                            </p>
                                            <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                                {TermsAndConditions?.map(item => (<li style={{ textAlign: "start" }}>{item?.TermsandConditions}</li>))}
                                                {/* <li>Please check the product before leaving the counter.</li> */}
                                            </ol>
                                        </div>)
                                    }

                                    {GlobaldummyData ? GlobalSignature && (<div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", paddingBottom: "1rem" }}>
                                        <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                        <img style={{ width: "70px", height: "40px" }} src={GlobalSignatureImages ? GlobalSignatureImages : signature} alt="" />
                                    </div>) : Signature == true && (<div style={{ display: "flex", flexDirection: "column", alignItems: "center", marginTop: "1rem", paddingBottom: "1rem" }}>
                                        <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                        <img style={{ width: "100px", height: "60px" }} src={SignatureImg} alt="" />
                                    </div>)}

                                </div>
                            </div>
                        )}
                    </div >
                ))}

                {shouldFooterBeOnNewPage && FormatTheme && (
                    <div
                        className="print-page"
                        style={{
                            display: "flex",
                            flexDirection: "column",
                            minHeight: "297mm",
                            justifyContent: "flex-end",
                            pageBreakBefore: "always",
                        }}
                    >
                        <div className="page-footerA4Style11"
                            style={{
                                marginTop: "auto",
                                pageBreakBefore: "avoid",
                                pageBreakInside: "avoid",
                                minHeight: "auto",
                            }}
                        >
                            <>
                                <div className='PrintA4Style11-print-ThirdDiv'>
                                    <div>
                                        <div style={{ display: 'flex', gap: '1rem', justifyContent: 'right', margin: '0.5rem 0rem', paddingRight: "1rem" }}>
                                            <div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                                                <div>ITEMS</div>
                                                <div>Qty</div>
                                                {(TotalOfferAmount > 0 || table2Data?.OverallDisc) ? (<div>OFFER</div>) : ""}
                                                {/* <div className='total-Amount' style={{ fontSize: "15px", fontWeight: "600" }}>Amount</div> */}
                                            </div>
                                            <div style={{ textAlign: 'right', display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
                                                <div>{GlobaldummyData ? "7" : totalQuantityFilter?.length}</div>
                                                <div>{GlobaldummyData ? "9" : totalQuantity}</div>
                                                {(TotalOfferAmount > 0 || table2Data?.OverallDisc) ? (<div>{Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>) : ""}
                                                {/* <div className='total-Amount' style={{ fontSize: "15px", fontWeight: "600" }}>{GlobaldummyData ? "1066" : Number(table2Data?.NetAmount).toFixed(2)}</div> */}
                                            </div>

                                        </div>
                                        <div className='total-Amount' style={{ fontSize: "25px", fontWeight: "600", padding: "10px", backgroundColor: "#fdc716", textAlign: "center" }}>Amount :{GlobaldummyData ? "1066" : Number(dataSource?.[0]?.NetAmt).toFixed(2)}</div>
                                    </div>
                                </div>

                                <hr className="PrintA4Style11-print-dottline" />

                                {OrderDetailGST?.length > 0 &&
                                    OrderDetailGST?.[0]?.TaxAmt > 0 && <table className="PrintA4Style11-print-table">
                                        <thead>
                                            <tr>
                                                <th style={{ width: '10px', textAlign: 'right' }}>CGST%</th>
                                                <th style={{ width: '10px', textAlign: 'right' }} >CGST Amt</th>
                                                <th style={{ width: '10px', textAlign: 'right' }}>SGST%</th>
                                                <th style={{ width: '10px', textAlign: 'right' }}>IGST%</th>
                                                <th style={{ width: '10px', textAlign: 'right' }}>IGST Amt</th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                            {OrderDetailGST?.map((item) => (<tr  >
                                                <td style={{ textAlign: 'right' }}>{OrderDetailGST?.[0]?.TaxPercentage / 2}% </td>
                                                <td style={{ textAlign: 'right' }}> {Number(item.CGST).toFixed(2)} </td>
                                                <td style={{ textAlign: 'right' }}> {OrderDetailGST?.[0]?.TaxPercentage / 2}%</td>
                                                <td style={{ textAlign: 'right' }} >  {OrderDetailIGST?.[0]?.TaxPercentage}%</td>
                                                <td style={{ textAlign: 'right' }} >  {Number(item.SGST).toFixed(2)}</td>
                                            </tr>))}

                                        </tbody>
                                    </table>}

                                <div className='PrintA4Style11-print-ThirdDiv2'>
                                    <div style={{ display: 'flex', justifyContent: 'right', flexDirection: 'column' }}>
                                        <hr style={{ margin: '0.5rem 0rem' }} />
                                    </div>
                                </div>

                                <div style={{ display: 'flex', justifyContent: "space-between", alignItems: 'center' }}>


                                    <div style={{ display: 'flex', alignItems: 'center', gap: '0.3rem' }}>


                                    </div>

                                    {GlobaldummyData
                                        ? GlobalQrcodet && (
                                            <div
                                                style={{
                                                    display: "flex",
                                                    flexDirection: "column",
                                                    justifyContent: "center",
                                                    alignItems: "center",
                                                }}
                                            >
                                                <QRCode
                                                    value={`upi://pay?pa=${UpiId}&pn=Merchant&am=${table2Data?.NetAmount}&cu=INR`}
                                                    size={80}
                                                />
                                                <div style={{ fontSize: "12px" }}>Scan to Pay </div>
                                                <div style={{ fontSize: "12px" }}>
                                                    ₹
                                                    {GlobaldummyData
                                                        ? "1,066"
                                                        : Number(table2Data?.NetAmount).toFixed(2)}
                                                </div>
                                            </div>
                                        )
                                        : Qrcodet &&
                                        table2Data?.PaymentTypeName == "UPI" && (
                                            <div
                                                style={{
                                                    display: "flex",
                                                    flexDirection: "column",
                                                    justifyContent: "center",
                                                    alignItems: "center",
                                                }}
                                            >
                                                <QRCode
                                                    value={`upi://pay?pa=${GlobalUpiID}&pn=Merchant&am=${table2Data?.NetAmount}&cu=INR`}
                                                    size={80}
                                                />
                                                <div style={{ fontSize: "10px" }}>Scan to Pay </div>
                                                <div style={{ fontSize: "10px" }}>
                                                    ₹
                                                    {GlobaldummyData
                                                        ? "1,066"
                                                        : Number(table2Data?.NetAmount).toFixed(2)}
                                                </div>
                                            </div>
                                        )}

                                </div>

                                <div style={{ margin: '0.5rem 0.5rem', display: 'flex', flexDirection: 'column', alignItems: "flex-start", gap: '0.5rem', height: GlobalthemeFormatr ? "13vh" : "5vh" }}>
                                    <div className='PrintA4Style11-print-InfoDivsub'>CASHIER : {table2Data?.customerName}</div>
                                    <div className='PrintA4Style11-print-InfoDivsub' style={{ textTransform: 'capitalize' }}>{Date1}</div>
                                </div>
                            </>
                            {GlobaldummyData ? GlobalIsnotes &&
                                (<div>
                                    <p style={{ padding: "0rem 1rem" }}>Notes : 10 days Return policy</p>

                                    <hr className="PrintA4Style11-print-dottline" />
                                </div>) :
                                Notestext && (<div>
                                    <p style={{ padding: "0rem 1rem", textAlign: "center" }}>{Notestext}</p>

                                    <hr className="PrintA4Style11-print-dottline" />
                                </div>)
                            }


                            <div style={{ display: "flex", width: "90%", padding: "0 1rem", justifyContent: GlobaltermsAndConditions ? "space-between" : "flex-end", alignItems: "center" }}>
                                {GlobaldummyData ? GlobaltermsAndConditions &&
                                    (<div style={{ margin: "8px 0", padding: "8px", fontFamily: "sans-serif", width: "100%" }}>
                                        <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                            Terms & Conditions
                                        </p>
                                        <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                            <li>Once goods are sold, they are not exchangeable or refundable.</li>
                                            <li>Please check the product before leaving the counter.</li>
                                        </ol>
                                    </div>)
                                    :
                                    (TermsnAdCondition == true && TermsAndConditions?.length > 0) && (<div style={{ margin: "8px 0", fontFamily: "sans-serif", width: "100%", display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
                                        <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                            Terms & Conditions
                                        </p>
                                        <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                            {TermsAndConditions?.map(item => (<li style={{ textAlign: "start" }}>{item?.TermsandConditions}</li>))}
                                            {/* <li>Please check the product before leaving the counter.</li> */}
                                        </ol>
                                    </div>)
                                }

                                {GlobaldummyData ? GlobalSignature && (<div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", paddingBottom: "1rem" }}>
                                    <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                    <img style={{ width: "70px", height: "40px" }} src={GlobalSignatureImages ? GlobalSignatureImages : signature} alt="" />
                                </div>) : Signature == true && (<div style={{ display: "flex", flexDirection: "column", alignItems: "center", marginTop: "1rem", paddingBottom: "1rem" }}>
                                    <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                    <img style={{ width: "100px", height: "60px" }} src={SignatureImg} alt="" />
                                </div>)}

                            </div>
                        </div>
                    </div>
                )}
            </div>

        </div>

    );
};

export default PurPrintStyleA4;
