@extends('backend.layouts.app')

@section('content')
    <div class="row page-titles">
        <div class="col-md-5 align-self-center">
            <h4 class="text-themecolor">Edit Member</h4>
        </div>
        <div class="col-md-7 align-self-center text-right">
            <div class="d-flex justify-content-end align-items-center">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="{{ route('member') }}">Member</a></li>
                    <li class="breadcrumb-item active">Edit Member</li>
                </ol>
            </div>
        </div>
    </div>

    <div class="container-fluid">
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Main content -->
            <section class="content">
                <div class="row">
                    <div class="col-md-12">
                        <!-- General form elements -->
                        <div class="card card-primary">
                            <div class="card-body">
                                <form id="member_form" action="{{ route('member.updates',$member->id) }}" method="POST" enctype="multipart/form-data">
                                    @csrf
                                    <div class="row">


                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="person_significate_control">Person with Significate Control (PSC)<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="person_significate_control" name="person_significate_control" class="form-control" placeholder="Enter Person with Significate Control (PSC)" value="{{ old('person_significate_control', $member->person_significate_control ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="business_name">Business Name<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="business_name" name="business_name" class="form-control" placeholder="Enter company name" value="{{ old('business_name', $member->business_name ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="email">Email<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="email" id="email" name="email" class="form-control" placeholder="Enter email address" value="{{ old('email', $member->email ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="mobile_number">Mobile Number<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="mobile_number" oninput="this.value = this.value.replace(/[^0-9]/g, '');" name="mobile_number" class="form-control" placeholder="Enter mobile number" value="{{ old('mobile_number', $member->mobile_number ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="second_mobile_number">Second Mobile Number<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="second_mobile_number" oninput="this.value = this.value.replace(/[^0-9]/g, '');" name="second_mobile_number" class="form-control" placeholder="Enter mobile number" value="{{ old('second_mobile_number', $member->second_mobile_number ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="business_address">Business Address<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="business_address" name="business_address" class="form-control" placeholder="Enter Business Address" value="{{ old('business_address', $member->business_address ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="business_address_line_two">Business Address Line Two</label>
                                                <input type="text" id="business_address_line_two" name="business_address_line_two" class="form-control" placeholder="Enter Business Address Line Two" value="{{ old('business_address_line_two', $member->business_address_line_two ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="business_post_code">Business Post Code<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="business_post_code" name="business_post_code" class="form-control" placeholder="Enter Business Post Code" value="{{ old('business_post_code', $member->business_post_code ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="business_area_code">Business Code<span style="color: red;font-size:18px;"><b>*</b></span></label><select name="business_area_code" class="form-control" id="business_area_code">
                                                                    <option value="">Select Area</option>
                                                                    @foreach ($areas as $areaCode => $area)
                                                                        <option {{$member->business_area_code==$areaCode? 'selected':''}} value="{{$areaCode}}">{{$areaCode." (".$area.") "}}</option>
                                                                    @endforeach
                                                                </select>

                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="business_district_code">Business District Code<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="business_district_code" name="business_district_code" class="form-control" placeholder="Enter Business District Code" value="{{ old('business_district_code', $member->business_district_code ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="company_name">Company Name<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="company_name" name="company_name" class="form-control" placeholder="Enter Company Name" value="{{ old('company_name', $member->company_name ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="company_number">Company Number<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="company_number" name="company_number" class="form-control" placeholder="Enter Company Number" value="{{ old('company_number', $member->company_number ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="company_address">Company Address<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="company_address" name="company_address" class="form-control" placeholder="Enter Company Address" value="{{ old('company_address', $member->company_address ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="company_address_line_two">Company Address Line Two</label>
                                                <input type="text" id="company_address_line_two" name="company_address_line_two" class="form-control" placeholder="Enter Company Address Line Two" value="{{ old('company_address_line_two', $member->company_address_line_two ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="company_post_code">Company Post Code<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="company_post_code" name="company_post_code" class="form-control" placeholder="Enter Company Post Code" value="{{ old('company_post_code', $member->company_post_code ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="balance">Balance<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="number" id="balance" name="balance" class="form-control" placeholder="Enter Balance" value="{{ old('balance', $member->balance ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="minimum_account_balance">Minimum Account Balance</label>
                                                <input type="number" id="minimum_account_balance" name="minimum_account_balance" class="form-control" placeholder="Enter Minimum Account Balance" value="{{ old('minimum_account_balance', $member->minimum_account_balance ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="profile_image">Profile Image</label>
                                                <input type="file" id="profile_image" name="profile_image" class="form-control" placeholder="Enter profile_image" value="{{ old('profile_image', $member->profile_image ?? '') }}">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="docs">Docs</label>
                                                <input type="file" id="docs" multiple name="docs[]" class="form-control" placeholder="Enter docs" value="{{ old('docs', $member->docs ?? '') }}">
                                            </div>
                                        </div>

                                        {{-- <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="reason">Reason</label>
                                                <select name="reason_id" class="form-control" id="reason">
                                                    <option value="">Select Reason</option>
                                                    @foreach ($reasons as $reasonkey => $reason)
                                                        <option {{$member->reason_id==$reasonkey? "selected":""}} value="{{$reasonkey}}">{{$reason}}</option>
                                                    @endforeach
                                                </select>

                                            </div>
                                        </div> --}}


                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="nature">Nature</label>
                                                <select  name="nature_id" class="form-control" id="nature">
                                                    <option value="">Select Nature</option>
                                                    @foreach ($natures as $naturekey => $nature)
                                                        <option {{$member->nature_id==$naturekey? "selected":""}} value="{{$naturekey}}">{{$nature}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="ip_address">IP Address</label>
                                                <input type="text" id="ip_address" name="ip_address" class="form-control" placeholder="Enter ip_address" readonly value="{{ old('ip_address', $member->ip_address ?? '') }}">
                                            </div>
                                        </div>



                                    </div>



                                    <div id="director_details">
                                    @if(!empty($directors))
@foreach ($directors as $key => $director)
<div class="row director-row">
    <div class="col-sm-12">
        <div class="form-group">
            <label class="director-label"><b>Director Detail</b></label>
        </div>
    </div>
    <div class="col-sm-6">
        <div class="form-group">
            <label for="director_name">Director Name</label>
            <input type="text" name="director_name[]" value="{{$director->director_name ?? ''}}" class="form-control"
                placeholder="Enter director Name"
                value="{{ old('director_name[]') }}">
        </div>

    </div>
    <div class="col-sm-6">
        <div class="form-group">
            <label for="director_dob">Director DOB</label>
            <input type="date" name="director_dob[]" value="{{$director->director_dob ?? ''}}" class="form-control"
                placeholder="Enter director DOB"
                value="{{ old('director_dob[]') }}">
        </div>
    </div>

    <div class="col-sm-6">
        <div class="form-group">
            <label for="director_address">Director Address</label>
            <input type="text" id="director_address" value="{{$director->director_address ?? ''}}" name="director_address[]"
                class="form-control" placeholder="Enter Director Address"
                value="{{ old('director_address') }}">
        </div>
    </div>
    <div class="col-sm-6">
        <div class="form-group">
            <label for="director_address_line_two">Director Address Line
                Two</label>
            <input type="text" id="director_address_line_two" value="{{$director->director_address_line_two ?? ''}}"
                name="director_address_line_two[]" class="form-control"
                placeholder="Enter Director Address Line two"
                value="{{ old('director_address_line_two') }}">
        </div>
    </div>
    <div class="col-sm-5">
        <div class="form-group">
            <label for="director_post_code">Director Address Post Code</label>
            <input type="text" id="director_post_code" value="{{$director->director_post_code ?? ''}}"
                name="director_post_code[]" class="form-control"
                placeholder="Enter Director Address Post Code"
                value="{{ old('director_post_code') }}">
        </div>
    </div>
</div>
@endforeach
@else

<div class="row director-row">
                                            <div class="col-sm-12">
                                                <div class="form-group">
                                                    <label class="director-label"><b>Director Detail</b></label>
                                                </div>
                                            </div>
                                            <div class="col-sm-6">

                                                <div class="form-group">
                                                    <label for="director_name">Director Name</label>
                                                    <input type="text" name="director_name[]" class="form-control"
                                                        placeholder="Enter director Name"
                                                        value="{{ old('director_name[]') }}">
                                                </div>

                                            </div>
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label for="director_dob">Director DOB</label>
                                                    <input type="date" name="director_dob[]" class="form-control"
                                                        placeholder="Enter director DOB"
                                                        value="{{ old('director_dob[]') }}">
                                                </div>
                                            </div>

                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label for="director_address">Director Address</label>
                                                    <input type="text" id="director_address" name="director_address[]"
                                                        class="form-control" placeholder="Enter Director Address"
                                                        value="{{ old('director_address') }}">
                                                </div>
                                            </div>
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label for="director_address_line_two">Director Address Line
                                                        Two</label>
                                                    <input type="text" id="director_address_line_two"
                                                        name="director_address_line_two[]" class="form-control"
                                                        placeholder="Enter Director Address Line two"
                                                        value="{{ old('director_address_line_two') }}">
                                                </div>
                                            </div>
                                            <div class="col-sm-5">
                                                <div class="form-group">
                                                    <label for="director_post_code">Director Address Post Code</label>
                                                    <input type="text" id="director_post_code"
                                                        name="director_post_code[]" class="form-control"
                                                        placeholder="Enter Director Address Post Code"
                                                        value="{{ old('director_post_code') }}">
                                                </div>

                                            </div>


                                        </div>
@endif
</div>

                                    <div class="col-sm-12 d-flex justify-content-end" style="margin-bottom: 5rem;">
                                        <a href="#!" for="director_post_code" style="font-size: 15px;" id="add_more"><b>Add
                                                More +</b></a>
                                    </div>



                                    <div id="comment_box">
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <label class="comment-label"><b>Comments</b></label>
                                            </div>
                                        </div>
                                    @if(!empty($comments))
                                    @foreach ($comments as $key => $comment)
                                    <div class="row comment-row">
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <input type="text" name="comment[]" value="{{$comment->comment}}" class="form-control"
                                                    placeholder="Enter Comment" value="{{ old('comment[]') }}">
                                            </div>
                                        </div>
                                    </div>
                                    @endforeach
                                    @else
                                    <div class="row comment-row">
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <input type="text" name="comment[]" class="form-control"
                                                    placeholder="Enter Comment" value="{{ old('comment[]') }}">
                                            </div>
                                        </div>
                                    </div>
                                    @endif
                                </div>

                                    <div class="col-sm-12 d-flex justify-content-end">
                                        <a href="#!" for="director_post_code" style="font-size: 15px;"
                                            id="add_more_comment"><b>Add More +</b></a>
                                    </div>

                                    <div class="col-sm-12">
                                        <div class="form-group">
                                            <div class="custom-control custom-checkbox mr-sm-2 m-b-15">
                                                <input type="checkbox" class="custom-control-input" name="status" id="is_active" value="1"
                                                    {{ old('status', $member->status ?? 0) == 1 ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="is_active">Is Active</label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-sm-12">
                                        <div class="form-group">
                                            <div class="custom-control custom-checkbox mr-sm-2 m-b-15">
                                                <input type="checkbox" class="custom-control-input" name="pause_unpause_status" id="is_pause" value="1"
                                                    {{ old('pause_unpause_status', $member->pause_unpause_status ?? 0) == 1 ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="is_pause">Is Pause</label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-sm-12">
                                        <div class="form-group">
                                            <div class="custom-control custom-checkbox mr-sm-2 m-b-15">
                                                <input type="checkbox" class="custom-control-input" name="suspend_status" id="checkbox_suspend" value="1"
                                                    {{ old('suspend_unsuspend_status', $member->suspend_unsuspend_status ?? 0) == 1 ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="checkbox_suspend">Is Suspend</label>
                                            </div>
                                        </div>
                                    </div>

                                    {{-- <div class="col-sm-12">
                                        <div class="form-group">
                                            <div class="custom-control custom-checkbox mr-sm-2 m-b-15">
                                                <input type="checkbox" class="custom-control-input" name="permanent_active_action" id="checkbox_permanent_active" value="1"
                                                    {{ old('permanent_active_action', $member->permanent_active_action ?? 0) == 1 ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="checkbox_permanent_active">Permanent Active</label>
                                            </div>
                                        </div>
                                    </div> --}}

                                    <div class="col-sm-12">
                                        <div class="form-group">
                                            <div class="custom-control custom-checkbox mr-sm-2 m-b-15">
                                                <input type="checkbox" class="custom-control-input" name="permanent_distribution_member" id="checkbox_permanent_distribution" value="1"
                                                    {{ old('permanent_distribution_member', $member->permanent_distribution_member ?? 0) == 1 ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="checkbox_permanent_distribution">Golden Member (PDF)</label>
                                            </div>
                                        </div>
                                    </div>





                                    <div class="col-sm-12">
                                        <button type="submit" class="btn btn-primary">Save</button>
                                        <a href="{{ route('member') }}" class="btn btn-secondary">Back</a>
                                    </div>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
        </div>
        </section>
    </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            let count = 1;
            $("#add_more").click(function() {
                count++;
                var newRow = $(".director-row:first").clone(); //first row clone
                newRow.find("input").val(""); // clear all input fields
                // newRow.find(".director-label").html("<b>Director Details " + count + "</b>");

                newRow.append(
                    '<div class="col-sm-1 d-flex justify-content-center align-items-center"><span class="remove-btn">❌</span></div>'
                )


                $("#director_details").append(newRow); // add new row
            });



            $(document).on("click", ".remove-btn", function() {
                if ($(".director-row").length > 1) {
                    $(this).closest(".director-row").remove();
                } else {
                    alert("At least one row is required!");
                }
            });

            //comment
            $("#add_more_comment").click(function() {
                count++;


                var newRow = $(".comment-row:first").clone(); //first row clone
                newRow.find("input").val(""); // clear all input fields
                // newRow.find(".director-label").html("<b>Director Details " + count + "</b>");

                newRow.append(
                    '<div class="col-sm-1 d-flex justify-content-center align-items-center"><span class="remove-comment-btn">❌</span></div>'
                )


                $("#comment_box").append(newRow); // add new row
            });

            $(document).on("click", ".remove-comment-btn", function() {
                if ($(".comment-row").length > 1) {
                    $(this).closest(".comment-row").remove();
                } else {
                    alert("At least one row is required!");
                }
            });

            // $(document).on("click", "#is_active", function(){

            // });

            // $(document).on("click", "#is_pause", function(){

            // });

            // $(document).on("click", "#checkbox_suspend", function(){

            // });

            $(document).ready(function() {
                $.validator.addMethod("regex", function(value, element, regexp) {
                    var re = new RegExp(regexp);
                    return this.optional(element) || re.test(value);
                }, "Please enter a valid email address.");

                $.validator.addMethod("strongPassword", function(value, element) {
                        return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
                            .test(value);
                    },
                    "Password must contain at least one uppercase letter, one lowercase letter, one numeric digit, one special character, and be at least 8 characters long."
                );

                $.validator.addMethod("noOnlySpaces", function(value, element) {
                    return $.trim(value).length !== 0;
                }, "Please enter a value other than spaces.");


                $.validator.addMethod("validEmail", function(value, element) {
                    // Regular expression for validating an email address
                    var emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
                    return this.optional(element) || emailPattern.test(value);
                }, "Please enter a valid email address.");

                $.validator.addMethod("minAge", function(value, element, minAge) {
                    var today = new Date();
                    var birthDate = new Date(value);
                    var age = today.getFullYear() - birthDate.getFullYear();
                    var m = today.getMonth() - birthDate.getMonth();
                    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
                        age--;
                    }
                    return this.optional(element) || age >= minAge;
                }, "You must be at least 14 years old.");

                $('#member_form').validate({
                    rules: {
                        business_name: {
                            required: true,
                            maxlength: 20,
                            noOnlySpaces: true
                        },
                        person_significate_control: {
                            required: true,
                            maxlength: 20,
                            noOnlySpaces: true
                        },
                        email: {
                            required: true,
                            email: true,
                            validEmail: true,
                            // remote: {
                            //     url: "{{ route('member.checkEmail') }}",
                            //     type: "get",
                            //     data: {
                            //         email: function() {
                            //             return $("#email").val();
                            //         }
                            //     }
                            // }
                        },
                        mobile_number: {
                            required: true,
                            minlength: 11,
                            maxlength: 11,
                            noOnlySpaces: true,
                            number: true
                        },
                        second_mobile_number: {
                            required: true,
                            minlength: 11,
                            maxlength: 11,
                            noOnlySpaces: true,
                            number: true
                        },
                        business_address: {
                            required: true,
                            noOnlySpaces: true,
                            maxlength: 150,

                        },
                        business_address_line_two: {
                            maxlength: 150,
                        },
                        business_post_code: {
                            required: true,
                            maxlength: 8,
                            noOnlySpaces: true,
                            minlength: 6
                        },
                        business_area_code: {
                            required: true,
                            noOnlySpaces: true,
                            maxlength: 2,
                            minlength: 1
                        },
                        business_district_code: {
                            required: true,
                            noOnlySpaces: true,
                            maxlength: 4,
                        },
                        company_name: {
                            required: true,
                            maxlength: 20,
                            noOnlySpaces: true
                        },
                        company_number: {
                            required: true,
                            maxlength: 8,
                            minlength: 6,
                            noOnlySpaces: true
                        },
                        company_address: {
                            required: true,
                            noOnlySpaces: true,
                            maxlength: 150,
                        },
                        company_address_line_two: {
                            maxlength: 150,
                        },
                        company_post_code: {
                            required: true,
                            maxlength: 8,
                            minlength: 6
                        },
                        balance: {
                            required: true,
                            number: true,
                            min: 0
                        },
                        minimum_account_balance: {
                            required: false,
                            number: true,
                            min: 0
                        },
                        // profile_image: {
                        //     required: false,
                        //     extension: "jpg|jpeg|png|gif"
                        // },

                        "director_name[]": {
                            required: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_name[]"]').val() !== "";
                            },
                            noOnlySpaces: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_name[]"]').val() !== "";
                            }
                        },
                        "director_dob[]": {
                            required: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_dob[]"]').val() !== "";
                            },
                            noOnlySpaces: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_dob[]"]').val() !== "";
                            }
                        },
                        "director_address[]": {
                            required: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_address[]"]').val() !== "";
                            },
                            noOnlySpaces: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_address[]"]').val() !== "";
                            }
                        },
                        "director_post_code[]": {
                            required: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_post_code[]"]').val() !== "";
                            },
                            noOnlySpaces: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_post_code[]"]').val() !== "";
                            }
                        },
                        "comment[]": {
                            required: function() {
                                return $(this).closest(".comment-row").find(
                                    'input[name="comment[]"]').val() !== "";
                            },
                            noOnlySpaces: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="comment[]"]').val() !== "";
                            }
                        }
                    },
                    messages:{
        business_name: {
            required: "Business Name is required.",
            maxlength: "Business Name cannot exceed 20 characters."
        },
        name: {
            required: "Name is required.",
            maxlength: "Name cannot exceed 20 characters."
        },
        person_significate_control: {
            required: "Person Significate Control is required.",
            maxlength: "Person Significate Control cannot exceed 20 characters."
        },
        email: {
            required: "Email is required.",
            email: "Please enter a valid email address.",
            maxlength: "Email cannot exceed 50 characters."
        },
        mobile_number: {
            required: "Mobile Number is required.",
            minlength: "Mobile Number must be 11 digits.",
            maxlength: "Mobile Number must be 11 digits."
        },
        second_mobile_number: {
            required: "Second Mobile Number is required.",
            minlength: "Second Mobile Number must be 11 digits.",
            maxlength: "Second Mobile Number must be 11 digits."
        },
        business_address: {
            required: "Business Address is required.",
            maxlength: "Business Address cannot exceed 150 characters."
        },
        business_address_line_two: {
            maxlength: "Business Address Line Two cannot exceed 150 characters."
        },
        business_post_code: {
            required: "Business Post Code is required.",
            maxlength: "Business Post Code cannot exceed 8 characters.",
            minlength: "Business Post Code must be at least 6 characters."
        },
        business_area_code: {
            required: "Business Code is required.",
            maxlength: "Business Code cannot exceed 2 characters.",
            minlength: "Business Code must be at least 1 character."
        },
        business_district_code: {
            required: "Business District Code is required.",
            maxlength: "Business District Code cannot exceed 4 characters."
        },
        company_name: {
            required: "Company Name is required.",
            maxlength: "Company Name cannot exceed 20 characters."
        },
        company_number: {
            required: "Company Number is required.",
            maxlength: "Company Number cannot exceed 8 characters.",
            minlength: "Company Number must be at least 6 characters."
        },
        company_address: {
            required: "Company Address is required.",
            maxlength: "Company Address cannot exceed 150 characters."
        },
        company_address_line_two: {
            maxlength: "Company Address Line Two cannot exceed 150 characters."
        },
        company_post_code: {
            required: "Company Post Code is required.",
            maxlength: "Company Post Code cannot exceed 8 characters.",
            minlength: "Company Post Code must be at least 6 characters."
        }
                    },
                    errorElement: "div",
                    errorPlacement: function(error, element) {
                        error.addClass("invalid-feedback");
                        element.closest(".form-group").append(error);
                    },
                    highlight: function(element, errorClass, validClass) {
                        $(element).addClass("is-invalid").removeClass("is-valid");
                    },
                    unhighlight: function(element, errorClass, validClass) {
                        $(element).removeClass("is-invalid");
                        // addClass("is-valid").
                    },
                    submitHandler: function(form) {
                        console.log(form);

                        form.submit();
                    }
                });

                $('.toggle-password').click(function() {
                    var passwordInput = $(this).closest('.form-group').find('.password-toggle');
                    var passwordIcon = $(this).find('i');

                    if (passwordInput.attr('type') === 'password') {
                        passwordInput.attr('type', 'text');
                        passwordIcon.removeClass('fa-eye').addClass('fa-eye-slash');
                    } else {
                        passwordInput.attr('type', 'password');
                        passwordIcon.removeClass('fa-eye-slash').addClass('fa-eye');
                    }
                });

                // Set the min and max date for dob
                var today = new Date();
                var minDate = new Date(today.getFullYear() - 100, today.getMonth(), today.getDate());
                var maxDate = new Date(today.getFullYear() - 14, today.getMonth(), today.getDate());

                $('#dob').attr('min', minDate.toISOString().split('T')[0]);
                $('#dob').attr('max', maxDate.toISOString().split('T')[0]);
            });



        });
    </script>

@stop
