<?php defined( 'ABSPATH' ) || exit;

?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="<?php echo get_template_directory_uri(); ?>/owl/pdf.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/owl/jspdf.js"></script>
</head>
<body style="padding: 30px 0px;">
<style>


#loading-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(255, 255, 255, 0.8);
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 9999;
}
        .spinner {
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-left-color: #000;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
		.print-button-box button:focus {
	opacity: 0.5;
}
		</style>
<div class="print-button-box">
<button onclick="printContent()">چاپ</button>
	 <button id="save-button">دانلود تصویر</button>
    <button id="download-pdf">دانلود PDF</button>

</div>

<div class="size" style="width: 1000px;">

  <div id="print-content3" class="factor-box-header">

  
  
  <style>

@font-face {
    font-family: iranyekan;
    font-style: normal;
    font-weight: 600;
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebboldfanum.eot');
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebboldfanum.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/woff/iranyekanwebboldfanum.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+ */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/ttf/iranyekanwebboldfanum.ttf') format('truetype');
}

@font-face {
    font-family: iranyekan;
    font-style: normal;
    font-weight: 300;
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanweblightfanum.eot');
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanweblightfanum.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/woff/iranyekanweblightfanum.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+ */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/ttf/iranyekanweblightfanum.ttf') format('truetype');
}

@font-face {
    font-family: iranyekan;
    font-style: normal;
    font-weight: normal;
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebregularfanum.eot');
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebregularfanum.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/woff/iranyekanwebregularfanum.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+ */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/ttf/iranyekanwebregularfanum.ttf') format('truetype');
}

.factor-create-php-one td {
	font-size: 13px;
}
.factor-create-php-one {
	float: right;
	width: 100%;
	padding: 0px;
	background: #fff;
	border-radius: 0px;
	border: 1px solid #d7d7d7;
	box-sizing: border-box;
	border-radius: 10px;
	overflow: hidden;
	margin-bottom: 5px;
	font-family: iranyekan;
}

.factor-box-header-inner {
	float: left;
	width: 20%;
	text-align: center;
	text-align: left;
	border-radius: 10px;
	box-sizing: border-box;
}

.factor-box-header-inner-two {
	float: right;
	width: 50%;
	padding-right: 20px;
	box-sizing: border-box;
}
.factor-box-header-inner-three {
	float: right;
	width: 30%;
}
.print-button-box {
	float: right;
	width: 100%;
	text-align: center;
	margin-bottom: 30px;
}
.factor-box-header-inner-two tr td {
	float: right;
	width: 100%;
	padding: 5px 0px;
}
.print-button-box button {
	background: #2DCEA2;
	border: 0px solid;
	color: #fff;
	padding: 10px 15px;
	border-radius: 10px;
	font-family: iranyekan;
	font-size: 16px;
	cursor: pointer;
	margin: 0px 5px;
}
.factor-box-header-inner-three tr td {
	float: right;
	width: 100%;
	padding: 5px 0px;
}
.factor-create-php-title {
	float: right;
	width: 100%;
	background-color: #eee;
	padding: 15px;
	border-top: 1px solid #d7d7d7;
	box-sizing: border-box;
	border-bottom: 0px solid #d7d7d7;
}
.factor-box-header {
	float: right;
	width: 100%;
	box-sizing: border-box;
	padding: 20px 20px;
}
.factor-create-php {
	margin: 30px 0px;
}

.factor-create-php-title-inner table tr td {
	padding: 10px;
}

  * {
    -webkit-print-color-adjust:exact;
    print-color-adjust:exact;
    -webkit-box-decoration-break:clone;
    box-decoration-break:clone
  }

.product-list-factor {
	float: right;
	width: 100%;
	padding: 15px;
	box-sizing: border-box;
}
.product-list-factor table {
	float: right;
	width: 100%;
	text-align: center;
}
.product-list-factor table th, .product-list-factor table td {
	border: 1px solid #d7d7d7;
	padding: 10px;
}
.product-list-factor table th {
	background: #eee;
	font-weight: 400;
}
.product-list-factor.factor-total-123 {
	float: right;
	width: 50%;
	box-sizing: border-box;
}
.factor-create-php-title:nth-child(4) {
	border-bottom: 1px solid #d7d7d7;
}
.meta-yaddasht-1we211 {
	float: right;
	max-width: 150px;
}
.product-list-factor.factor-total-122 {
	float: left;
	width: 50%;
}
.meta-yaddasht-1we211 img {
	float: right;
	width: 100%;
}
.product-list-factor.factor-total-122 table tr td:first-child {
	background: #eee;
	font-weight: 400;
}
.meta-yaddasht-1we {
	float: right;
	width: 100%;
	text-align: right;
	margin-bottom: ;
	margin-top: 10px;
}
.meta-yaddasht-1we:last-child strong {
	float: right;
	width: 100%;
}
.meta-yaddasht-1we strong {
	float: right;
}

.factor-create-php-title-inner {
	position: relative;
}
.factor-create-php-title-inner-title {
	float: right;
	position: absolute;
	background: #666;
	padding: 4px 15px;
	color: #fff;
	border-radius: 90px;
	top: 0;
	margin-top: -29px;
}
.factor-logo-website {
	float: right;
	width: 100%;
	padding: 20px;
	box-sizing: border-box;
	border-bottom: 1px solid #d7d7d7;
	text-align: center;
}

.factor-logo-website img {
	max-width: 150px;
}

.meta-yaddasht-1we211 img {
	width: 60px;
	padding: 10px;
}

.meta-yaddasht-1we strong {
	margin-left: 5px;
}

.print-button-box button , .factor-create-php-title-inner-title {
	
	background: <?php echo esc_html( get_option('color1') ); ?> !important;
}

@media only screen and (max-width : 1050px) {
#print-content3 {
	width: 970px;
	padding: 5px;
}
.size {
	width: 95% !important;
	overflow: auto;
}
.factor-create-php-one {
	width: 960px;
	float: unset;
	margin: auto;
}
.factor-box-header {
	overflow: auto;
}
	}



