@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">
                                    <!-- Show all validation errors at the top -->
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
                                <form id="member_form" action="{{ route('member.updates',$member->id) }}" method="POST" enctype="multipart/form-data">
                                    @csrf
                                    <div class="row">

                                        <div class="col-sm-12">
                                            <h4><b>Business Details</b></h4>
                                        </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="landline_name">Landline Number<span
                                                        style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="landline_number" name="landline_number"
                                                    class="form-control" placeholder="Enter Landline Number"
                                                    value="{{ old('landline_number',$member->landline_number ?? '') }}">
                                            </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_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="business_area_id">Business Name<span
                                                        style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <select name="business_area_id" class="form-control"
                                                    id="business_area_id">
                                                    <option value="">Select Area</option>
                                                    @foreach ($areas as $areaCode => $area)
                                                        <option  {{$member->business_area_id == $area->id ? 'selected':''}} 
                                                         value="{{  $area->id }}"> {{ $area->code . ' (' . $area->name . ') ' }}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>

                                         <div class="col-sm-12">
                                            <h4><b>Lead Recepiant Details</b></h4>
                                        </div>


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


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


                                        <div class="col-sm-12">
                                            <h4><b>PSC Details</b></h4>
                                        </div>




                                        
                                        <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="person_significate_control">PSC DOB
                                                    (PSC)<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="date" id="psc_dob" name="psc_dob" class="form-control"
                                                    value="{{ old('psc_dob',$member->psc_dob) }}">
                                            </div>
                                        </div>

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

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="psc_home_address">PSC Home Address<span
                                                        style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="psc_home_address" name="psc_home_address"
                                                    class="form-control" placeholder="Enter PSC Home Address"
                                                    value="{{ old('psc_home_address',$member->psc_home_address) }}">
                                            </div>
                                        </div>
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="psc_address_line_two">PSC Home Address line Two</label>
                                                <input type="text" id="psc_address_line_two"
                                                    name="psc_home_address_line_two" class="form-control"
                                                    placeholder="Enter PSC Home Address Line two"
                                                    value="{{ old('psc_address_line_two',$member->psc_address_line_two) }}">
                                            </div>
                                        </div>

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

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

                                                                          <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="leads_per_day">Leads Per Day<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="number" id="leads_per_day" name="leads_per_day" class="form-control" placeholder="Enter Minimum Account Balance" value="{{ old('leads_per_day', $member->leads_per_day ?? '') }}">
                                            </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="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="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="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="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 == $area->code ? 'selected' : '' }} value="{{ $area->code }}">{{ $area->code." (". $area->name .") "}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div> --}}

                                       
    <div class="col-sm-12 mt-3 mb-1">
                                            <h4><b>Limited Company Details</b></h4>
                                        </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_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_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_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_vat_number">Company VAT Number<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                <input type="text" id="company_vat_number" name="company_vat_number" class="form-control" placeholder="Enter Company Number" value="{{ old('company_vat_number', $member->company_vat_number ?? '') }}">
                                            </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="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="docs">Docs</label>
                                                <input type="file" accept=".pdf, .docx, .txt, .odt" id="docs" multiple name="docs[]" class="form-control" placeholder="Enter docs">
                                                <small>Note:Only PDF, DOCX, TXT, and ODT files are allowed.</small>
                                            </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="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><span class="director-no">{{ $key + 1 }}</span>. Director Detail</b></label>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label for="director_name">Director Name<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                        <input type="text" name="director_name[]" class="form-control" placeholder="Enter director Name" value="{{ old('director_name.' . $loop->index, $director->director_name ?? '') }}">

                                                    </div>

                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label for="director_dob">Director DOB<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                        <input type="date" name="director_dob[]"  class="form-control" placeholder="Enter director DOB" value="{{ old('director_dob.' . $loop->index, $director->director_dob ?? '') }}">

                                                    </div>
                                                </div>

                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label for="director_nin_number">Director NIN Number<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                        <input type="text" id="director_nin_number"  name="director_nin_number[]" class="form-control"  placeholder="Enter Director NIN Number" value="{{ old('director_nin_number.' . $loop->index, $director->director_nin_number ?? '') }}">

                                                    </div>
                                                </div>

                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label for="director_address">Director Address<span style="color: red;font-size:18px;"><b>*</b></span></label>
                                                        <input type="text" id="director_address"  name="director_address[]" class="form-control"  placeholder="Enter Director Address" value="{{ old('director_address.' . $loop->index, $director->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.' . $loop->index, $director->director_address_line_two ?? '') }}">
                                                    </div>
                                                </div>
                                                <div class="col-sm-5">
                                                    <div class="form-group">
                                                        <label for="director_post_code">Director Address Post Code<span style="color: red;font-size:18px;"><b>*</b></span></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.' . $loop->index, $director->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>1. 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">
                                            <label for="director_address_line_two">Additional Information</label>
                                            <textarea name="additional_information" class="form-control" id="additional_information">{{$member->additional_information?? ''}}</textarea>
                                        </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_unsuspend_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
                updateDirectorNumbers();
            });



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

              // Function to update the director numbers
              function updateDirectorNumbers() {
                $(".director-row").each(function (index) {
                    $(this).find(".director-no").text(index + 1);
                });
            }


            //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.");


                $.validator.addMethod("dobValidation", function(value, element) {
                    if (!value) return false; // Ensure field is not empty
                    var selectedDate = new Date(value);
                    var today = new Date();
                    today.setHours(0, 0, 0, 0); // Reset time to avoid mismatch

                    return selectedDate <= today; // DOB should not be in the past
                }, "Date of Birth cannot be in the future.");

                $.validator.addMethod("validateFile", function(value, element) {
                    // Allowed file extensions for images
                    var fileExtension = ['jpg', 'jpeg', 'png'];

                    // Check if a file is selected
                    if (element.files && element.files.length > 0) {
                        // Extract the file extension from the selected file
                        var file = element.files[0];
                        var extension = file.name.split('.').pop()
                    .toLowerCase(); // Get the file extension

                        // Check if the extension is in the allowed list
                        return ($.inArray(extension, fileExtension) != -1);
                    }
                    return true; // If no file is selected, allow it (optional)
                }, "Please select a valid image file (JPG, JPEG, or PNG are allowed)");


                $.validator.addMethod("fileExtension", function(value, element, param) {
                    // Get the file list
                    const files = element.files;

                    // Allowed file types (can modify as needed)
                    const allowedTypes = ['pdf', 'docx', 'txt', 'odt'];

                    // Check each file extension
                    for (let i = 0; i < files.length; i++) {
                        const file = files[i];
                        const fileExtension = file.name.split('.').pop().toLowerCase();

                        if (!allowedTypes.includes(fileExtension)) {
                            return false;
                        }
                    }

                    return true;
                }, "Only PDF, DOCX, TXT, and ODT files are allowed.");

                $('#member_form').validate({
                    rules: {
                        business_name: {
                            required: true,
                            maxlength: 20,
                            noOnlySpaces: true
                        },
                            landline_number: {
                                required: false,
                                number: true,
                                minlength: 10,
                                maxlength: 15
                            },
                            leads_recepiant_email_address: {
                                required: true,
                                email: true,
                                maxlength: 50

                            },
                            message_recepiant_mobile_number: {
                                required: true,
                                number: true,
                                minlength: 11,
                                maxlength: 11
                            },
                            psc_dob: {
                                required: true,
                                dobValidation: true
                                
                            },
                            psc_nin_number: {
                                required: true,
                                maxlength: 10,
                                noOnlySpaces: true

                            },
                            psc_home_address: {
                                required: true,
                                maxlength: 150,
                                noOnlySpaces: true

                            },
                            psc_home_address_line_two: {
                                maxlength: 150

                            },
                            psc_post_code: {
                                required: true,
                                maxlength: 8,
                                minlength: 6,
                                noOnlySpaces: true

                            },
                            psc_mobile_number: {
                                required: true,
                                number: true,
                                minlength: 11,
                                maxlength: 11

                            },
                            leads_per_day: {
                                required: true,
                                number: true,
                                min: 0
                            },  
                            director_mobile_number: {
                                required: true,
                                number: true,
                                minlength: 11,
                                maxlength: 11
                            },
                        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: 25,

                        },
                        business_address_line_two: {
                            maxlength: 25,
                        },
                        business_post_code: {
                            required: true,
                            maxlength: 8,
                            noOnlySpaces: true,
                            minlength: 6
                        },
                        // business_area_code: {
                        //     required: true,
                        //     noOnlySpaces: true,
                        //     maxlength: 2,
                        //     minlength: 1
                        // },
                        business_area_id: {
                            required: true
                        },
                        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_vat_number:{
                            required: true,
                            number: true,
                            maxlength: 40,
                            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
                        },
                        leads_per_day: {
                            required: true,
                            number: true,
                            min: 0
                        },
                        minimum_account_balance: {
                            required: false,
                            number: true,
                            min: 0
                        },
                        profile_image: {
                            validateFile: true
                        },
                        "docs[]": {
                            fileExtension: true
                        },

                        "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() !== "";
                            },
                            maxlength:20
                        },
                        "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_nin_number[]": {
                            required: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_nin_number[]"]').val() !== "";
                            },
                            noOnlySpaces: function() {
                                return $(this).closest(".director-row").find(
                                    'input[name="director_nin_number[]"]').val() !== "";
                            },
                            maxlength:8
                        },
                        "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() !== "";
                            },
                            maxlength:25
                        },
                        "director_address_line_two[]": {
                            maxlength:25
                        },
                        "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() !== "";
                            },
                            maxlength: 8,
                            minlength: 6,
                        },
                        // "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 25 characters."
        },
        business_address_line_two: {
            maxlength: "Business Address Line Two cannot exceed 25 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_area_id: {
            required: "Business Area Id is required.",
        },
        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."
        },
                        'director_post_code[]':{
                            maxlength: "Director Post Code cannot exceed 8 characters.",
                            minlength: "Director 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
