<!DOCTYPE html>
<html lang="vi">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DAT Group - Kích Hoạt Kỷ Nguyên Mới</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @font-face {
            font-family: 'Goldman';
            src: url('/font/Goldman-Bold.ttf') format('truetype');
            font-weight: bold;
        }

        @font-face {
            font-family: 'SFPro';
            src: url('/font/SFProDisplay-Medium.otf') format('opentype');
            font-weight: 500;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', sans-serif;
        }

        /* body {
            background-color: #001a52;
            height: 100vh;
            overflow: hidden;
            display: flex;
            justify-content: center;
        }

        .app-container {
            width: 100%;
            max-width: 480px;
            height: 100%;
            position: relative;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
            overflow: hidden;
        } */

        body {
            background-color: #032266;
            min-height: 100vh;
            overflow-y: auto;
            display: flex;
            justify-content: center;
        }
      
        .app-container {
            width: 100%;
            max-width: 480px;
            min-height: 100vh;
            position: relative;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
        }

        .bg-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            object-position: bottom center;
            z-index: 1;
            opacity: 0;
            transition: opacity 0.8s ease-in-out;
            pointer-events: none;
        }


        .bg-layer.active {
            opacity: 1;
        }

        .scene {
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            opacity: 0;
            pointer-events: none;

            transform: translateY(30px);
            transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);

            padding-top: 40px;
            z-index: 10;
        }

        .scene.active {
            opacity: 1;
            transform: translateY(0);
            pointer-events: auto;
            transition-delay: 0.2s;
        }

        .content-wrapper {
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 0 20px;
            margin-top: 20px;
        }

        .img-text {
            max-width: 95%;
            height: auto;
            object-fit: contain;
        }

        .img-btn {
            max-width: 75%;
            height: auto;
            cursor: pointer;
            margin-top: 20px;
            animation: pulse-zoom 1.5s infinite ease-in-out;
        }

        .img-btn:active {
            animation: none;
            transform: scale(0.95);
        }


        @keyframes pulse-zoom {
            0% {
                transform: scale(1);
                filter: drop-shadow(0px 0px 0px rgba(255, 219, 88, 0));
            }

            50% {
                transform: scale(1.06);
                filter: drop-shadow(0px 0px 15px rgba(255, 219, 88, 0.6));
            }

            100% {
                transform: scale(1);
                filter: drop-shadow(0px 0px 0px rgba(255, 219, 88, 0));
            }
        }

        .mt-40 {
            margin-top: 40px;
        }

        .mt-30 {
            margin-top: 30px;
        }

        .mt-20 {
            margin-top: 20px;
        }

        .mb-40 {
            margin-bottom: 40px;
        }

        .mb-30 {
            margin-bottom: 30px;
        }

        .mb-10 {
            margin-bottom: 10px;
        }

        .input-wrapper {
            position: relative;
            width: 90%;
            max-width: 380px;
            margin-bottom: 20px;
            transition: transform 0.2s;
        }

        .input-bg-img {
            width: 100%;
            display: block;
            user-select: none;
            pointer-events: none;
        }

        .input-text-area {
            position: absolute;
            top: 0;
            left: 26%;
            width: 70%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            padding-top: 2%;
        }

        .input-text-area label {
            font-family: 'Goldman', sans-serif;
            color: #002aac;
            font-size: 1.1rem;
            /* font-weight: 900; */
            margin-bottom: 2px;
            letter-spacing: 0.5px;
        }

        .input-text-area input {
            font-family: 'SFPro', sans-serif;
            width: 100%;
            background: transparent;
            border: none;
            outline: none;
            color: #002aac;
            font-size: 1.2rem;
            /* font-weight: bold; */
            /* text-transform: uppercase; */
        }

        .input-text-area input::placeholder {
            font-family: 'SFPro', sans-serif;
            color: #002aac;
            /* font-weight: normal; */
            font-size: 1rem;
            text-transform: none;
        }

        @keyframes shake {

            0%,
            100% {
                transform: translateX(0);
            }

            25% {
                transform: translateX(-8px);
            }

            50% {
                transform: translateX(8px);
            }

            75% {
                transform: translateX(-8px);
            }
        }

        .error-shake {
            animation: shake 0.4s ease-in-out;
        }


        .flare-wrapper {
            position: relative;
            display: inline-block;
            overflow: hidden;
            max-width: 95%;
            border-radius: 10px;
        }

        .flare-wrapper::after {
            content: "";
            position: absolute;
            top: 0;
            left: -150%;
            width: 20%;
            height: 100%;
            background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0) 100%);
            transform: skewX(-25deg);
            animation: sweep-flare 3s infinite;
            pointer-events: none;
            z-index: 5;
        }

        @keyframes sweep-flare {
            0% {
                left: -150%;
            }

            60% {
                left: 200%;
            }

            100% {
                left: 200%;
            }

        }


        .float-3d {
            animation: levitate 3s ease-in-out infinite;
        }

        @keyframes levitate {

            0%,
            100% {
                transform: translateY(0);
            }

            50% {
                transform: translateY(-5px);
            }

        }
    </style>
</head>

