<!DOCTYPE html>
<html>
<head>
<title> Home </title>
<meta charset="UTF-8">
<meta name="keywords" content="HTML, CSS, JavaScript">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%- include('./parcials/cssLinks') %>
<link href="<%= baseUrl %>css/dashboard.css" rel="stylesheet" type="text/css">
</head>
<body>
<%- include('./parcials/header') %>
<main class="certificate-page">
<% if(certificate){ %>
<h2 class="theme-h2">Your Certificate</h2>
<section class="certificate-wrapper">
<div class="certificate-item">
<input type="hidden" id="certificate-base64">
<button class="print-certificate" onclick="printCertificate()" title="Print Certificate"><i class="fa-solid fa-print"></i></button>
<a href="/api/certificate/download-certificate/<%= certificate._id %>" download="Certificate" id="download-received-certificate" class="download-certificate" title="Download Certificate"><i class="fa-solid fa-file-arrow-down"></i></a>
<h1 class="certificate-h1">CERTIFICATE OF VIRTUAL BALLZ</h1>
<h6 class="certificate-h6">PRESENTED TO</h6>
<h2 class="certificate-title">
<%= certificate.name %>
</h2>
<h6 class="certificate-h6 desc-p">
<% if(certificate.anonymousName){ %>
<%= certificate.anonymousName %>
<% } else { %>
<%= certificate.senderName %>
<% } %>
has determined that you have earned a pair of <%= certificate.ballz_type %> in recognition
of your ability to <%= certificate.reason %>
</h6>
<h6 class="certificate-h6">Awarded this <span class="date">
<%= certificate.createdAt.getDate() %>
</span> day of <span class="date month">
<%= months[certificate.createdAt.getMonth()] %>
</span>, 20<span class="date year">
<%= certificate.createdAt.getFullYear().toString().slice(-2) %>
</span></h6>
<img src="<%= baseUrl %>images/certificate-footer.png" alt="" class="img-featured">
<img class="certificate-sign" src="<%= baseUrl %>images/certificate-signature.png" alt="">
</div>
</section>
<% } else{ %>
<section class="certificate-wrapper">
<h2 class="theme-h2">Certificate Not Found...</h2>
</section>
<% } %>
</main>
<%- include('./parcials/footer') %>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<%- include('./parcials/scriptLinks') %>
<script>
$(".print-certificate").hide()
$("#download-received-certificate").hide()
html2canvas($(".certificate-page .certificate-wrapper .certificate-item")[0]).then(function(canvas) {
$("#download-received-certificate").attr("href", canvas.toDataURL('image/png'))
$("#certificate-base64").val(canvas.toDataURL('image/png'))
$("#download-received-certificate").show()
$(".print-certificate").show()
});
</script>
</body>
<script>
function printCertificate() {
var printWindow = window.open('', '', `width=1056 ,height=816,left=${screen.width / 4},top=100`);
printWindow.document.write('<html><head><title>Print Certificate</title></head><body>');
printWindow.document.write('<style>body{display:flex;align-items:center;justify-content:center;} img{transform: scale(1.2)} @media print {@page {size: landscape;margin:0;@top-left {content: "";}@top-right {content: "";}@bottom-left {content: "";}@bottom-right {content: "";}}}</style><img src="' + $("#certificate-base64").val() + '"' + 'width="' + $(".certificate-item").width() + '" height="' + $(".certificate-item").height() + '">');
printWindow.document.write('</body></html>');
setTimeout(() => {
printWindow.print();
printWindow.close();
}, 1000);
}
</script>
</html>