</style>
  <?php include( locate_template( 'ffile/factor/factor-code.php' ) );  ?>



    </div></div></div>

    <div id="loading-overlay" class="loading-grid-12">
        <div class="spinner"></div>
    </div>

<script>
function printContent() {
    const printContents = document.getElementById("print-content3").innerHTML;
    
    // باز کردن یک پنجره جدید برای چاپ
    const printWindow = window.open('', '', 'width=800,height=600');
    printWindow.document.write(`
        <html>
            <head>
                <title>چاپ فاکتور</title>
                 <style>

@font-face {
    font-family: iranyekan;
    font-style: normal;
    font-weight: 600;
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebboldfanum.eot');
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebboldfanum.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/woff/iranyekanwebboldfanum.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+ */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/ttf/iranyekanwebboldfanum.ttf') format('truetype');
}

@font-face {
    font-family: iranyekan;
    font-style: normal;
    font-weight: 300;
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanweblightfanum.eot');
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanweblightfanum.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/woff/iranyekanweblightfanum.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+ */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/ttf/iranyekanweblightfanum.ttf') format('truetype');
}

@font-face {
    font-family: iranyekan;
    font-style: normal;
    font-weight: normal;
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebregularfanum.eot');
    src: url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/eot/iranyekanwebregularfanum.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/woff/iranyekanwebregularfanum.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+ */
         url('<?php echo get_template_directory_uri(); ?>/fonts/yekan/ttf/iranyekanwebregularfanum.ttf') format('truetype');
}

.factor-create-php-one td {
	font-size: 13px;
}
.factor-create-php-one {
	float: right;
	width: 100%;
	padding: 0px;
	background: #fff;
	border-radius: 0px;
	border: 1px solid #d7d7d7;
	box-sizing: border-box;
	border-radius: 10px;
	overflow: hidden;
	margin-bottom: 5px;
	font-family: iranyekan;
}
.factor-box-header-inner {
	float: left;
	width: 20%;
	text-align: center;
	text-align: left;
	border-radius: 10px;
	box-sizing: border-box;
}

.factor-box-header-inner-two {
	float: right;
	width: 50%;
	padding-right: 20px;
	box-sizing: border-box;
}
.factor-box-header-inner-three {
	float: right;
	width: 30%;
}
.print-button-box {
	float: right;
	width: 100%;
	text-align: center;
	margin-bottom: 30px;
}
.factor-box-header-inner-two tr td {
	float: right;
	width: 100%;
	padding: 5px 0px;
}
.print-button-box button {
	background: #2DCEA2;
	border: 0px solid;
	color: #fff;
	padding: 10px 15px;
	border-radius: 10px;
	font-family: iranyekan;
	font-size: 16px;
	cursor: pointer;
	margin: 0px 5px;
}
.factor-box-header-inner-three tr td {
	float: right;
	width: 100%;
	padding: 5px 0px;
}
.factor-create-php-title {
	float: right;
	width: 100%;
	background-color: #EAF0FF;
	padding: 15px;
	border-top: 1px solid #C1CDEC;
	box-sizing: border-box;
	border-bottom: 1px solid #C1CDEC;
}
.factor-box-header {
	float: right;
	width: 100%;
	box-sizing: border-box;
	padding: 20px 20px;
}
.factor-create-php {
	margin: 30px 0px;
}

.factor-create-php-title-inner table tr td {
	padding: 10px;
}

  * {
    -webkit-print-color-adjust:exact;
    print-color-adjust:exact;
    -webkit-box-decoration-break:clone;
    box-decoration-break:clone
  }

.product-list-factor {
	float: right;
	width: 100%;
	padding: 15px;
	box-sizing: border-box;
}
.product-list-factor table {
	float: right;
	width: 100%;
	text-align: center;
}
.product-list-factor table th, .product-list-factor table td {
	border: 1px solid #d7d7d7;
	padding: 10px;
}
.product-list-factor table th {
	background: #eee;
	font-weight: 400;
}
.product-list-factor.factor-total-123 {
	float: right;
	width: 50%;
	box-sizing: border-box;
}
.factor-create-php-title:nth-child(4) {
	border-bottom: 1px solid #d7d7d7;
}
.meta-yaddasht-1we211 {
	float: right;
	max-width: 150px;
}
.product-list-factor.factor-total-122 {
	float: left;
	width: 50%;
}
.meta-yaddasht-1we211 img {
	float: right;
	width: 100%;
}
.product-list-factor.factor-total-122 table tr td:first-child {
	background: #EAF0FF;
	font-weight: 400;
}
.meta-yaddasht-1we {
	float: right;
	width: 100%;
	text-align: right;
	margin-bottom: ;
	margin-top: 10px;
}
.meta-yaddasht-1we:last-child strong {
	float: right;
	width: 100%;
}
.meta-yaddasht-1we strong {
	float: right;
}

.factor-create-php-title-inner {
	position: relative;
}
.factor-create-php-title-inner-title {
	float: right;
	position: absolute;
	background: #666;
	padding: 4px 15px;
	color: #fff;
	border-radius: 90px;
	top: 0;
	margin-top: -29px;
}
.factor-logo-website {
	float: right;
	width: 100%;
	padding: 20px;
	box-sizing: border-box;
	border-bottom: 1px solid #d7d7d7;
	text-align: center;
}
.factor-logo-website img {
	max-width: 150px;
}

.meta-yaddasht-1we211 img {
	width: 60px;
	padding: 10px;
}

.meta-yaddasht-1we strong {
	margin-left: 5px;
}

.print-button-box button , .factor-create-php-title-inner-title {
	
	background: <?php echo esc_html( get_option('color1') ); ?> !important;
}
.factor-create-php-one {
	direction: rtl;
}
@media only screen and (max-width : 1050px) {
#print-content3 {
	width: 970px;
	padding: 5px;
}
.size {
	width: 95% !important;
}
.factor-create-php-one {
	width: 960px;
	float: unset;
	margin: auto;
}
.factor-box-header {
	overflow: auto;
}
	}



</style>
            </head>
            <body>
                ${printContents}
            </body>
        </html>
    `);
    printWindow.document.close(); // بستن جریان ورودی به پنجره
    printWindow.print(); // دستور چاپ
    printWindow.onafterprint = function() {
        printWindow.close(); // بستن پنجره بعد از چاپ
    };
}
</script>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('save-button').addEventListener('click', saveAsJPG);

            async function saveAsJPG() {
                const element = document.getElementById('print-content3');
                const orderNumber = document.getElementById('order-number').innerText;

                if (!element || !orderNumber) {
                    console.error('عنصر مورد نظر یافت نشد.');
                    return;
                }

                document.getElementById('loading-overlay').style.display = 'grid';

                try {
                    const canvas = await html2canvas(element, { useCORS: true });
                    const imgData = canvas.toDataURL('image/jpeg', 1.0);

                    const link = document.createElement('a');
                    link.href = imgData;
                    link.download = `factor-${orderNumber}.jpg`;

                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                } catch (error) {
                    console.error('Error creating JPG:', error);
                } finally {
                    document.getElementById('loading-overlay').style.display = 'none';
                }
            }
        });
    </script>

    <script>
        document.getElementById('download-pdf').addEventListener('click', function() {
            var element = document.getElementById('print-content3');
                const orderNumber = document.getElementById('order-number').innerText;

            html2canvas(element, {
                useCORS: true, 
                allowTaint: true
            }).then(function(canvas) {
                var imgData = canvas.toDataURL('image/png');
                var pdf = new jspdf.jsPDF('p', 'mm', 'a4');
                var imgWidth = 210;
                var imgHeight = canvas.height * imgWidth / canvas.width;
                pdf.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);
				                    pdf.save(`factor-${orderNumber}.pdf`);

            }).catch(function(error) {
                console.error('Error capturing content:', error);
            });
        });
    </script>

</body>
</html>






