@extends('layouts.admin')
@section('content')
<!-- start page title -->
<div class="row">
    <div class="col-12">
        <div class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
            <h4 class="mb-sm-0">Reject User</h4>

            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Home</a></li>
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Users</a></li>
                    <li class="breadcrumb-item active"> Reject Male</li>
                </ol>
            </div>
        </div>
    </div>
</div>
<!-- end page title -->


<div class="row">
    <div class="col-lg-12">
        <div class="card" id="orderList">
            <div class="card-body">
                <form class="tablelist-form {{ !empty($user->id) ? 'edit-form' : '' }}" autocomplete="off" action="{{ route('admin.users.rejectreason') }}" method="post" enctype="multipart/form-data" novalidate name="userForm" id="userForm">
                    @csrf
                    <input hidden id="id" name="id" value="{{ !empty($user->id) ? $user->id : '' }}">
                    <div class="row">
                         <div class="mb-3 col-lg-12">
                            <label for="customername-field" class="form-label">Reject Reason</label>
                            <input type="text" id="rejectreason" name="rejectreason" value="{{ !empty($user->reject_reason) ? $user->reject_reason : '' }}" class="form-control" placeholder="Enter Reject Reason" required />
                        </div>

                       
                    </div>

                    <div class="hstack gap-2 justify-content-between">
                        <a href="{{ route('admin.users.male') }}" class="btn btn-success">Back</a>
                        <button type="submit" class="btn btn-success" id="submitBtn">Submit</button>
                        <!-- <button type="button" class="btn btn-success" id="edit-btn">Update</button> -->
                    </div>
                </form> 
            </div>
        </div>
    </div>
</div>

@endsection
@section('script')
    <script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/additional-methods.min.js"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {

            $('.icon-image-field').change(function() {
            var file = this.files[0];
            var fileType = file.type;
            var validImageTypes = ['image/png', 'image/jpeg', 'image/png'];

            if (validImageTypes.includes(fileType)) {
                var reader = new FileReader();

                reader.onload = function(event) {
                    $('.icon-image-preview').attr('src',event.target.result);
                }

                reader.readAsDataURL(file);
            }
        });

            $(document).on('change', '#profile_image', function () {
                $('#submitBtn').prop('disabled', false);
            });

            const dateInput = document.getElementById('dob');
            const today = new Date().toISOString().split('T')[0]; // Format as YYYY-MM-DD
           // dateInput.setAttribute('max', today);


           
    $("#userForm").validate({
        rules: {
            rejectreason: {
                required: true,
                minlength: 10,
            },
        },
        messages: {
            rejectreason: {
                required: "Please enter reject reason.",
                minlength: "Reject reason must be at least 10 characters.",
            },
        },
        submitHandler: function (form, event) {
            event.preventDefault(); // prevent default submit
            let formData = new FormData(form);

            $.ajax({
                url: form.action,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                },
                success: function (response) {
                    Swal.fire({
                        iconHtml: `<img src="{{ asset('assets/images/success-circle.svg') }}" class="img-fluid">`,
                        text: response.message,
                        confirmButtonText: "OK",
                        customClass: { confirmButton: 'custom-ok-button-class w-sm' }
                    }).then(() => {
                        window.location.href = "{{ route('admin.users.male') }}";
                    });
                },
                error: function (xhr) {
                    console.error("AJAX error:", xhr);
                }
            });
        }
    });


        });
    </script>
    
@endsection
