const URLScanSuccessImage = "./assets/svg/scan-success.svg"
const URLEnterGateImage = "./assets/svg/enter-gate.svg"
const DOMFullScreenMask = document.getElementById("full-screen-mask")
const DOMScanResultContainer = document.getElementById("scan-result-container")
const DOMQRCodeScanSuccessImage = document.getElementById("qrcode-scan-success")

var isShowing = false

function showResult(imageType) {
    console.log("showResult")
    if (isShowing) {
        // console.log("showResult() skipped coz showing.")
        // 等待 0.1s 重试
        setTimeout(() => showResult(imageType), 100)
        return
    }
    isShowing = true
    DOMQRCodeScanSuccessImage.src = imageType === "onscan" ? URLScanSuccessImage : URLEnterGateImage
    DOMFullScreenMask.classList.remove("hidden")
    DOMScanResultContainer.classList.remove("hidden")
    //
    setTimeout(() => {
        DOMQRCodeScanSuccessImage.classList.add("scan-result-image-show")
    }, 100)

    setTimeout(function hideResult() {
        console.log("hideResult")
        DOMQRCodeScanSuccessImage.classList.remove("scan-result-image-show")
        setTimeout(() => {
            DOMQRCodeScanSuccessImage.src = ""
            DOMFullScreenMask.classList.add("hidden")
            DOMScanResultContainer.classList.add("hidden")
            isShowing = false
        }, 300)
    }, 3000)
}

// setTimeout(showResult, 100)
window.showResult = showResult
