

<?php $__env->startSection('title', 'Xét tuyển theo kết quả Trung Học Phổ Thông Quốc Gia - Xét tuyển online Trường Đại học Bình Dương'); ?>

<?php $__env->startSection('content'); ?>

<main>
    <div class="container" id="container">
        <h1 class="post-title">ĐĂNG KÝ XÉT TUYỂN ĐẠI HỌC BẰNG KẾT QUẢ THI THPT QUỐC GIA</h1>
        <p class="post-subtitle">THỜI GIAN: <?php echo e($dotXetTuyen->NgayBatDau->format('d/m/Y')); ?> - <?php echo e($dotXetTuyen->NgayKetThuc->format('d/m/Y')); ?></p>
        <form action="<?php echo e(route('user.storeTHPT')); ?>" class="form-xet-tuyen" id="form-xet-tuyen" method="post" enctype="multipart/form-data" onsubmit="return onSubmitPressed();">
            <?php echo csrf_field(); ?>

            <?php if(session()->has('success')): ?>
            <div id="success-message" class="alert alert-success card " role="alert">
                <div class='upper-side'>
                    <div class="status">
                        <?php echo session()->get('success'); ?>

                        <button type="button" class="close Btn" data-dismiss="alert" aria-label="Close" onclick="document.getElementById('success-message').style.display='none';">
                            <span>&times;</span>
                        </button>
                    </div>
                </div>
            </div>
            <?php endif; ?>

            <?php if(session()->has('error')): ?>
            <div class="alert alert-error" role="alert">
                <?php echo e(session()->get('error')); ?>

                <button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="this.parentElement.style.display='none';">
                    <span>&times;</span>
                </button>
            </div>
            <?php endif; ?>

            <section class="form-section">
                <h2 class="form-section-title">THÔNG TIN HỌC SINH</h2>
                <div class="form-field-container">
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="hoVaTen">Họ và tên học
                            sinh</label>
                        <input type="text" placeholder="Họ và tên" size="0" class="form-field-input" name="hoVaTen" value="<?php echo e(session()->has('success') ? '' : old('hoVaTen')); ?>" required>
                        <?php $__errorArgs = ['hoVaTen'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="gioiTinh">Giới
                            tính</label>
                        <select size="0" class="form-field-input" name="gioiTinh" required>
                            <option value="" selected>Chọn giới tính</option>
                            <option value="1" <?php echo e(session()->has('success') ? '' : (old('gioiTinh') == '1' ? 'selected' : '')); ?>>Nam</option>
                            <option value="0" <?php echo e(session()->has('success') ? '' : (old('gioiTinh') == '0' ? 'selected' : '')); ?>>Nữ</option>
                        </select>
                        <?php $__errorArgs = ['gioiTinh'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="ngaySinh">Ngày
                            sinh</label>
                        <input type="date" requied size="0" class="form-field-input" name="ngaySinh" value="<?php echo e(session()->has('success') ? '' : old('ngaySinh')); ?>" max="<?php echo date('Y-m-d'); ?>" required>
                        <?php $__errorArgs = ['ngaySinh'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="cccd">Số CCCD</label>
                        <input type="number" placeholder="Số CCCD" size="0" class="form-field-input" name="cccd" value="<?php echo e(session()->has('success') ? '' : old('cccd')); ?>" required>
                        <?php $__errorArgs = ['cccd'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label" for="email">Địa chỉ email</label>
                        <input type="email" placeholder="Địa chỉ email" size="0" class="form-field-input" name="email" value="<?php echo e(session()->has('success') ? '' : old('email')); ?>" required>
                        <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="soDienThoai">Số điện
                            thoại</label>
                        <input type="tel" placeholder="Số điện thoại" size="0" class="form-field-input" name="soDienThoai" value="<?php echo e(session()->has('success') ? '' : old('soDienThoai')); ?>" pattern=".{10,12}" title="Vui lòng nhập từ 10 đến 12 số" required>
                        <?php $__errorArgs = ['soDienThoai'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="diaChi">Địa chỉ liên
                            lạc</label>
                        <input type="text" placeholder="Nơi nhận giấy báo trúng tuyển" size="0" class="form-field-input" name="diaChi" value="<?php echo e(session()->has('success') ? '' : old('diaChi')); ?>" required>
                        <?php $__errorArgs = ['diaChi'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="tinh">Tỉnh/Thành
                            phố</label>
                        <select id="tinh" size="0" class="form-field-input" name="tinh" required>
                            <option value="" selected>Chọn Tỉnh/TP</option>
                            <?php $__currentLoopData = $tinhs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tinh): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($tinh->MaTinh); ?>" <?php echo e(session()->has('success') ? '' : (old('tinh') == $tinh->MaTinh ? 'selected' : '')); ?>><?php echo e($tinh->TenTinh); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php $__errorArgs = ['tinh'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div id="container-truong" class="form-field">
                        <label class="form-field-label form-field-label--required" for="truongTHPT">Trường
                            THPT</label>
                        <select id="truong" size="0" class="form-field-input" name="truongTHPT" required>
                            <option value="" selected>Chọn trường THPT</option>
                        </select>
                        <?php $__errorArgs = ['truongTHPT'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        <p class="form-field-note">
                            (Ghi chú: Nếu là thí sinh tự do thì bạn chọn trường THPT đã tốt nghiệp trước đó)
                        </p>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="khuVuc">Khu vực</label>
                        <select size="0" class="form-field-input" name="khuVuc" required>
                            <option value="" selected>Chọn khu vực</option>
                            <?php $__currentLoopData = $khuVucs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $khuVuc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($khuVuc->MaKhuVuc); ?>" <?php echo e(session()->has('success') ? '' : (old('khuVuc') == $khuVuc->MaKhuVuc ? 'selected' : '')); ?> ><?php echo e($khuVuc->TenKhuVuc); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php $__errorArgs = ['khuVuc'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="khuVuc">Đối tượng</label>
                        <select size="0" class="form-field-input" name="doiTuong" required>
                            <option value="" selected>Chọn đối tượng</option>
                            <?php $__currentLoopData = $doiTuongs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doiTuong): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($doiTuong->MaDoiTuong); ?>" <?php echo e(session()->has('success') ? '' : (old('doiTuong') == $doiTuong->MaDoiTuong ? 'selected' : '')); ?>><?php echo e($doiTuong->TenDoiTuong); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php $__errorArgs = ['doiTuong'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                </div>
            </section>
            <section class="form-section">
                <h2 class="form-section-title">THÔNG TIN ĐĂNG KÝ</h2>
                <div class="form-field-container">
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="bacHoc">Bậc học</label>
                        <select size="0" class="form-field-input" name="bacHoc" required>
                            <option selected>Đại học</option>
                        </select>
                    </div>
                    <div class="form-field">
                        <label class="form-field-label form-field-label--required" for="nganhHoc">Ngành
                            học</label>
                        <select id="nganh-hoc" size="0" class="form-field-input" name="nganhHoc" required>
                            <option value="" selected>Chọn ngành học</option>
                            <?php $__currentLoopData = $nganhHocs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $nganhHoc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($nganhHoc->chuyennganh->isEmpty()): ?>
                                    <option value="<?php echo e($nganhHoc->MaNganhHoc); ?>-0" <?php echo e(session()->has('success') ? '' : (old('nganhHoc') == $nganhHoc->MaNganhHoc . '-0' ? 'selected' : '')); ?>>
                                        <?php echo e($nganhHoc->TenNganhHoc); ?>

                                    </option>
                                <?php else: ?>
                            <?php $__currentLoopData = $nganhHoc->chuyennganh; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $chuyenNganh): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($nganhHoc->MaNganhHoc); ?>-<?php echo e($chuyenNganh->MaChuyenNganh); ?>" <?php echo e(session()->has('success') ? '' : (old('nganhHoc') == $nganhHoc->MaNganhHoc . '-' . $chuyenNganh->MaChuyenNganh ? 'selected' : '')); ?>>
                                    <?php echo e($nganhHoc->TenNganhHoc); ?> (<?php echo e($chuyenNganh->TenChuyenNganh); ?>)
                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php $__errorArgs = ['nganhHoc'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        <p class="form-field-note">(Ghi chú: Thí sinh được phép chuyển đổi ngành phù hợp sau 1
                            Học kỳ đến 1 Năm học theo quy chế của Bộ Giáo dục và Đào tạo.)</p>
                    </div>
                    <div id="container-khoi-xet-tuyen" class="form-field">
                        <label class="form-field-label form-field-label--required" for="khoiXetTuyen">Tổ hợp xét tuyển</label>
                        <select id="khoi-xet-tuyen" size="0" class="form-field-input" name="khoiXetTuyen" required>
                            <option value="" selected>Chọn tổ hợp xét tuyển</option>
                        </select>
                        <?php $__errorArgs = ['khoiXetTuyen'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field form-field-grade">
                        <label class="form-field-label form-field-label--required">Nhập kết quả học tập (Tôi cam đoan số điểm trên hoàn toàn đúng với học bạ của tôi)</label>
                        <table class="form-table-input">
                            <thead>
                                <tr>
                                    <th width="25%" id='mon-1' name="monHocMot"></th>
                                    <th width="25%" id='mon-2' name="monHocHai"></th>
                                    <th width="25%" id='mon-3' name="monHocBa"></th>
                                    <th width="25%">Tổng điểm</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td data-label="" id="label-1">
                                        <input type="number" name="diemMon1" size="0" placeholder="Nhập điểm..." required min="0" max="10" step="0.01" value="<?php echo e(session()->has('success') ? '' : old('diemMon1')); ?>" oninput="tongDiemTHPT()">
                                    </td>
                                    <td data-label="" id="label-2">
                                        <input type="number" name="diemMon2" size="0" placeholder="Nhập điểm..." required min="0" max="10" step="0.01" value="<?php echo e(session()->has('success') ? '' : old('diemMon2')); ?>" oninput="tongDiemTHPT()">
                                    </td>
                                    <td data-label="" id="label-3">
                                        <input type="number" name="diemMon3" size="0" placeholder="Nhập điểm..." required min="0" max="10" step="0.01" value="<?php echo e(session()->has('success') ? '' : old('diemMon3')); ?>" oninput="tongDiemTHPT()">
                                    </td>
                                    <td data-label="Tổng điểm">
                                        <input type="number" name="tongDiem" disabled size="0" placeholder="">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <?php $__errorArgs = ['diemMon1'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        <?php $__errorArgs = ['diemMon2'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        <?php $__errorArgs = ['diemMon3'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="form-field form-field-grade">
                        <label class="form-field-label" id="tongDiemDaCoDiemUuTien"></label>
                    </div>
                    <div class="form-field">
                    <input type="checkbox" id="nguyen-vong-du-hoc" class="form-field-input form-field-input--checkbox" name="nguyenVongDuHoc" value="0" <?php echo e(session()->has('success') ? '' : (old('nguyenVongDuHoc') ? 'checked' : '')); ?>>
                    <label class="form-field-label" for="nguyenVongDuHoc">Nguyện vọng du học</label>
                    </div>
                    <div class="form-field" id="namTotNghiepField">
                        <label class="form-field-label" for="namTotNghiep">Năm tốt nghiệp (có thể bỏ qua nếu chưa tốt nghiệp)</label>
                        <input type="number" placeholder="Năm tốt nghiệp" size="0" class="form-field-input" name="namTotNghiep" value="<?php echo e(session()->has('success') ? '' : old('namTotNghiep')); ?>">                        <?php $__errorArgs = ['namTotNghiep'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <span style="color: red"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div class="form-field" id="fileUploadField">
                        <label class="form-field-label" for="fileUpload">
                            File học bạ (hình, hoặc scan)
                            <span class="form-field-input--file-button">
                                <img src="<?php echo e(asset('/assets/img/websiteInterface/user/icons/cloud-computing.png')); ?>" class="form-field-input--file-icon">Chọn file
                            </span>
                        </label>
                        <input type="file" id="fileUpload" size="0" class="form-field-input form-field-input--file" name="fileUpload[]" multiple>
                        <div id="file-list"></div>
                        <div id="message"></div>
                        <input type="hidden" id="hiddenFiles" name="hiddenFiles">
                    </div>
                    <div class="form-submit">
                        <span class="form-submit-bar"></span>
                        <input type="submit" class="form-submit-button" size="0" value="Đăng ký xét tuyển">
                        <span class="form-submit-bar"></span>
                    </div>
                </div>
            </section>
        </form>
    </div>
</main>

<style>
    .card {
        z-index: 10000000;
        text-align: center;
    }

    .upper-side {
        position: relative;
        padding: 30px;
        background: wheat;
        display: block;
        color: #000000;
        font-weight: 600;
        border-radius: 12px;
        margin: 100px auto;
        width: 70%;
    }

    .status {
        text-transform: uppercase;
        letter-spacing: 2px;
        font-size: 13px;
        margin-bottom: 0;
        overflow-wrap: break-word;
    }

    .Btn {
        background: #fff;
        margin: auto;
        padding: 8px 15px;
        border-radius: 12px;
        border: wheat;
    }

    .alert-success {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .alert-success .close {
        color: #155724;
        position: absolute;
        top: 0;
        right: 0px;
    }

    .alert {
        padding: 40px;
        margin-bottom: 20px;
        border: 1px solid transparent;
        border-radius: 4px;
        background: rgba(0, 0, 0, 0.8);
        width: 100%;
        height: 100%;
    }

    .alert-error {
        color: #ffffff;
        background-color: #a02321;
        border-color: #d6e9c6;
    }

    .close {
        cursor: pointer;
        float: right;
        font-size: 20px;
        font-weight: bold;
    }

    .message {
        margin-top: 10px;
        font-size: 14px;
    }

    .message.error {
        color: red;
    }

    .message.success {
        color: green;
    }

    .close-button {
        margin-left: 5px;
        background: none;
        color: red;
        cursor: pointer;
        font-size: 14px;
    }
</style>

<script>
    // Lấy trường học thông qua tỉnh
    document.addEventListener('DOMContentLoaded', function() {
        var tinhSelect = document.getElementById('tinh');
        var truongHocSelect = document.getElementById('truong');
        var maTinhOld = "<?php echo e(session()->has('success') ? '' : old('tinh')); ?>";
        var maTruongOld = "<?php echo e(session()->has('success') ? '' : old('truongTHPT')); ?>";

        if (maTinhOld) {
            fetch(`/get-truong-hoc-THPT/${maTinhOld}`)
                .then(response => response.json())
                .then(data => {
                    truongHocSelect.innerHTML = '<option value="">Chọn trường THPT</option>';

                    Object.keys(data).forEach(function(MaTruong) {
                        var option = document.createElement('option');
                        option.text = data[MaTruong];
                        option.value = MaTruong;
                        if (MaTruong == maTruongOld) {
                            option.selected = true;
                        }
                        truongHocSelect.appendChild(option);
                    });
                });
        }

        tinhSelect.addEventListener('change', function() {
            var maTinh = this.value;
            if (maTinh) {
                fetch(`/get-truong-hoc-THPT/${maTinh}`)
                    .then(response => response.json())
                    .then(data => {
                        truongHocSelect.innerHTML = '<option value="">Chọn trường THPT</option>';

                        Object.keys(data).forEach(function(MaTruong) {
                            var option = document.createElement('option');
                            option.text = data[MaTruong];
                            option.value = MaTruong;
                            truongHocSelect.appendChild(option);
                        });

                    });
            } else {
                truongHocSelect.innerHTML = '<option value="">Chọn trường THPT</option>';
            }
        });

    });

    // Lấy khối xét tuyển và môn học
    document.addEventListener('DOMContentLoaded', function() {
        var nganhHocSelect = document.getElementById('nganh-hoc');
        var khoiXetTuyenSelect = document.getElementById('khoi-xet-tuyen');
        var oldNganhHoc = "<?php echo e(session()->has('success') ? '' : old('nganhHoc')); ?>";
        var oldKhoiXetTuyen = "<?php echo e(session()->has('success') ? '' : old('khoiXetTuyen')); ?>";
        var oldMonHocMot = "<?php echo e(old('monHocMot')); ?>";
        var oldMonHocHai = "<?php echo e(old('monHocHai')); ?>";
        var oldMonHocBa = "<?php echo e(old('monHocBa')); ?>";
        if (oldNganhHoc) {
            var selectedValue = oldNganhHoc;
            var maNganhHoc = selectedValue.split('-')[0];

            fetch(`/get-khoi-xet-tuyen-THPT/${maNganhHoc}`)
                .then(response => response.json())
                .then(data => {
                    khoiXetTuyenSelect.innerHTML = '<option value="">Chọn tổ hợp xét tuyển</option>';
                    Object.keys(data).forEach(function(MaKhoiXetTuyen) {
                        var option = document.createElement('option');
                        option.text = data[MaKhoiXetTuyen];
                        option.value = MaKhoiXetTuyen;
                        console.log('MaKhoi:', MaKhoiXetTuyen);
                        console.log('oldKhoiXetTuyen:', oldKhoiXetTuyen);
                        if (MaKhoiXetTuyen == oldKhoiXetTuyen) {
                            option.selected = true;

                            fetch(`/get-mon-hoc-THPT/${MaKhoiXetTuyen}`)
                                .then(response => response.json())
                                .then(data => {
                                    Object.keys(data).forEach(function(MaMonHoc, index) {
                                        var labelId = 'mon-' + (index + 1);
                                        var monLabel = document.getElementById(labelId);
                                        monLabel.innerHTML = data[MaMonHoc];
                                        monLabel.setAttribute('value', MaMonHoc);
                                        if (index == 0 && oldMonHocMot) {
                                            monLabel.innerHTML = oldMonHocMot;
                                        }
                                        if (index == 1 && oldMonHocHai) {
                                            monLabel.innerHTML = oldMonHocHai;
                                        }
                                        if (index == 2 && oldMonHocBa) {
                                            monLabel.innerHTML = oldMonHocBa;
                                        }
                        		var thLabel = 'label-' +(index + 1);
                        		var labelTh = document.getElementById(thLabel);
                        		labelTh.setAttribute('data-label', data[MaMonHoc]);
                                    });
                                });
                        }

                        khoiXetTuyenSelect.appendChild(option);
                    });
                });
        }

        nganhHocSelect.addEventListener('change', function() {
            var selectedValue = this.value;
            var maNganhHoc = selectedValue.split('-')[0];

            fetch(`/get-khoi-xet-tuyen-THPT/${maNganhHoc}`)
                .then(response => response.json())
                .then(data => {
                    khoiXetTuyenSelect.innerHTML = '<option value="">Chọn tổ hợp xét tuyển</option>';

                    Object.keys(data).forEach(function(MaKhoi) {
                        var option = document.createElement('option');
                        option.text = data[MaKhoi];
                        option.value = MaKhoi;
                        khoiXetTuyenSelect.appendChild(option);
                    });
                });
        });

        khoiXetTuyenSelect.addEventListener('change', function() {
            var maKhoiXetTuyen = this.value;
            fetch(`/get-mon-hoc-THPT/${maKhoiXetTuyen}`)
                .then(response => response.json())
                .then(data => {
                    Object.keys(data).forEach(function(MaMonHoc, index) {
                        var labelId = 'mon-' + (index + 1);
                        var monLabel = document.getElementById(labelId);
                        monLabel.innerHTML = data[MaMonHoc];
                        monLabel.setAttribute('value', MaMonHoc);

                        var thLabel = 'label-' +(index + 1);
                        var labelTh = document.getElementById(thLabel);
                        labelTh.setAttribute('data-label', data[MaMonHoc]);
                    });
                });
        });
    });


    // Tính toán điểm
    function tongDiemTHPT() {
        var diemMon1 = parseFloat(document.getElementsByName("diemMon1")[0].value);
        var diemMon2 = parseFloat(document.getElementsByName("diemMon2")[0].value);
        var diemMon3 = parseFloat(document.getElementsByName("diemMon3")[0].value);

        if (!isNaN(diemMon1) && !isNaN(diemMon2) && !isNaN(diemMon3)) {
            var tongDiem = diemMon1 + diemMon2 + diemMon3;
            document.getElementsByName("tongDiem")[0].value = tongDiem.toFixed(2);
            updateTongDiem();
        }
    }

    // Lấy điểm ưu tiên
    document.addEventListener('DOMContentLoaded', function() {
        var khuVucSelect = document.getElementsByName('khuVuc')[0];
        var doiTuongSelect = document.getElementsByName('doiTuong')[0];

        khuVucSelect.addEventListener('change', function() {
            updateTongDiem();
        });

        doiTuongSelect.addEventListener('change', function() {
            updateTongDiem();
        });
    });

    // Tính toán tổng điểm
    function updateTongDiem() {

        var khuVucSelect = document.getElementsByName('khuVuc')[0];
        var doiTuongSelect = document.getElementsByName('doiTuong')[0];
        var diemMon1 = parseFloat(document.getElementsByName("diemMon1")[0].value);
        var diemMon2 = parseFloat(document.getElementsByName("diemMon2")[0].value);
        var diemMon3 = parseFloat(document.getElementsByName("diemMon3")[0].value);

        var tongDiemLabel = document.getElementById('tongDiemDaCoDiemUuTien');

        var tongDiem = 0;
        diemMon1 = isNaN(diemMon1) ? 0 : diemMon1;
        diemMon2 = isNaN(diemMon2) ? 0 : diemMon2;
        diemMon3 = isNaN(diemMon3) ? 0 : diemMon3;

        var diemUuTienKhuVuc = 0;
        var diemUuTienDoiTuong = 0;

        if (khuVucSelect.value !== "Chọn khu vực" && doiTuongSelect.value !== "Chọn đối tượng") {
            // Lấy điểm ưu tiên của khu vực
            var maKhuVuc = khuVucSelect.value;
            fetch(`/get-diem-uu-tien-khu-vuc/${maKhuVuc}`)
                .then(response => response.json())
                .then(data => {
                    diemUuTienKhuVuc = parseFloat(data[0]);

                    var maDoiTuong = doiTuongSelect.value;
                    fetch(`/get-diem-uu-tien-doi-tuong/${maDoiTuong}`)
                        .then(response => response.json())
                        .then(data => {
                            diemUuTienDoiTuong = parseFloat(data[0]);

                            tongDiem = diemUuTienKhuVuc + diemUuTienDoiTuong + diemMon1 + diemMon2 + diemMon3;
                            tongDiemLabel.innerText = "Tổng điểm: " + tongDiem.toFixed(2) + " (Đã cộng điểm ưu tiên)";
                        })
                        .catch(error => console.error(error));
                })
                .catch(error => console.error(error));
        } else {
            tongDiem = diemMon1 + diemMon2 + diemMon3;
            tongDiemLabel.innerText = "Tổng điểm: " + tongDiem.toFixed(2) + " (Chưa cộng điểm ưu tiên)";
        }
    }
    
    document.addEventListener('DOMContentLoaded', function() {
        tongDiemTHPT();
        updateTongDiem();
    });

    // Upload file hình ảnh 
    document.getElementById('fileUpload').addEventListener('change', function() {
        const validFileExtensions = ['png', 'jpg', 'jpeg', 'pdf'];
        const maxFileSize = 10 * 1024 * 1024;
        const maxTotalSize = 20 * 1024 * 1024;
        let totalSize = 0;
        let filesArray = [];

        const fileList = document.getElementById('file-list');
        const message = document.getElementById('message');
        message.innerHTML = '';

        const files = this.files;
        for (let i = 0; i < files.length; i++) {
            const file = files[i];
            const fileExtension = file.name.split('.').pop().toLowerCase();
            const fileSize = file.size;

            if (!validFileExtensions.includes(fileExtension)) {
                message.textContent = 'Định dạng tệp không hợp lệ, vui lòng upload file có định dạng png, jpg, jpeg hoặc pdf';
                message.className = 'message error';
                return;
            }

            if (fileSize > maxFileSize) {
                message.textContent = 'Kích thước tệp quá lớn, tối đa mỗi tệp là 10MB.';
                message.className = 'message error';
                return;
            }

            totalSize += fileSize;
            if (totalSize > maxTotalSize) {
                message.textContent = 'Tổng dung lượng không được vượt quá 20MB.';
                message.className = 'message error';
                return;
            }

            filesArray.push(file);

            const reader = new FileReader();
            reader.onload = function(event) {
                const hiddenFiles = document.getElementById('hiddenFiles');
                let fileInfoArray = JSON.parse(hiddenFiles.value || '[]');
                fileInfoArray.push({
                    name: file.name,
                    size: file.size,
                    type: file.type,
                    lastModified: file.lastModified,
                    content: event.target.result.split(',')[1]
                });
                hiddenFiles.value = JSON.stringify(fileInfoArray);
            };
            reader.readAsDataURL(file);

            const listItem = document.createElement('div');
            listItem.textContent = 'Đã chọn thành công file ' + file.name;
            listItem.dataset.fileIndex = filesArray.length - 1;
            listItem.className = 'message success';

            const closeButton = document.createElement('button');
            closeButton.textContent = 'x';
            closeButton.className = 'close-button';
            closeButton.addEventListener('click', function() {
                totalSize = totalSize - fileSize;
                filesArray = filesArray.filter((_, index) => index != listItem.dataset.fileIndex);
                fileList.removeChild(listItem);

                const hiddenFiles = document.getElementById('hiddenFiles');
                let fileInfoArray = JSON.parse(hiddenFiles.value || '[]');
                fileInfoArray = fileInfoArray.filter((_, index) => index != listItem.dataset.fileIndex);
                hiddenFiles.value = JSON.stringify(fileInfoArray);

                Array.from(fileList.children).forEach((child, index) => {
                    child.dataset.fileIndex = index;
                    filesArray[index] = filesArray[child.dataset.fileIndex];
                });
            });

            listItem.appendChild(closeButton);
            fileList.appendChild(listItem);
        }
    });
    
    // Click chọn checkbox
    document.addEventListener('DOMContentLoaded', function() {
        var checkbox = document.getElementById('nguyen-vong-du-hoc');
        checkbox.value = checkbox.checked ? '1' : '0';
        checkbox.addEventListener('change', function() {
            this.value = this.checked ? '1' : '0';
        });
    });

    // Hiển thị thông báo xét tuyển
    document.addEventListener('DOMContentLoaded', function() {
        var registerForm = document.getElementById('form-xet-tuyen');
        var successMessage = document.getElementById('success-message');

        if (successMessage) {
            document.getElementById('container').appendChild(successMessage);
            successMessage.style.display = 'block';
        }
    });
</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('masterUser', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/demo/public_html/resources/views/users/tuyenSinhTHPT.blade.php ENDPATH**/ ?>