@php
    $jobid = request()->query('jobid');
    $serviceid = request()->query('serviceid');
@endphp
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    @if (config('GET.main_favicon'))
    <link rel="icon" type="image/png" sizes="16x16" href="{{ asset('assets/photo/' .config('GET.main_favicon')) }}">
    @else
    <link rel="icon" type="image/png" sizes="16x16" href="{{ asset('assets/photo/favicon.png') }}">
    @endif
    <title>SURPLUS-HR</title>
    <link rel="stylesheet" href="{{ asset('frontend/css/font-awesome.min.css') }}">
    <link href="{{ asset('frontend/css/bootstrap.min.css') }}" rel="stylesheet">
    <link rel="stylesheet" href="{{ asset('frontend/css/style.css') }}">
    <link rel="stylesheet" href="{{ asset('frontend/css/owl.carousel.css') }}">
    <link rel="stylesheet" href="{{ asset('frontend/css/responsive.css') }}">
    <script src="{{ asset('frontend/js/jquery-3.5.1.min.js') }}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>
</head>

<style>
    .error {
        color: red;
    }

    /* Adjusting the positioning of the password icon */
    .password-container {
        position: relative;
    }

    .password-container input {
        padding-right: 35px; /* Add padding to the right of the input field to make space for the icon */
    }

    .password-icon {
        position: absolute;
        right: 10px;  /* Position the icon 10px from the right side */
        top: 66%;
        transform: translateY(-50%); /* Vertically center the icon */
        cursor: pointer;
    }
</style>

<body>
    <div class="login-layout d-flex">
        <div class="login-layout-lt">
            <div class="caption-card">
                <img style="width: 19rem;" src="{{ asset('frontend/images/logoFt.png') }}" alt="logo">
                <h1>Hi, Welcome <br> Back!</h1>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
            </div>
        </div>

        <div class="login-layout-rt">
            <div class="login-layout-rt-content">
                <div style="text-align: right;">
                    <a href="{{route('home')}}">Back to home page</a>
                </div>
                <div class="title">
                    <h2>Sign In</h2>
                    <p>Welcome, Sign In to your account.</p>
                </div>
                @include('frontend.layouts.flash_message')
                {{-- $serviceid --}}
                <form action="{{ route('submit.login') . ($jobid ? '?jobid=' . $jobid : '') . ($serviceid ? ($jobid ? '&' : '?') . 'serviceid=' . $serviceid : '') }}" method="POST">
                    @csrf <!-- CSRF protection -->
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="required">Email</label>
                                <input type="text" name="email" class="form-control" value="{{ old('email') }}" placeholder="example@email.com" required>
                            </div>
                        </div>
                        <div class="col-sm-12">
                            <div class="form-group password-container">
                                <label class="required">Password</label>
                                <input type="password" name="password" class="form-control" placeholder="............" required id="password-field">
                                <i class="fa fa-eye-slash password-icon" style="top: 54px;" id="toggle-password"></i> <!-- Eye icon -->
                            </div>
                        </div>
                        <div class="col-sm-12">
                            <div class="remember-link mb-2 d-flex align-items-center justify-content-between">
                                <label class="custom-checkbox">Remember
                                    <input type="checkbox" name="remember" checked="checked">
                                    <span class="checkmark"></span>
                                </label>
                                <a href="{{route('user.forgotPassword')}}" class="forgot-link">Forgot password?</a>
                            </div>
                        </div>
                        <div class="col-sm-12 text-right my-4">
                            <button type="submit" class="btn-custom" id="sign-in">Sign In</button>
                        </div>
                        <div class="col-sm-12 text-center">
                            Don't have an account? <a href="{{route('home')}}">Sign Up</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="{{ asset('frontend/js/popper.min.js') }}"></script>
    <script src="{{ asset('frontend/js/bootstrap.min.js') }}"></script>
    <script src="{{ asset('frontend/js/iphone-menu.js') }}"></script>
    <script src="{{ asset('frontend/js/owl.carousel-min.js') }}"></script>
    <script src="{{ asset('frontend/js/custom.js') }}"></script>
    <script>
        $(document).ready(function() {
            // Add custom validation method for email without extension
            $.validator.addMethod("validEmail", function(value, element) {
                // Regex to validate email format with an extension
                return this.optional(element) || /^[\w.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
            }, "Please enter a valid email address with an extension.");

            // Validate the form
            $("form").validate({
                rules: {
                    email: {
                        required: true,
                        validEmail: true // Use the custom method
                    },
                    password: {
                        required: true
                    }
                },
                messages: {
                    email: {
                        required: "Email is required.",
                        validEmail: "Please enter a valid email address with an extension."
                    },
                    password: {
                        required: "Password is required."
                    }
                },
                errorClass: "error", // Class for error message
                highlight: function(element) {
                    $(element).addClass("error");
                },
                unhighlight: function(element) {
                    $(element).removeClass("error");
                },
                submitHandler: function(form) {
                    // This function will be called if the form is valid
                    // You can perform actions here before submitting, e.g.:
                    console.log("Form is valid. Submitting...");

                    // Optionally disable the submit button
                    $(form).find("button[type='submit']").prop("disabled", true);

                    // Submit the form
                    form.submit();
                }
            });

            // Trim leading spaces on input
            const inputs = document.querySelectorAll('input');
            inputs.forEach(input => {
                input.addEventListener('input', function() {
                    this.value = this.value.replace(/^\s+/, '');
                });
            });

            // Toggle password visibility
            $('#toggle-password').on('click', function() {
                var passwordField = $('#password-field');
                var type = passwordField.attr('type') === 'password' ? 'text' : 'password';
                passwordField.attr('type', type);
                $(this).toggleClass('fa-eye fa-eye-slash'); // Toggle eye icon
            });
        });
    </script>
</body>
</html>
