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

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

    <!-- Main Content Area -->
    <main class="pt-10 md:pt-14 pb-24 md:pb-8 min-h-screen lg:ml-80">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">

<style>
    .field-input {
        background: #FFFFFF;
        border: 1px solid #E0E5E5;
        color: #0D1B23;
        outline: none;
        transition: border-color 0.2s ease;
    }
    .field-input:focus, .field-input:focus-within {
        border-color: #49786B;
        box-shadow: 0 0 0 2px rgba(73, 120, 107, 0.12);
    }
    .field-input::placeholder { color: #7A7A7A; }

    @keyframes spin-slow {
        to { transform: rotate(360deg); }
    }
    .spin-slow { animation: spin-slow 1.2s linear infinite; }

    @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="pb-20 md:pb-8" x-data="{
    amount: '',
    account_name: '',
    account_number: '',
    bank_name: '',
    account_type: 'Online Banking',
    bank_country: '',
    routing_number: '',
    swift_code: '',
    pin: '',
    description: '',
    showPreview: false,
    showOptional: false,
    isProcessing: false,
    processingProgress: 0,
    processingStage: 'Initiating transfer...',
    balance: <?php echo $acct_balance; ?>,
    currency: '<?= $currency ?>',

    setQuickAmount(value) {
        this.amount = value === 'all' ? this.balance.toFixed(2) : value;
    },

    get remainingBalance() {
        return this.balance - (parseFloat(this.amount) || 0);
    },

    get isValidAmount() {
        const amt = parseFloat(this.amount);
        return amt > 0 && amt <= this.balance;
    },

    openPreview() {
        if (!this.isValidAmount) {
            swal('Invalid Amount', 'Please enter a valid transfer amount', 'error');
            return;
        }
        if (!this.account_name || !this.account_number || !this.bank_name || !this.bank_country || !this.pin) {
            swal('Missing Information', 'Please fill all required fields including Country', 'warning');
            return;
        }
        this.showPreview = true;
        setTimeout(() => lucide.createIcons(), 100);
    },

    submitTransfer() {
        this.showPreview = false;
        this.isProcessing = true;
        this.processingProgress = 0;
        const stages = [
            { progress: 20, text: 'Initiating transfer...' },
            { progress: 40, text: 'Verifying account details...' },
            { progress: 60, text: 'Processing transaction...' },
            { progress: 80, text: 'Confirming with bank...' },
            { progress: 100, text: 'Finalizing transfer...' }
        ];
        let currentStage = 0;
        const interval = setInterval(() => {
            if (currentStage < stages.length) {
                this.processingProgress = stages[currentStage].progress;
                this.processingStage = stages[currentStage].text;
                currentStage++;
                lucide.createIcons();
            } else {
                clearInterval(interval);
                setTimeout(() => { this.$refs.transferForm.submit(); }, 500);
            }
        }, 1000);
    }
}" x-init="setTimeout(() => lucide.createIcons(), 100)">

    <!-- Page Header -->
    <div class="mb-6">
        <div class="flex items-center space-x-3">
            <a href="dashboard.php" class="w-9 h-9 rounded-lg bg-white border border-[#E0E5E5] flex items-center justify-center hover:bg-[#DFE5E5] transition-colors">
                <i data-lucide="arrow-left" class="w-4 h-4 text-[#7A7A7A]"></i>
            </a>
            <div>
                <h1 class="text-xl md:text-2xl font-semibold text-[#0D1B23]">Local Transfer</h1>
                <p class="text-sm text-[#7A7A7A]">Send money to any local bank account</p>
            </div>
        </div>
    </div>

    <!-- Balance Card -->
    <div class="bg-white border border-[#E0E5E5] rounded-xl p-5 mb-6">
        <div class="flex items-center justify-between">
            <div>
                <p class="text-xs uppercase tracking-wider text-[#7A7A7A] mb-1 font-medium">Available Balance</p>
                <h2 class="text-2xl md:text-3xl font-bold text-[#0D1B23]">
                    <?= $currency ?><?php echo number_format($acct_balance, 2, '.', ','); ?>
                </h2>
                <p class="text-xs text-[#7A7A7A] mt-1">Account: </p>
            </div>
            <div class="w-12 h-12 rounded-xl bg-primary-50 border border-primary-200 flex items-center justify-center">
                <i data-lucide="wallet" class="w-5 h-5 text-primary-500"></i>
            </div>
        </div>
    </div>

    <!-- Transfer Form -->
    <form method="POST" x-ref="transferForm" @submit.prevent="openPreview()">
        <input type="hidden" name="_token" value="<?= $_SESSION['_token'] ?? '' ?>">
        <input type="hidden" name="balance_type" value="fiat">
        <input type="hidden" name="fee" value="<?= $page['domesticfee'] ?>">
        <input type="hidden" name="domestic-transfer" value="1">

        <div class="bg-[#F9F9F9] border border-[#E0E5E5] rounded-xl p-5 md:p-6 space-y-6">

            <!-- Amount Section -->
            <div>
                <label class="block text-sm text-[#7A7A7A] mb-1.5">Transfer Amount <span class="text-[#D55672]">*</span></label>

                <div class="field-input flex items-center rounded-lg mb-3">
                    <span class="pl-4 pr-2 text-[#7A7A7A] font-medium text-lg"><?= $currency ?></span>
                    <input
                        type="number"
                        name="amount"
                        x-model="amount"
                        step="0.01"
                        min="1"
                        max="<?php echo $acct_balance; ?>"
                        required
                        placeholder="0.00"
                        class="flex-1 bg-transparent border-none outline-none text-[#0D1B23] text-xl font-semibold py-3.5 px-2 placeholder-[#7A7A7A]">
                </div>

                <div class="grid grid-cols-4 gap-2 mb-2">
                    <button type="button" @click="setQuickAmount(100)" class="px-3 py-2 rounded-lg text-xs font-medium bg-[#DFE5E5] border border-[#C8D1D1] text-[#4A4A4A] hover:bg-[#DFE5E5] hover:text-[#0D1B23] transition-colors">
                        <?= $currency ?>100
                    </button>
                    <button type="button" @click="setQuickAmount(500)" class="px-3 py-2 rounded-lg text-xs font-medium bg-[#DFE5E5] border border-[#C8D1D1] text-[#4A4A4A] hover:bg-[#DFE5E5] hover:text-[#0D1B23] transition-colors">
                        <?= $currency ?>500
                    </button>
                    <button type="button" @click="setQuickAmount(1000)" class="px-3 py-2 rounded-lg text-xs font-medium bg-[#DFE5E5] border border-[#C8D1D1] text-[#4A4A4A] hover:bg-[#DFE5E5] hover:text-[#0D1B23] transition-colors">
                        <?= $currency ?>1,000
                    </button>
                    <button type="button" @click="setQuickAmount('all')" class="px-3 py-2 rounded-lg text-xs font-medium bg-[#DFE5E5] border border-[#C8D1D1] text-[#4A4A4A] hover:bg-[#DFE5E5] hover:text-[#0D1B23] transition-colors">
                        All
                    </button>
                </div>

                <p class="text-xs text-[#7A7A7A] px-1">
                    Limits: <?= $currency ?>1.00 – <?= $currency ?><?php echo number_format($acct_balance, 2, '.', ','); ?>
                </p>
            </div>

            <hr class="border-[#E0E5E5]">

            <!-- Beneficiary Information -->
            <div>
                <h3 class="text-sm font-semibold text-[#4A4A4A] uppercase tracking-wider mb-4">Beneficiary Information</h3>

                <div class="space-y-4">

                    <!-- Account Holder Name -->
                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Account Holder Name <span class="text-[#D55672]">*</span></label>
                        <input
                            type="text"
                            name="account_name"
                            x-model="account_name"
                            required
                            placeholder="Full name as registered"
                            class="field-input w-full px-4 py-3 rounded-lg text-sm">
                    </div>

                    <!-- Account Number -->
                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Account Number <span class="text-[#D55672]">*</span></label>
                        <input
                            type="text"
                            inputmode="numeric"
                            pattern="[0-9]+"
                            minlength="10"
                            maxlength="12"
                            name="account_number"
                            x-model="account_number"
                            required
                            placeholder="Beneficiary account number"
                            class="field-input w-full px-4 py-3 rounded-lg text-sm">
                    </div>

                    <!-- Bank Name -->
                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Bank Name <span class="text-[#D55672]">*</span></label>
                        <input
                            type="text"
                            name="bank_name"
                            x-model="bank_name"
                            required
                            placeholder="Recipient's bank name"
                            class="field-input w-full px-4 py-3 rounded-lg text-sm">
                    </div>

                    <!-- Account Type -->
                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Account Type <span class="text-[#D55672]">*</span></label>
                        <select
                            name="account_type"
                            x-model="account_type"
                            required
                            class="field-input w-full px-4 py-3 rounded-lg text-sm cursor-pointer">
                            <option value="Online Banking" style="background:#FFFFFF;color:#0D1B23;">Online Banking</option>
                            <option value="Checking" style="background:#FFFFFF;color:#0D1B23;">Checking Account</option>
                            <option value="Savings Account" style="background:#FFFFFF;color:#0D1B23;">Savings Account</option>
                            <option value="Current Account" style="background:#FFFFFF;color:#0D1B23;">Current Account</option>
                            <option value="Joint Account" style="background:#FFFFFF;color:#0D1B23;">Joint Account</option>
                            <option value="Business Account" style="background:#FFFFFF;color:#0D1B23;">Business Account</option>
                            <option value="Corporate Account" style="background:#FFFFFF;color:#0D1B23;">Corporate Account</option>
                            <option value="Money Market Account" style="background:#FFFFFF;color:#0D1B23;">Money Market Account</option>
                            <option value="Investment Account" style="background:#FFFFFF;color:#0D1B23;">Investment Account</option>
                            <option value="Fixed Deposit Account" style="background:#FFFFFF;color:#0D1B23;">Fixed Deposit Account</option>
                            <option value="Trust Account" style="background:#FFFFFF;color:#0D1B23;">Trust Account</option>
                            <option value="Student Account" style="background:#FFFFFF;color:#0D1B23;">Student Account</option>
                            <option value="Senior Citizen Account" style="background:#FFFFFF;color:#0D1B23;">Senior Citizen Account</option>
                            <option value="Salary Account" style="background:#FFFFFF;color:#0D1B23;">Salary Account</option>
                            <option value="Domiciliary Account" style="background:#FFFFFF;color:#0D1B23;">Domiciliary Account</option>
                            <option value="NRI Account" style="background:#FFFFFF;color:#0D1B23;">NRI Account (Non-Resident)</option>
                        </select>
                    </div>

                    <!-- Country -->
                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Country <span class="text-[#D55672]">*</span></label>
                        <select
                            name="bank_country"
                            x-model="bank_country"
                            required
                            class="field-input w-full px-4 py-3 rounded-lg text-sm cursor-pointer">
                            <option value="">Select Country</option>
                            <option value="Afghanistan">Afghanistan</option>
                            <option value="Albania">Albania</option>
                            <option value="Algeria">Algeria</option>
                            <option value="American Samoa">American Samoa</option>
                            <option value="Andorra">Andorra</option>
                            <option value="Angola">Angola</option>
                            <option value="Anguilla">Anguilla</option>
                            <option value="Antigua & Barbuda">Antigua & Barbuda</option>
                            <option value="Argentina">Argentina</option>
                            <option value="Armenia">Armenia</option>
                            <option value="Aruba">Aruba</option>
                            <option value="Australia">Australia</option>
                            <option value="Austria">Austria</option>
                            <option value="Azerbaijan">Azerbaijan</option>
                            <option value="Bahamas">Bahamas</option>
                            <option value="Bahrain">Bahrain</option>
                            <option value="Bangladesh">Bangladesh</option>
                            <option value="Barbados">Barbados</option>
                            <option value="Belarus">Belarus</option>
                            <option value="Belgium">Belgium</option>
                            <option value="Belize">Belize</option>
                            <option value="Benin">Benin</option>
                            <option value="Bermuda">Bermuda</option>
                            <option value="Bhutan">Bhutan</option>
                            <option value="Bolivia">Bolivia</option>
                            <option value="Bonaire">Bonaire</option>
                            <option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option>
                            <option value="Botswana">Botswana</option>
                            <option value="Brazil">Brazil</option>
                            <option value="British Indian Ocean Ter">British Indian Ocean Ter</option>
                            <option value="Brunei">Brunei</option>
                            <option value="Bulgaria">Bulgaria</option>
                            <option value="Burkina Faso">Burkina Faso</option>
                            <option value="Burundi">Burundi</option>
                            <option value="Cambodia">Cambodia</option>
                            <option value="Cameroon">Cameroon</option>
                            <option value="Canada">Canada</option>
                            <option value="Canary Islands">Canary Islands</option>
                            <option value="Cape Verde">Cape Verde</option>
                            <option value="Cayman Islands">Cayman Islands</option>
                            <option value="Central African Republic">Central African Republic</option>
                            <option value="Chad">Chad</option>
                            <option value="Channel Islands">Channel Islands</option>
                            <option value="Chile">Chile</option>
                            <option value="China">China</option>
                            <option value="Christmas Island">Christmas Island</option>
                            <option value="Cocos Island">Cocos Island</option>
                            <option value="Colombia">Colombia</option>
                            <option value="Comoros">Comoros</option>
                            <option value="Congo">Congo</option>
                            <option value="Cook Islands">Cook Islands</option>
                            <option value="Costa Rica">Costa Rica</option>
                            <option value="Cote DIvoire">Cote D'Ivoire</option>
                            <option value="Croatia">Croatia</option>
                            <option value="Cuba">Cuba</option>
                            <option value="Curacao">Curacao</option>
                            <option value="Cyprus">Cyprus</option>
                            <option value="Czech Republic">Czech Republic</option>
                            <option value="Denmark">Denmark</option>
                            <option value="Djibouti">Djibouti</option>
                            <option value="Dominica">Dominica</option>
                            <option value="Dominican Republic">Dominican Republic</option>
                            <option value="East Timor">East Timor</option>
                            <option value="Ecuador">Ecuador</option>
                            <option value="Egypt">Egypt</option>
                            <option value="El Salvador">El Salvador</option>
                            <option value="Equatorial Guinea">Equatorial Guinea</option>
                            <option value="Eritrea">Eritrea</option>
                            <option value="Estonia">Estonia</option>
                            <option value="Ethiopia">Ethiopia</option>
                            <option value="Falkland Islands">Falkland Islands</option>
                            <option value="Faroe Islands">Faroe Islands</option>
                            <option value="Fiji">Fiji</option>
                            <option value="Finland">Finland</option>
                            <option value="France">France</option>
                            <option value="French Guiana">French Guiana</option>
                            <option value="French Polynesia">French Polynesia</option>
                            <option value="French Southern Ter">French Southern Ter</option>
                            <option value="Gabon">Gabon</option>
                            <option value="Gambia">Gambia</option>
                            <option value="Georgia">Georgia</option>
                            <option value="Germany">Germany</option>
                            <option value="Ghana">Ghana</option>
                            <option value="Gibraltar">Gibraltar</option>
                            <option value="Great Britain">Great Britain</option>
                            <option value="Greece">Greece</option>
                            <option value="Greenland">Greenland</option>
                            <option value="Grenada">Grenada</option>
                            <option value="Guadeloupe">Guadeloupe</option>
                            <option value="Guam">Guam</option>
                            <option value="Guatemala">Guatemala</option>
                            <option value="Guinea">Guinea</option>
                            <option value="Guyana">Guyana</option>
                            <option value="Haiti">Haiti</option>
                            <option value="Hawaii">Hawaii</option>
                            <option value="Honduras">Honduras</option>
                            <option value="Hong Kong">Hong Kong</option>
                            <option value="Hungary">Hungary</option>
                            <option value="Iceland">Iceland</option>
                            <option value="Indonesia">Indonesia</option>
                            <option value="India">India</option>
                            <option value="Iran">Iran</option>
                            <option value="Iraq">Iraq</option>
                            <option value="Ireland">Ireland</option>
                            <option value="Isle of Man">Isle of Man</option>
                            <option value="Israel">Israel</option>
                            <option value="Italy">Italy</option>
                            <option value="Jamaica">Jamaica</option>
                            <option value="Japan">Japan</option>
                            <option value="Jordan">Jordan</option>
                            <option value="Kazakhstan">Kazakhstan</option>
                            <option value="Kenya">Kenya</option>
                            <option value="Kiribati">Kiribati</option>
                            <option value="Korea North">Korea North</option>
                            <option value="Korea South">Korea South</option>
                            <option value="Kuwait">Kuwait</option>
                            <option value="Kyrgyzstan">Kyrgyzstan</option>
                            <option value="Laos">Laos</option>
                            <option value="Latvia">Latvia</option>
                            <option value="Lebanon">Lebanon</option>
                            <option value="Lesotho">Lesotho</option>
                            <option value="Liberia">Liberia</option>
                            <option value="Libya">Libya</option>
                            <option value="Liechtenstein">Liechtenstein</option>
                            <option value="Lithuania">Lithuania</option>
                            <option value="Luxembourg">Luxembourg</option>
                            <option value="Macau">Macau</option>
                            <option value="Macedonia">Macedonia</option>
                            <option value="Madagascar">Madagascar</option>
                            <option value="Malaysia">Malaysia</option>
                            <option value="Malawi">Malawi</option>
                            <option value="Maldives">Maldives</option>
                            <option value="Mali">Mali</option>
                            <option value="Malta">Malta</option>
                            <option value="Marshall Islands">Marshall Islands</option>
                            <option value="Martinique">Martinique</option>
                            <option value="Mauritania">Mauritania</option>
                            <option value="Mauritius">Mauritius</option>
                            <option value="Mayotte">Mayotte</option>
                            <option value="Mexico">Mexico</option>
                            <option value="Midway Islands">Midway Islands</option>
                            <option value="Moldova">Moldova</option>
                            <option value="Monaco">Monaco</option>
                            <option value="Mongolia">Mongolia</option>
                            <option value="Montserrat">Montserrat</option>
                            <option value="Morocco">Morocco</option>
                            <option value="Mozambique">Mozambique</option>
                            <option value="Myanmar">Myanmar</option>
                            <option value="Namibia">Namibia</option>
                            <option value="Nauru">Nauru</option>
                            <option value="Nepal">Nepal</option>
                            <option value="Netherland Antilles">Netherland Antilles</option>
                            <option value="Netherlands">Netherlands (Holland, Europe)</option>
                            <option value="Nevis">Nevis</option>
                            <option value="New Caledonia">New Caledonia</option>
                            <option value="New Zealand">New Zealand</option>
                            <option value="Nicaragua">Nicaragua</option>
                            <option value="Niger">Niger</option>
                            <option value="Nigeria">Nigeria</option>
                            <option value="Niue">Niue</option>
                            <option value="Norfolk Island">Norfolk Island</option>
                            <option value="Norway">Norway</option>
                            <option value="Oman">Oman</option>
                            <option value="Pakistan">Pakistan</option>
                            <option value="Palau Island">Palau Island</option>
                            <option value="Palestine">Palestine</option>
                            <option value="Panama">Panama</option>
                            <option value="Papua New Guinea">Papua New Guinea</option>
                            <option value="Paraguay">Paraguay</option>
                            <option value="Peru">Peru</option>
                            <option value="Philippines">Philippines</option>
                            <option value="Pitcairn Island">Pitcairn Island</option>
                            <option value="Poland">Poland</option>
                            <option value="Portugal">Portugal</option>
                            <option value="Puerto Rico">Puerto Rico</option>
                            <option value="Qatar">Qatar</option>
                            <option value="Republic of Montenegro">Republic of Montenegro</option>
                            <option value="Republic of Serbia">Republic of Serbia</option>
                            <option value="Reunion">Reunion</option>
                            <option value="Romania">Romania</option>
                            <option value="Russia">Russia</option>
                            <option value="Rwanda">Rwanda</option>
                            <option value="St Barthelemy">St Barthelemy</option>
                            <option value="St Eustatius">St Eustatius</option>
                            <option value="St Helena">St Helena</option>
                            <option value="St Kitts-Nevis">St Kitts-Nevis</option>
                            <option value="St Lucia">St Lucia</option>
                            <option value="St Maarten">St Maarten</option>
                            <option value="St Pierre & Miquelon">St Pierre & Miquelon</option>
                            <option value="St Vincent & Grenadines">St Vincent & Grenadines</option>
                            <option value="Saipan">Saipan</option>
                            <option value="Samoa">Samoa</option>
                            <option value="Samoa American">Samoa American</option>
                            <option value="San Marino">San Marino</option>
                            <option value="Sao Tome & Principe">Sao Tome & Principe</option>
                            <option value="Saudi Arabia">Saudi Arabia</option>
                            <option value="Senegal">Senegal</option>
                            <option value="Seychelles">Seychelles</option>
                            <option value="Sierra Leone">Sierra Leone</option>
                            <option value="Singapore">Singapore</option>
                            <option value="Slovakia">Slovakia</option>
                            <option value="Slovenia">Slovenia</option>
                            <option value="Solomon Islands">Solomon Islands</option>
                            <option value="Somalia">Somalia</option>
                            <option value="South Africa">South Africa</option>
                            <option value="Spain">Spain</option>
                            <option value="Sri Lanka">Sri Lanka</option>
                            <option value="Sudan">Sudan</option>
                            <option value="Suriname">Suriname</option>
                            <option value="Swaziland">Swaziland</option>
                            <option value="Sweden">Sweden</option>
                            <option value="Switzerland">Switzerland</option>
                            <option value="Syria">Syria</option>
                            <option value="Tahiti">Tahiti</option>
                            <option value="Taiwan">Taiwan</option>
                            <option value="Tajikistan">Tajikistan</option>
                            <option value="Tanzania">Tanzania</option>
                            <option value="Thailand">Thailand</option>
                            <option value="Togo">Togo</option>
                            <option value="Tokelau">Tokelau</option>
                            <option value="Tonga">Tonga</option>
                            <option value="Trinidad & Tobago">Trinidad & Tobago</option>
                            <option value="Tunisia">Tunisia</option>
                            <option value="Turkey">Turkey</option>
                            <option value="Turkmenistan">Turkmenistan</option>
                            <option value="Turks & Caicos Is">Turks & Caicos Is</option>
                            <option value="Tuvalu">Tuvalu</option>
                            <option value="Uganda">Uganda</option>
                            <option value="United Kingdom">United Kingdom</option>
                            <option value="Ukraine">Ukraine</option>
                            <option value="United Arab Emirates">United Arab Emirates</option>
                            <option value="United States of America">United States of America</option>
                            <option value="Uruguay">Uruguay</option>
                            <option value="Uzbekistan">Uzbekistan</option>
                            <option value="Vanuatu">Vanuatu</option>
                            <option value="Vatican City State">Vatican City State</option>
                            <option value="Venezuela">Venezuela</option>
                            <option value="Vietnam">Vietnam</option>
                            <option value="Virgin Islands (Brit)">Virgin Islands (Brit)</option>
                            <option value="Virgin Islands (USA)">Virgin Islands (USA)</option>
                            <option value="Wake Island">Wake Island</option>
                            <option value="Wallis & Futana Is">Wallis & Futana Is</option>
                            <option value="Yemen">Yemen</option>
                            <option value="Zaire">Zaire</option>
                            <option value="Zambia">Zambia</option>
                            <option value="Zimbabwe">Zimbabwe</option>
                        </select>
                    </div>

                    <!-- Optional Fields Toggle -->
                    <button
                        type="button"
                        @click="showOptional = !showOptional"
                        class="text-sm text-primary-400 hover:text-primary-300 font-medium flex items-center space-x-2 transition-colors">
                        <span x-text="showOptional ? 'Hide' : 'Show'">Show</span>
                        <span>optional fields (Routing & SWIFT)</span>
                        <i data-lucide="chevron-down" class="w-4 h-4 transition-transform duration-200" :class="{ 'rotate-180': showOptional }"></i>
                    </button>

                    <!-- Optional Fields -->
                    <div x-show="showOptional" x-collapse class="space-y-4 pt-2">
                        <div>
                            <label class="block text-sm text-[#7A7A7A] mb-1.5">Routing Number <span class="text-[#7A7A7A]">(Optional)</span></label>
                            <input
                                type="text"
                                name="routing_number"
                                x-model="routing_number"
                                maxlength="9"
                                placeholder="9-digit routing number"
                                class="field-input w-full px-4 py-3 rounded-lg text-sm">
                        </div>

                        <div>
                            <label class="block text-sm text-[#7A7A7A] mb-1.5">SWIFT Code <span class="text-[#7A7A7A]">(Optional)</span></label>
                            <input
                                type="text"
                                name="swift_code"
                                x-model="swift_code"
                                maxlength="11"
                                placeholder="8-11 character identifier"
                                class="field-input w-full px-4 py-3 rounded-lg text-sm">
                        </div>
                    </div>

                </div>
            </div>

            <hr class="border-[#E0E5E5]">

            <!-- Security & Details -->
            <div>
                <h3 class="text-sm font-semibold text-[#4A4A4A] uppercase tracking-wider mb-4">Security & Details</h3>

                <div class="space-y-4">
                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Transaction PIN <span class="text-[#D55672]">*</span></label>
                        <input
                            type="password"
                            name="pin"
                            x-model="pin"
                            pattern="[0-9]+"
                            minlength="4"
                            maxlength="10"
                            required
                            placeholder="Enter your PIN"
                            class="field-input w-full px-4 py-3 rounded-lg text-sm">
                    </div>

                    <div>
                        <label class="block text-sm text-[#7A7A7A] mb-1.5">Description / Note <span class="text-[#7A7A7A]">(Optional)</span></label>
                        <textarea
                            name="description"
                            x-model="description"
                            rows="3"
                            placeholder="Purpose of transfer..."
                            class="field-input w-full px-4 py-3 rounded-lg text-sm resize-none"></textarea>
                    </div>
                </div>
            </div>

            <!-- Action Buttons -->
            <div class="flex flex-col sm:flex-row gap-3 pt-2">
                <a href="/dashboard.php" class="flex-1 px-5 py-3.5 text-center rounded-lg border border-[#C8D1D1] hover:bg-[#DFE5E5] transition-colors text-sm font-medium text-[#7A7A7A]">
                    Cancel
                </a>
                <button
                    type="submit"
                    class="flex-1 px-5 py-3.5 rounded-lg font-medium text-white text-sm bg-primary-500 hover:bg-primary-600 transition-colors flex items-center justify-center space-x-2">
                    <span>Review Transfer</span>
                    <i data-lucide="arrow-right" class="w-4 h-4"></i>
                </button>
            </div>

        </div>
    </form>

    <!-- Preview Modal -->
    <div
        x-show="showPreview"
        x-transition:enter="transition ease-out duration-200"
        x-transition:enter-start="opacity-0"
        x-transition:enter-end="opacity-100"
        x-transition:leave="transition ease-in duration-150"
        x-transition:leave-start="opacity-100"
        x-transition:leave-end="opacity-0"
        class="fixed inset-0 z-50 flex items-center justify-center p-4"
        style="display: none;">

        <div @click="showPreview = false" class="absolute inset-0 bg-black/30"></div>

        <div
            x-show="showPreview"
            x-transition:enter="transition ease-out duration-200 transform"
            x-transition:enter-start="opacity-0 scale-95 translate-y-2"
            x-transition:enter-end="opacity-100 scale-100 translate-y-0"
            x-transition:leave="transition ease-in duration-150 transform"
            x-transition:leave-start="opacity-100 scale-100"
            x-transition:leave-end="opacity-0 scale-95"
            class="relative bg-white border border-[#E0E5E5] rounded-xl p-6 w-full max-w-md z-10 max-h-[90vh] overflow-y-auto">

            <div class="flex items-center justify-between mb-5">
                <h3 class="text-lg font-semibold text-[#0D1B23]">Confirm Transfer</h3>
                <button @click="showPreview = false" class="w-8 h-8 rounded-lg hover:bg-[#DFE5E5] flex items-center justify-center transition-colors">
                    <i data-lucide="x" class="w-4 h-4 text-[#7A7A7A]"></i>
                </button>
            </div>

            <div class="space-y-0 mb-5">
                <div class="flex justify-between items-center py-3 border-b border-[#E0E5E5]">
                    <span class="text-[#7A7A7A] text-sm">Amount</span>
                    <span class="text-[#0D1B23] font-semibold text-lg" x-text="currency + parseFloat(amount || 0).toFixed(2)"></span>
                </div>
                <div class="flex justify-between items-center py-3 border-b border-[#E0E5E5]">
                    <span class="text-[#7A7A7A] text-sm">Recipient</span>
                    <span class="text-[#0D1B23] font-medium text-sm" x-text="account_name"></span>
                </div>
                <div class="flex justify-between items-center py-3 border-b border-[#E0E5E5]">
                    <span class="text-[#7A7A7A] text-sm">Account Number</span>
                    <span class="text-[#4A4A4A] font-mono text-sm" x-text="account_number"></span>
                </div>
                <div class="flex justify-between items-center py-3 border-b border-[#E0E5E5]">
                    <span class="text-[#7A7A7A] text-sm">Bank</span>
                    <span class="text-[#0D1B23] text-sm" x-text="bank_name"></span>
                </div>
                <div class="flex justify-between items-center py-3 border-b border-[#E0E5E5]">
                    <span class="text-[#7A7A7A] text-sm">Account Type</span>
                    <span class="text-[#0D1B23] text-sm" x-text="account_type"></span>
                </div>
                <div class="flex justify-between items-center py-3 border-b border-[#E0E5E5]">
                    <span class="text-[#7A7A7A] text-sm">Country</span>
                    <span class="text-[#0D1B23] text-sm" x-text="bank_country"></span>
                </div>
                
                <div class="flex justify-between items-center py-3">
                    <span class="text-[#7A7A7A] text-sm">Remaining Balance</span>
                    <span class="text-[#0D1B23] font-semibold" x-text="currency + remainingBalance.toFixed(2)"></span>
                </div>
            </div>

            <div class="bg-[#EBBC46]/10 border border-[#EBBC46]/20 rounded-lg p-3 mb-5">
                <div class="flex items-start space-x-2.5">
                    <i data-lucide="alert-triangle" class="w-4 h-4 text-[#EBBC46] flex-shrink-0 mt-0.5"></i>
                    <p class="text-xs text-[#7A7A7A]">This transfer is irreversible. Please verify all details before confirming.</p>
                </div>
            </div>

            <div class="flex space-x-3">
                <button
                    @click="showPreview = false"
                    class="flex-1 px-4 py-3 border border-[#C8D1D1] rounded-lg hover:bg-[#DFE5E5] transition-colors text-sm font-medium text-[#7A7A7A]">
                    Cancel
                </button>
                <button
                    @click="submitTransfer()"
                    class="flex-1 px-4 py-3 rounded-lg font-medium text-white text-sm bg-primary-500 hover:bg-primary-600 transition-colors">
                    Confirm Transfer
                </button>
            </div>
        </div>
    </div>

    <!-- Processing Modal -->
    <div
        x-show="isProcessing"
        x-transition:enter="transition ease-out duration-200"
        x-transition:enter-start="opacity-0"
        x-transition:enter-end="opacity-100"
        class="fixed inset-0 z-50 flex items-center justify-center p-4"
        style="display: none;">

        <div class="absolute inset-0 bg-black/30"></div>

        <div class="relative bg-white border border-[#E0E5E5] rounded-xl p-8 w-full max-w-sm z-10 text-center">
            <div class="w-14 h-14 mx-auto mb-5 rounded-xl bg-primary-50 border border-primary-200 flex items-center justify-center">
                <i data-lucide="loader" class="w-7 h-7 text-primary-500 spin-slow"></i>
            </div>

            <h3 class="text-lg font-semibold text-[#0D1B23] mb-1">Processing Transfer</h3>
            <p class="text-sm text-[#7A7A7A] mb-5" x-text="processingStage"></p>

            <div class="w-full bg-[#DFE5E5] rounded-full h-1.5 mb-2">
                <div
                    class="bg-primary-500 h-1.5 rounded-full transition-all duration-700 ease-out"
                    :style="'width: ' + processingProgress + '%'">
                </div>
            </div>
            <p class="text-xs text-[#7A7A7A] font-medium" x-text="processingProgress + '%'"></p>
        </div>
    </div>

</div>

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

        </div>
    </main>

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