<?php

include_once 'auth.php';

?>

<link rel="stylesheet"
      href="https://unpkg.com/html5-qrcode/minified/html5-qrcode.min.css">

<script src="https://unpkg.com/html5-qrcode"></script>

<div class="page-header">

    <h1 class="page-title">
        QR Scanner
    </h1>

</div>

<div class="admin-card"
     style="max-width:700px;margin:auto;">

    <div id="reader"></div>

    <div id="scan-result"
         style="margin-top:30px;"></div>

</div>

<script>

function onScanSuccess(decodedText){

    fetch(

        'process_scan.php?code=' +

        encodeURIComponent(decodedText)

    )

    .then(response => response.text())

    .then(data => {

        document.getElementById(

            'scan-result'

        ).innerHTML = data;

    });

}

const html5QrcodeScanner =
    new Html5QrcodeScanner(

        "reader",

        {
            fps:10,
            qrbox:250
        },

        false
    );

html5QrcodeScanner.render(onScanSuccess);

</script>