<body>

    <div class="app-container">

        <!-- ================= BACKGROUND ================= -->
        <img src="/img/datgroup/bg-full-1.jpg" id="bg-scene1" class="bg-layer active" alt="Nền Scene 1">
        <img src="/img/datgroup/bg-full-2.jpg" id="bg-scene2" class="bg-layer" alt="Nền Scene 2">
        <img src="/img/datgroup/bg-full-3.jpg" id="bg-scene3" class="bg-layer" alt="Nền Scene 3">

        <!-- ================= SCENE 1 ================= -->
        <div id="scene1" class="scene active">
            <div class="content-wrapper">

                <div class="input-wrapper" id="wrapCompany">
                    <img src="/img/datgroup/bg-input-company.png" class="input-bg-img" alt="Khung nền">
                    <div class="input-text-area">
                        <label>Công ty</label>
                        <input type="text" id="companyName" placeholder="Nhập tên công ty...">
                    </div>
                </div>

                <div class="input-wrapper" id="wrapUser">
                    <img src="/img/datgroup/bg-input-user.png" class="input-bg-img" alt="Khung nền">
                    <div class="input-text-area">
                        <label>Họ và tên</label>
                        <input type="text" id="fullName" placeholder="Nhập họ và tên...">
                    </div>
                </div>

                <img src="/img/datgroup/s1-text-center.png" class="img-text mt-30">
                <img src="/img/datgroup/s1-btn.png" class="img-btn mt-20" onclick="nextScene('scene2')">
            </div>
        </div>

        <!-- ================= SCENE 2 ================= -->
        <div id="scene2" class="scene">
            <div class="content-wrapper mt-20">
                <img src="/img/datgroup/s2-text-top.png" class="img-text">
                <img src="/img/datgroup/s2-btn.png" class="img-btn mt-40" onclick="goToScene3AndCreate()">
            </div>
        </div>

        <!-- ================= SCENE 3 ================= -->
        <!-- <div id="scene3" class="scene">
            <div class="content-wrapper mt-30">
                <img src="/img/datgroup/s3-logo-top.png" style="max-width: 50%;">
                <img src="/img/datgroup/s3-title.png" class="img-text mt-30 mb-40" style="max-width: 85%;">
                <img src="/img/datgroup/s3-text-center.png" class="img-text" style="max-width: 105%;">
            </div>
        </div> -->

        <!-- ================= SCENE 3 ================= -->
        <div id="scene3" class="scene">
            <div class="content-wrapper mt-20">
                <!-- Hiệu ứng Float (Trôi nổi) cho Logo 20 năm -->
                <img src="/img/datgroup/s3-logo-top.png" alt="Logo 20 năm" class="float-3d" style="max-width: 50%;">
                <img src="/img/datgroup/s3-title.png" alt="Chào mừng bạn đến với" class="img-text mt-30 mb-40"
                    style="max-width: 85%;">
                <!-- BỌC TEXT CENTER ĐỂ TẠO TIA SÁNG + CHO NÓ TRÔI NỔI -->
                <div class="flare-wrapper float-3d" style="max-width: 105%;">
                    <img src="/img/datgroup/s3-text-center.png" alt="Kỷ nguyên mới cùng DAT" class="img-text"
                        style="max-width: 100%;">
                </div>

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

    <script>
        function nextScene(targetSceneId) {

            if (targetSceneId === 'scene2') {
                const companyInput = document.getElementById('companyName');
                const nameInput = document.getElementById('fullName');
                const wrapCompany = document.getElementById('wrapCompany');
                const wrapUser = document.getElementById('wrapUser');

                let isValid = true;

                if (companyInput.value.trim() === '') {
                    wrapCompany.classList.remove('error-shake');
                    void wrapCompany.offsetWidth;
                    wrapCompany.classList.add('error-shake');
                    isValid = false;
                }

                if (nameInput.value.trim() === '') {
                    wrapUser.classList.remove('error-shake');
                    void wrapUser.offsetWidth;
                    wrapUser.classList.add('error-shake');
                    isValid = false;
                }

                if (!isValid) {
                    return;
                }
            }
            // 1. Chuyển Nội Dung (Scene)
            const scenes = document.querySelectorAll('.scene');
            scenes.forEach(scene => scene.classList.remove('active'));

            const targetScene = document.getElementById(targetSceneId);
            if (targetScene) targetScene.classList.add('active');


            // 2. Chuyển Background Layer tương ứng
            const backgrounds = document.querySelectorAll('.bg-layer');
            backgrounds.forEach(bg => bg.classList.remove('active'));

            const targetBgId = 'bg-' + targetSceneId;
            const targetBg = document.getElementById(targetBgId);
            if (targetBg) targetBg.classList.add('active');
        }
    </script>
    <script>
        async function goToScene3AndCreate() {
            const company = document.getElementById('companyName').value.trim();
            const fullName = document.getElementById('fullName').value.trim();
            try {
                const response = await fetch('/record/create', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        agency: company,
                        name: fullName
                    })
                });

                if (!response.ok) {
                    throw new Error('Failed to create record');
                }
                const result = await response.json();
                console.log('Created:', result);
                nextScene('scene3');
            } catch (error) {
                console.error(error);
                alert('Có lỗi xảy ra, vui lòng thử lại!');
            }
        }
    </script>
</body>

</html>