<?php
$pageName  = "COT Verification";
include($_SERVER['DOCUMENT_ROOT'] . "/user/layout/header.php");

require_once($_SERVER['DOCUMENT_ROOT'] . "/include/Transfer/WireFunction.php");

if (!isset($_SESSION['is_wire_code'])) {
    header("Location:./wire-transfer.php");
    exit();
}

if (!isset($_SESSION['is_transfer'])) {
    header("Location:./dashboard.php");
}

if (isset($_POST['cot_submit'])) {
    $cotCode = $_POST['cot_code'];
    $acct_cot = $row['acct_cot'];

    if ($cotCode === $acct_cot) {
        if($page['tax_code']=='0') {

            $_SESSION['wire-transfer'] = $user_id;
        $_SESSION['is_tax_code'] = "Cot";
        $_SESSION['is_transfer']  = "transfer";

        header("Location:./imf.php");


        } else {

        $_SESSION['wire-transfer'] = $user_id;
        $_SESSION['is_cot_code'] = "Cot";
        $_SESSION['is_transfer']  = "transfer";


        header("Location:./tax.php");
        }
    } else {
        toast_alert('error', 'Invalid COT Code');
    }
    
}

?>
<!-- Main Content -->
<main class="pt-10 md:pt-14 pb-24 md:pb-8 min-h-screen lg:ml-80">
<div class="min-h-screen flex items-center justify-center p-4 relative z-10">

<style>
    @keyframes progress {
        from { width: 100%; }
        to   { width: 0%; }
    }
    @keyframes shake {
        0%, 100% { transform: rotate(0deg); }
        25%       { transform: rotate(-5deg); }
        75%       { transform: rotate(5deg); }
    }
    .animate-shake { animation: shake 0.5s ease-in-out; }
    .hover-lift {
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    .hover-lift:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    }
</style>

<div class="w-full max-w-md mx-auto"
     x-cloak
     x-data="{
         otp: ''
     }">

    <!-- COT Verification Card -->
    <div class="bg-white border border-[#E0E5E5] rounded-xl p-8 md:p-10 space-y-8">

        <!-- Header -->
        <div class="text-center space-y-4">
            <div class="relative inline-block">
                <div class="w-16 h-16 rounded-xl bg-[#DFE5E5] flex items-center justify-center mx-auto">
                    <i data-lucide="shield-check" class="w-8 h-8 text-[#49786B]"></i>
                </div>
            </div>
            <div>
                <h2 class="text-xl font-semibold text-[#0D1B23]">COT Verification</h2>
                <p class="text-sm text-[#7A7A7A] mt-1">
                    Enter your COT code to proceed with this transfer
                </p>
            </div>
        </div>

        <!-- Contact Support Alert -->
        <div x-data="{ show: true }"
             x-show="show"
             x-transition:enter="transition ease-out duration-300"
             x-transition:enter-start="opacity-0 translate-y-2"
             x-transition:enter-end="opacity-100 translate-y-0"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100"
             x-transition:leave-end="opacity-0">
            <div class="border border-[#49786B]/30 rounded-xl overflow-hidden hover-lift">
                <div class="flex items-start p-4 gap-4">
                    <div class="flex-shrink-0">
                        <div class="w-10 h-10 rounded-xl bg-gradient-to-br from-[#49786B] to-[#3a6055] flex items-center justify-center shadow-lg relative">
                            <div class="absolute inset-0 bg-[#49786B]/20 rounded-xl animate-pulse"></div>
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-white relative z-10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                                <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
                            </svg>
                        </div>
                    </div>
                    <div class="flex-1 min-w-0">
                        <h4 class="text-sm font-bold text-[#0D1B23] mb-1">Need Your COT Code?</h4>
                        <p class="text-sm text-[#4A4A4A] leading-relaxed">Please contact customer support to receive your COT verification code.</p>
                    </div>
                    <button @click="show = false" class="flex-shrink-0 p-1.5 rounded-lg hover:bg-[#49786B]/10 transition-colors">
                        <i data-lucide="x" class="w-4 h-4 text-[#7A7A7A]"></i>
                    </button>
                </div>
                <div class="h-1 bg-[#49786B]/10">
                    <div class="h-full bg-gradient-to-r from-[#49786B] to-[#6a9e8f]"
                         style="animation: progress 5s linear forwards;"
                         @animationend="show = false"></div>
                </div>
            </div>
        </div>

        <!-- COT Form -->
        <form method="POST" class="space-y-6">

            <input type="hidden" name="cot_submit" value="1">

            <!-- COT Input -->
            <div class="space-y-2">
                <label class="block text-sm font-semibold text-[#4A4A4A] text-center">
                    Enter COT Code
                </label>
                <input
                    type="text"
                    name="cot_code"
                    x-model="otp"
                    @input="otp = otp.replace(/\D/g, '').slice(0, 6)"
                    maxlength="6"
                    inputmode="numeric"
                    pattern="[0-9]*"
                    placeholder="000000"
                    autocomplete="off"
                    autofocus
                    required
                    class="field-input w-full text-center text-2xl font-bold tracking-[0.4em] rounded-xl py-4 px-4 border border-[#E0E5E5] outline-none focus:border-[#49786B] focus:ring-2 focus:ring-[#49786B]/10">
            </div>

            <!-- Info Banner -->
            <div class="bg-[#49786B]/5 border border-[#49786B]/20 rounded-xl p-4">
                <div class="flex items-start space-x-3">
                    <i data-lucide="info" class="w-5 h-5 text-[#49786B] flex-shrink-0 mt-0.5"></i>
                    <p class="text-xs text-[#4A4A4A]">
                        If you don't have a COT code, please contact support to request one. Never share this code with anyone.
                    </p>
                </div>
            </div>

            <!-- Submit Button -->
            <button
                type="submit"
                :disabled="otp.length < 4"
                class="w-full py-4 rounded-xl font-semibold text-white text-sm flex items-center justify-center space-x-2 bg-primary-500 hover:bg-primary-600 transition-colors disabled:opacity-50 disabled:cursor-not-allowed group">
                <i data-lucide="check-circle" class="w-5 h-5"></i>
                <span>Verify & Continue</span>
                <i data-lucide="arrow-right" class="w-5 h-5 group-hover:translate-x-1 transition-transform"></i>
            </button>

            <p class="text-xs text-center text-[#7A7A7A]">
                <i data-lucide="lock" class="w-3 h-3 inline mr-1"></i>
                Your security is protected with end-to-end encryption
            </p>
        </form>

        <!-- Footer -->
        <div class="pt-6 border-t border-[#E0E5E5]">
            <div class="flex items-center justify-between text-xs text-[#7A7A7A]">
                <a href="./dashboard.php" class="text-[#49786B] inline-flex items-center space-x-1 group hover:underline">
                    <i data-lucide="arrow-left" class="w-4 h-4 group-hover:-translate-x-1 transition-transform"></i>
                    <span>Back to Dashboard</span>
                </a>
                <span>Secure Connection</span>
            </div>
        </div>

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

<script>
document.addEventListener('DOMContentLoaded', function () {
    lucide.createIcons();
});
</script>

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/user/layout/footer.php");
?>