import React from "react";
import { useDispatch, useSelector } from "react-redux";
import {
  GlobalPritdummyData,
  changeReprintDataFound,
  GlobalprinttermsAndConditions,
} from '../../../Features/ThemeChange/ThemeChange'
import '../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle5.scss'
import { extractLastNumber } from "../../../Services/Others";
import { isMobile } from "react-device-detect";


const PurPrintStyle5 = ({ index, ExtraChargeTotal, totalQuantityFilter, Date1, CashierName, totalQuantity, OrderDetailGST, OrderDetailIGST,
  OrderDetailVAT, table2Data, PaymentStatus, PrintGreeting, printDatas }) => {

  console.log(table2Data, 'table2Data')
  const dispatch = useDispatch();

  const FieldDetails = printDatas?.FieldDetails?.reduce((acc, item) => {
    acc[item.ConfigName] = true;
    return acc;
  }, {});

  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 GlobaldummyData = useSelector(GlobalPritdummyData);
  const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions);


  let TermsAndConditions = printDatas?.TermsandConditions
  let SignatureImg = printDatas?.Signature
  let Notestext = printDatas?.Notes
  let BillName = printDatas?.PrintHdrName
  let FormatTheme = printDatas?.PrintType == "S" ? true : false
  let PageSize = printDatas?.PageSize
  const Signature = FieldDetails?.["signature"];
  const TermsnAdCondition = FieldDetails?.["terms&conditions"];


  const keysLength = Object.keys(table2Data ?? {}).length;
  if (keysLength > 0) {
    dispatch(changeReprintDataFound(true));
  }

  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
  console.log(TakeawayData, "TakeawayData", table2Data)





  let TotalOfferAmount = 0;

  // Calculate SalesWiseOffers total amount


  const chunkSize = PageSize == "A5" ? 5 : 11;
  let dataSource = table2Data?.[0]?.ProductDetails;



  // Paginate the data
  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 > (PageSize == "A5" ? 2 : 10);

  return (
    <>
      {FormatTheme ?
        <div className="PrintStyle5-MasterDiv" id={`SQPrintStyle5`} style={{ fontFamily: "'Courier New', Courier, monospace", position: "relative", width: "100%", minHeight: isMobile ? (PageSize === "A5" ? "210mm" : "297mm") : "auto" }}>
          {paginatedChunks.map((dataChunk, chunkIndex) => (
            <div className={`container print-chunk${chunkIndex > 0 ? ' print-page-break' : ''}`} style={{ display: "flex", flexDirection: "column", justifyContent: ((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme ? "space-between" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : "257mm" : "", }} key={chunkIndex}>

              {/* <div className="header" style={{ position: "fixed", top: 0, width: "100%" }}> */}
                <div className="header" style={{ position: isMobile ? GlobaldummyData ? "absolute" : "fixed" : "", top: 0, width: "100%" }}>
                <div className="PrintStyle5-Head">
                  <div>
                    <div style={{ fontSize: 'clamp(2rem, 2.5vw, 2rem)', fontWeight: '600' }}>{table2Data?.[0]?.BrName}</div>

                  </div>


                  <div>{
                    (table2Data?.[0]?.AddressDetails?.[0]?.Address1 || '') + (table2Data?.[0]?.AddressDetails?.[0]?.City ? (table2Data?.[0]?.AddressDetails?.[0]?.Address1 && table2Data?.[0]?.AddressDetails?.[0]?.City ? '-' : '') + table2Data?.[0]?.AddressDetails?.[0]?.City : '') + (table2Data?.[0]?.AddressDetails?.[0]?.Zip ? (table2Data?.[0]?.AddressDetails?.[0]?.City && table2Data?.[0]?.AddressDetails?.[0]?.Zip ? '-' : '') + table2Data?.[0]?.AddressDetails?.[0]?.Zip : '')}
                  </div>
                  <div style={{ fontSize: "14px", fontWeight: '600' }}> Mobile :{GlobaldummyData ? '1234567890' : table2Data?.[0]?.BrMobile} </div>
                  {<div style={{ textTransform: 'uppercase' }}>{BillName}  </div>}

                  <hr />
                </div>


                <div style={{ display: "flex", justifyContent: "space-between", fontSize: "14px", fontWeight: '600' }}>
                  {" "}
                  <div> {GlobaldummyData ? formattedDate : Date1} </div>{" "}
                  <div> Bill No :{table2Data?.[0]?.QuotationNo && extractLastNumber(table2Data?.[0]?.QuotationNo)} </div>{" "}
                </div>

                <hr />
              </div>

              <div style={{ marginTop: GlobaldummyData ? "9rem" : "0rem" }} className="print-body">
                {(TakeawayData?.length > 0 || GlobaldummyData) &&
                  <>
                    <div style={{ display: "flex", justifyContent: "space-between", fontWeight: '600', fontSize: 'clamp(1rem, 2.5vw, 1.2rem)', width: '100%', gap: '0.5rem' }}>
                      {GlobaldummyData ? GlobalSlNo && <div style={{ width: '100%', textAlign: 'center' }}>S.No</div> : SLNO && <div style={{ width: '100%', textAlign: 'center' }}>S.No</div>}
                      {GlobaldummyData ? (GlobalItem || GlobalQuantity) &&
                        <div style={{ width: '300%', textAlign: 'center' }} > {GlobaldummyData ? GlobalItem && 'ITEM /DES /' : 'ITEM /DES /'} {GlobaldummyData ? GlobalQuantity && 'QTY' : 'QTY'} </div> :
                        <div style={{ width: '300%', textAlign: 'center' }} > {GlobaldummyData ? GlobalItem && 'ITEM /DES /' : Item && 'ITEM /DES /'} {GlobaldummyData ? GlobalQuantity && 'QTY' : Quantity && 'QTY'} </div>}
                      {GlobaldummyData ? GlobalHsnCode && <div style={{ width: '100%', textAlign: 'right' }}>HSN</div> : HsnCode && <div style={{ width: '100%', textAlign: 'right' }}>HSN</div>}
                      {MRP && <div style={{ width: '100%', textAlign: 'right' }}>MRP</div>}
                      {Rate && <div style={{ width: '100%', textAlign: 'right' }}>RATE</div>}
                      {Discount && <div style={{ width: '100%', textAlign: 'right' }}>DIS </div>}
                      {Amount && <div style={{ width: '100%', textAlign: 'right' }}> AMT </div>}
                    </div>

                    <hr className="hrline" />

                    {dataChunk?.map((item, index) => (
                      <div key={index} className="PrintStyle5-print-prddtls" style={{ display: "flex", justifyContent: "space-between", fontSize: 'clamp(1rem, 2.5vw, 1.2rem)', fontWeight: '600', width: '100%', gap: '0.5rem' }}>
                        {SLNO && <div style={{ width: '100%', textAlign: 'center' }}>{chunkIndex * chunkSize + index + 1}</div>}
                        {
                          GlobaldummyData ? (GlobalItem || GlobalQuantity) &&
                            <div style={{ textAlign: "left", width: '300%' }}>
                              {
                                (
                                  <>
                                    <div>{item?.ProdName}</div>
                                    <div>{item?.Size + item?.UomName + '-' +
                                      (item?.Qty)}</div>
                                  </>
                                )
                              }
                            </div> :
                            <div style={{ textAlign: "left", width: '300%' }}>
                              {
                                (
                                  <>
                                    <div>{item?.ProdName}</div>
                                    <div>
                                      {
                                        (item?.Size || "1") +
                                        (item?.SinglePc === "Y" ? "PCS" : item?.Type !== "C" ? item?.UomName : "COMBO") +
                                        (item?.BrandName || "") +
                                        (
                                          item?.ProductIdentifierDtls?.filter(
                                            (items) => items.SerialNumber && items.SerialNumber !== ""
                                          )?.map((a, index) => <div key={`serial-${index}`}>{a.SerialNumber}</div>) || ""
                                        ) +
                                        (
                                          item?.ProductIdentifierDtls?.filter(
                                            (item1) => item1.IMEI1 || item1.IMEI2
                                          )?.map((item2, index) => {
                                            const imei1 = item2.IMEI1 || "";
                                            const imei2 = item2.IMEI2 || "";
                                            return (
                                              <div key={`imei-${index}`}>
                                                {[imei1, imei2].filter(Boolean).join(",")}
                                              </div>
                                            );
                                          }) || "") +
                                        "-" + (GlobaldummyData ? (GlobalQuantity && item?.Qty) : item?.Qty)
                                      }
                                    </div>
                                  </>
                                )}
                            </div>
                        }
                        {HsnCode && <div style={{ width: '100%', textAlign: 'right' }}>{item?.HSN}</div>}
                        {MRP && <div style={{ width: '100%', textAlign: 'right' }}>{item?.SinglePc === 'Y' ? item?.Price : item?.MRP}</div>}
                        {Rate && <div style={{ width: '100%', textAlign: 'right' }}>{item?.Price}</div>}
                        {Discount && <div style={{ width: '100%', textAlign: 'right' }}>{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}</div>}
                        {Amount && <div style={{ width: "100%", textAlign: "right", }}>   {item?.NetAmt?.toFixed(2)}</div>}
                      </div>
                    ))}
                  </>
                }

              </div>

              {((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme &&

                <>

                  <div>
                    {((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
                      (OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
                      (OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
                      <>
                        <hr className="hrline" />

                        <div>
                          <div style={{ margin: 0, padding: 0, textAlign: "center" }}>
                            --------- GST Breakup Details -----------</div>
                          {(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
                            <table style={{ width: "90%" }}>

                              <tr>
                                <td style={{ textAlign: "center" }}>
                                  Taxable Amount
                                </td>
                                <td style={{ textAlign: "center" }}>
                                  CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                </td>
                                <td style={{ textAlign: "center" }}>
                                  SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                </td>
                                <td style={{ textAlign: "center" }}>

                                  Total Amount
                                </td>
                              </tr>
                              {OrderDetailGST?.map((item) =>
                                <tr>
                                  <td style={{ textAlign: "center" }}>
                                    {Number(item.WithoutTaxRate).toFixed(2)}
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    {Number(item.CGST).toFixed(2)}
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    {Number(item.SGST).toFixed(2)}
                                  </td>
                                  <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                </tr>
                              )
                              }
                            </table>
                          }

                          {(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
                            <>
                              <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                              <table style={{ width: "90%" }}>

                                <tr>
                                  <td style={{ textAlign: "center" }}>
                                    Taxable Amount
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
                                  </td>

                                  <td style={{ textAlign: "center" }}>

                                    Total Amount
                                  </td>
                                </tr>
                                {OrderDetailIGST?.map((item) =>
                                  <tr>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.WithoutTaxRate).toFixed(2)}
                                    </td>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.TaxAmt).toFixed(2)}
                                    </td>

                                    <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                  </tr>
                                )
                                }
                              </table>
                            </>
                          }
                          {(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
                            <>
                              <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                              <table style={{ width: "90%" }}>

                                <tr>
                                  <td style={{ textAlign: "center" }}>
                                    Taxable Amount
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
                                  </td>

                                  <td style={{ textAlign: "center" }}>

                                    Total Amount
                                  </td>
                                </tr>
                                {OrderDetailVAT?.map((item) =>
                                  <tr>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.WithoutTaxRate).toFixed(2)}
                                    </td>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.TaxAmt).toFixed(2)}
                                    </td>

                                    <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                  </tr>
                                )
                                }
                              </table>
                            </>
                          }

                        </div>
                        <hr className="hrline" />

                      </>
                    }
                  </div>

                  <div>
                    <div className="align-style">  <div >Items : </div>  <div>{GlobaldummyData ? '8' : totalQuantityFilter?.length}</div>  </div>
                    <div className="align-style">  <div>Qty : </div>  <div>{GlobaldummyData ? '9' : totalQuantity}</div>  </div>
                    {/* {ExtraChargeTotal>0 &&<div className="align-style">  <div>Extra Charges  : </div>  <div> {ExtraChargeTotal}</div> </div>} */}
                    {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) && <div className="align-style">  <div>Off : </div>  <div>{GlobaldummyData ? '100' : Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>  </div>}

                    <hr className="hrline" />

                    <div className="align-style" style={{ fontWeight: '600', fontSize: '19px' }}>  <div>Amount </div> <div> : </div>  <div>{GlobaldummyData ? '1,066' : Number(table2Data?.[0]?.NetAmount).toFixed(2)}</div>  </div>

                    <hr className="hrline" />
                    {/* 
          <div className="align-style" style={{ fontWeight: '400', }}>  <div>You Pay  : </div>  <div>1066.00</div>  </div>
          <div className="align-style">  <div>Recived Amt  : </div>   <div>1066.00</div>  </div>
          <div className="align-style">  <div>Balance Amt  : </div>  <div>0.00</div>  </div> */}

                  </div>

                  <br />

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

                      {/* <div style={{ display: 'flex', justifyContent: 'flex-start', }}>CARD : *********12</div>
            <div style={{ display: 'flex', justifyContent: 'flex-start', }}>CARD HOLDER : CARD HOLDER NAME</div> */}


                      <hr />
                      {/* <div style={{ display: 'flex', justifyContent: 'flex-start', fontWeight: '600', fontSize: '16px', }} >TOTAL SAVING : 10.00</div> */}
                    </div>


                  </div>
                  <div className='PrintStyle4-FourthP'>

                    {CashierName && CashierName !== undefined && CashierName !== null && !GlobaldummyData &&
                      <div className='PrintStyle4-FourthSmallwordings'>Cashier : {CashierName}
                      </div>
                    }

                    {table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
                      <div className='PrintStyle4-FourthSmallwordings'>Customer : {table2Data?.CustSuppName}
                      </div>
                    }



                  </div>


                  <div className="page-footerA4Style11"
                    style={{
                      marginTop: "auto",
                      pageBreakBefore: "avoid",
                      pageBreakInside: "avoid",
                      minHeight: "auto",
                    }}
                  >
                    {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" }}>{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>

                  {PrintGreeting?.SettingValue === "Y" &&
                    <div style={{ display: 'flex', justifyContent: 'center', fontWeight: '600', textTransform: 'uppercase', }}>Thank You Visit Again</div>
                  }

                </>
              }


            </div>
          ))}

          {shouldFooterBeOnNewPage && FormatTheme &&
            <div
              className="print-page"
              style={{
                display: "flex",
                flexDirection: "column",
                minHeight: PageSize == "A5" ? "200mm" : "297mm",
                justifyContent: "flex-end",
                pageBreakBefore: "always",
              }}
            >
              <div className="page-footerA4Style11"
                style={{
                  marginTop: "auto",
                  pageBreakBefore: "avoid",
                  pageBreakInside: "avoid",
                  minHeight: "auto",
                }}
              >
                <>
                  <div>
                    {((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
                      (OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
                      (OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
                      <>
                        <hr className="hrline" />

                        <div>
                          <div style={{ margin: 0, padding: 0, textAlign: "center" }}>
                            --------- GST Breakup Details -----------</div>
                          {(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
                            <table style={{ width: "90%" }}>

                              <tr>
                                <td style={{ textAlign: "center" }}>
                                  Taxable Amount
                                </td>
                                <td style={{ textAlign: "center" }}>
                                  CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                </td>
                                <td style={{ textAlign: "center" }}>
                                  SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                </td>
                                <td style={{ textAlign: "center" }}>

                                  Total Amount
                                </td>
                              </tr>
                              {OrderDetailGST?.map((item) =>
                                <tr>
                                  <td style={{ textAlign: "center" }}>
                                    {Number(item.WithoutTaxRate).toFixed(2)}
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    {Number(item.CGST).toFixed(2)}
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    {Number(item.SGST).toFixed(2)}
                                  </td>
                                  <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                </tr>
                              )
                              }
                            </table>
                          }

                          {(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
                            <>
                              <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                              <table style={{ width: "90%" }}>

                                <tr>
                                  <td style={{ textAlign: "center" }}>
                                    Taxable Amount
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
                                  </td>

                                  <td style={{ textAlign: "center" }}>

                                    Total Amount
                                  </td>
                                </tr>
                                {OrderDetailIGST?.map((item) =>
                                  <tr>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.WithoutTaxRate).toFixed(2)}
                                    </td>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.TaxAmt).toFixed(2)}
                                    </td>

                                    <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                  </tr>
                                )
                                }
                              </table>
                            </>
                          }
                          {(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
                            <>
                              <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                              <table style={{ width: "90%" }}>

                                <tr>
                                  <td style={{ textAlign: "center" }}>
                                    Taxable Amount
                                  </td>
                                  <td style={{ textAlign: "center" }}>
                                    VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
                                  </td>

                                  <td style={{ textAlign: "center" }}>

                                    Total Amount
                                  </td>
                                </tr>
                                {OrderDetailVAT?.map((item) =>
                                  <tr>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.WithoutTaxRate).toFixed(2)}
                                    </td>
                                    <td style={{ textAlign: "center" }}>
                                      {Number(item.TaxAmt).toFixed(2)}
                                    </td>

                                    <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                  </tr>
                                )
                                }
                              </table>
                            </>
                          }

                        </div>
                        <hr className="hrline" />

                      </>
                    }
                  </div>

                  <div>
                    <div className="align-style">  <div >Items : </div>  <div>{GlobaldummyData ? '8' : totalQuantityFilter?.length}</div>  </div>
                    <div className="align-style">  <div>Qty : </div>  <div>{GlobaldummyData ? '9' : totalQuantity}</div>  </div>
                    {/* {ExtraChargeTotal>0 &&<div className="align-style">  <div>Extra Charges  : </div>  <div> {ExtraChargeTotal}</div> </div>} */}
                    {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) && <div className="align-style">  <div>Off : </div>  <div>{GlobaldummyData ? '100' : Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>  </div>}

                    <hr className="hrline" />

                    <div className="align-style" style={{ fontWeight: '600', fontSize: '19px' }}>  <div>Amount </div> <div> : </div>  <div>{GlobaldummyData ? '1,066' : Number(table2Data?.NetAmount).toFixed(2)}</div>  </div>

                    <hr className="hrline" />

                  </div>

                  <br />

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




                      <hr />
                      {/* <div style={{ display: 'flex', justifyContent: 'flex-start', fontWeight: '600', fontSize: '16px', }} >TOTAL SAVING : 10.00</div> */}
                    </div>


                  </div>
                  <div className='PrintStyle4-FourthP'>


                    {CashierName && CashierName !== undefined && CashierName !== null && !GlobaldummyData &&
                      <div className='PrintStyle4-FourthSmallwordings'>Cashier : {CashierName}
                      </div>
                    }

                    {table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
                      <div className='PrintStyle4-FourthSmallwordings'>Customer : {table2Data?.CustSuppName}
                      </div>
                    }



                  </div>


                  <div className="page-footerA4Style11"
                    style={{
                      marginTop: "auto",
                      pageBreakBefore: "avoid",
                      pageBreakInside: "avoid",
                      minHeight: "auto",
                    }}
                  >
                    {
                      Notestext && (<div>
                        <p style={{ padding: "0rem 1rem" }}>{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" }}>
                      {
                        (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>

                  {PrintGreeting?.SettingValue === "Y" &&
                    <div style={{ display: 'flex', justifyContent: 'center', fontWeight: '600', textTransform: 'uppercase', }}>Thank You Visit Again</div>
                  }

                </>
              </div>
            </div>
          }
        </div >
        :
        <div className="PrintStyle5-MasterDiv" id={`SQPrintStyle5`} style={{ fontFamily: "'Courier New', Courier, monospace" }} >

          <div className="PrintStyle5-Head">
            <div>
              <div style={{ fontSize: 'clamp(2rem, 2.5vw, 2rem)', fontWeight: '600' }}>{table2Data?.[0]?.BrName}</div>

            </div>

            <div>{
              (table2Data?.[0]?.AddressDetails?.[0]?.Address1 || '') + (table2Data?.[0]?.AddressDetails?.[0]?.City ? (table2Data?.[0]?.AddressDetails?.[0]?.Address1 && table2Data?.[0]?.AddressDetails?.[0]?.City ? '-' : '') + table2Data?.[0]?.AddressDetails?.[0]?.City : '') + (table2Data?.[0]?.AddressDetails?.[0]?.Zip ? (table2Data?.[0]?.AddressDetails?.[0]?.City && table2Data?.[0]?.AddressDetails?.[0]?.Zip ? '-' : '') + table2Data?.[0]?.AddressDetails?.[0]?.Zip : '')}
            </div>
            <div style={{ fontSize: "14px", fontWeight: '600' }}> Mobile :{GlobaldummyData ? '1234567890' : table2Data?.[0]?.BrMobile} </div>
            {<div style={{ textTransform: 'uppercase' }}>{BillName}</div>}

            <hr />
          </div>



          <div className="PrintStyle5-print-table">


            <div style={{ display: "flex", justifyContent: "space-between", fontSize: "14px", fontWeight: '600' }}>
              {" "}
              <div> {GlobaldummyData ? formattedDate : Date1} </div>{" "}
              <div> Bill No :{table2Data?.[0]?.QuotationNo && extractLastNumber(table2Data?.[0]?.QuotationNo)} </div>{" "}
            </div>

            <hr />
            {(TakeawayData?.length > 0) &&
              <>
                <div style={{ display: "flex", justifyContent: "space-between", fontWeight: '600', fontSize: 'clamp(1rem, 2.5vw, 1.2rem)', width: '100%', gap: '0.5rem' }}>
                  {
                    SLNO && <div style={{ width: '100%', textAlign: 'center' }}>S.No</div>}
                  {
                    <div style={{ width: '300%', textAlign: 'center' }} >
                      {Item && 'ITEM'}
                      {Quantity && 'QTY'} </div>}
                  {HsnCode && <div style={{ width: '100%', textAlign: 'right' }}>HSN</div>}
                  {MRP && <div style={{ width: '100%', textAlign: 'right' }}>MRP</div>}
                  {Rate && <div style={{ width: '100%', textAlign: 'right' }}>RATE</div>}
                  {Discount && <div style={{ width: '100%', textAlign: 'right' }}>DIS </div>}
                  {Amount && <div style={{ width: '100%', textAlign: 'right' }}> AMT </div>}
                </div>

                <hr className="hrline" />

                {(TakeawayData)?.map((item, index) => (
                  <div key={index} className="PrintStyle5-print-prddtls" style={{ display: "flex", justifyContent: "space-between", fontSize: 'clamp(1rem, 2.5vw, 1.2rem)', fontWeight: '600', width: '100%', gap: '0.5rem' }}>
                    {SLNO && <div style={{ width: '100%', textAlign: 'center' }}>{index + 1}</div>}
                    {

                      <div style={{ textAlign: "left", width: '300%' }}>
                        {
                          (
                            <>
                              <div>{item?.ProdName}</div>
                              <div>
                                {
                                  (item?.Size || "1") +
                                  (item?.SinglePc === "Y" ? "PCS" : item?.Type !== "C" ? item?.UomName : "COMBO") +
                                  (item?.BrandName || "") +
                                  (
                                    item?.ProductIdentifierDtls?.filter(
                                      (items) => items.SerialNumber && items.SerialNumber !== ""
                                    )?.map((a, index) => <div key={`serial-${index}`}>{a.SerialNumber}</div>) || ""
                                  ) +
                                  (
                                    item?.ProductIdentifierDtls?.filter(
                                      (item1) => item1.IMEI1 || item1.IMEI2
                                    )?.map((item2, index) => {
                                      const imei1 = item2.IMEI1 || "";
                                      const imei2 = item2.IMEI2 || "";
                                      return (
                                        <div key={`imei-${index}`}>
                                          {[imei1, imei2].filter(Boolean).join(",")}
                                        </div>
                                      );
                                    }) || "") +
                                  "-" + (item?.Qty)
                                }
                              </div>
                            </>
                          )}
                      </div>
                    }
                    {HsnCode && <div style={{ width: '100%', textAlign: 'right' }}>{item?.HSN}</div>}
                    {MRP && <div style={{ width: '100%', textAlign: 'right' }}>{item?.SinglePc === 'Y' ? item?.Price : item?.MRP}</div>}
                    {Rate && <div style={{ width: '100%', textAlign: 'right' }}>{item?.Price}</div>}
                    {Discount && <div style={{ width: '100%', textAlign: 'right' }}>{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}</div>}
                    {Amount && <div style={{ width: "100%", textAlign: "right", }}>   {item?.NetAmt?.toFixed(2)}</div>}
                  </div>
                ))}
              </>
            }

            <div>
              {((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
                (OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
                (OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
                <>
                  <hr className="hrline" />

                  <div>
                    <div style={{ margin: 0, padding: 0, textAlign: "center" }}>
                      --------- GST Breakup Details -----------</div>
                    {(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
                      <table style={{ width: "90%" }}>

                        <tr>
                          <td style={{ textAlign: "center" }}>
                            Taxable Amount
                          </td>
                          <td style={{ textAlign: "center" }}>
                            CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                          </td>
                          <td style={{ textAlign: "center" }}>
                            SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                          </td>
                          <td style={{ textAlign: "center" }}>

                            Total Amount
                          </td>
                        </tr>
                        {OrderDetailGST?.map((item) =>
                          <tr>
                            <td style={{ textAlign: "center" }}>
                              {Number(item.WithoutTaxRate).toFixed(2)}
                            </td>
                            <td style={{ textAlign: "center" }}>
                              {Number(item.CGST).toFixed(2)}
                            </td>
                            <td style={{ textAlign: "center" }}>
                              {Number(item.SGST).toFixed(2)}
                            </td>
                            <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                          </tr>
                        )
                        }
                      </table>
                    }

                    {(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
                      <>
                        <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                        <table style={{ width: "90%" }}>

                          <tr>
                            <td style={{ textAlign: "center" }}>
                              Taxable Amount
                            </td>
                            <td style={{ textAlign: "center" }}>
                              IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
                            </td>

                            <td style={{ textAlign: "center" }}>

                              Total Amount
                            </td>
                          </tr>
                          {OrderDetailIGST?.map((item) =>
                            <tr>
                              <td style={{ textAlign: "center" }}>
                                {Number(item.WithoutTaxRate).toFixed(2)}
                              </td>
                              <td style={{ textAlign: "center" }}>
                                {Number(item.TaxAmt).toFixed(2)}
                              </td>

                              <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                            </tr>
                          )
                          }
                        </table>
                      </>
                    }
                    {(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
                      <>
                        <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                        <table style={{ width: "90%" }}>

                          <tr>
                            <td style={{ textAlign: "center" }}>
                              Taxable Amount
                            </td>
                            <td style={{ textAlign: "center" }}>
                              VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
                            </td>

                            <td style={{ textAlign: "center" }}>

                              Total Amount
                            </td>
                          </tr>
                          {OrderDetailVAT?.map((item) =>
                            <tr>
                              <td style={{ textAlign: "center" }}>
                                {Number(item.WithoutTaxRate).toFixed(2)}
                              </td>
                              <td style={{ textAlign: "center" }}>
                                {Number(item.TaxAmt).toFixed(2)}
                              </td>

                              <td style={{ textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                            </tr>
                          )
                          }
                        </table>
                      </>
                    }

                  </div>
                  <hr className="hrline" />

                </>
              }
            </div>



            <div>
              <div className="align-style">  <div >Items : </div>  <div>{GlobaldummyData ? '8' : totalQuantityFilter?.length}</div>  </div>
              <div className="align-style">  <div>Qty : </div>  <div>{GlobaldummyData ? '9' : totalQuantity}</div>  </div>
              {/* {ExtraChargeTotal>0 &&<div className="align-style">  <div>Extra Charges  : </div>  <div> {ExtraChargeTotal}</div> </div>} */}
              {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) && <div className="align-style">  <div>Off : </div>  <div>{GlobaldummyData ? '100' : Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>  </div>}

              <hr className="hrline" />

              <div className="align-style" style={{ fontWeight: '600', fontSize: '19px' }}>  <div>Amount </div> <div> : </div>  <div>{GlobaldummyData ? '1,066' : Number(table2Data?.[0]?.NetAmount).toFixed(2)}</div>  </div>

              <hr className="hrline" />
              {/* 
              <div className="align-style" style={{ fontWeight: '400', }}>  <div>You Pay  : </div>  <div>1066.00</div>  </div>
              <div className="align-style">  <div>Recived Amt  : </div>   <div>1066.00</div>  </div>
              <div className="align-style">  <div>Balance Amt  : </div>  <div>0.00</div>  </div> */}

            </div>


            <br />
            {/* <hr className="hrline" /> */}

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

                {/* <div style={{ display: 'flex', justifyContent: 'flex-start', }}>CARD : *********12</div>
                <div style={{ display: 'flex', justifyContent: 'flex-start', }}>CARD HOLDER : CARD HOLDER NAME</div> */}


                <hr />
                {/* <div style={{ display: 'flex', justifyContent: 'flex-start', fontWeight: '600', fontSize: '16px', }} >TOTAL SAVING : 10.00</div> */}
              </div>


            </div>
            <div className='PrintStyle4-FourthP'>


              {CashierName && CashierName !== undefined && CashierName !== null && !GlobaldummyData &&
                <div className='PrintStyle4-FourthSmallwordings'>Cashier : {CashierName}
                </div>
              }

              {table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
                <div className='PrintStyle4-FourthSmallwordings'>Customer : {table2Data?.CustSuppName}
                </div>
              }



            </div>

            <div style={{ letterSpacing: '5px', fontSize: '14px', }}>********************************************************************************************************************************</div>

            <div>




              <div className="page-footerA4Style11"
                style={{
                  marginTop: "auto",
                  pageBreakBefore: "avoid",
                  pageBreakInside: "avoid",
                  minHeight: "auto",
                }}
              >
                {
                  Notestext && (<div>
                    <p style={{ padding: "0rem 1rem" }}>{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" }}>
                  {
                    (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>))}

                      </ol>
                    </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 PurPrintStyle5;
