@extends('layouts.admin')
@section('content')

    @php
        $user_access_end_date = '';
        if(!empty($user['data']['user_access_end_date'])){
            $user_access_end_date  = getStringToDate($user['data']['user_access_end_date'],'m/d/Y');
          }
        $inputData['subscription_status'] = $user['data']['subscription_status'];
        $inputData['status'] = $user['data']['status'];
        $inputData['is_import'] = $user['data']['is_import'];
        $waves = clientWaves(config('constant.MAX_WAVE'));
    @endphp

    <div class="row">
        <div class="col-xs-12 col-sm-12 column col-sm-offset-0">
            <div class="panel panel-default panel-frm">

                <div class="panel-heading">
                    <div class="row" style="padding-left: 20px;padding-right: 15px">
                        <h3 class="pull-left">Account Info Of {{$user['data']['first_name'].' '.$user['data']['last_name']}}</h3>
                        <form method="post" action="{{route('update.client.id')}}"
                              autocomplete="off"
                              class="input-form-section" id="client_activate_form">
                            @csrf
                            <input type="hidden" name="client_id" value="{{$user['data']['id']}}">
                            @if(getClientStatus($user['data']))
                                <div class="pull-right">
                                    <input type="hidden" name="type" value="1">
                                    <input class="btn btn-success btn2" type="submit" onclick="return client_activate(this)" value="Active">
                                </div>
                            @else
                                <div class="pull-right">
                                    <input type="hidden" name="type" value="2">
                                    <input class="btn btn-success btn2" type="submit" onclick="return client_activate(this)" value="Reset Credit Report">
                                </div>
                            @endif
{{--                            @if(getEnableImportReset($inputData))--}}


{{--                            @endif--}}
                        </form>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="clearfix"></div>
                    <div class="row">
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            <div class="x_panel">
                                <form method="post" action="{{route('update.client')}}" id="client_form"
                                      autocomplete="off"
                                      class="input-form-section">
                                    @csrf
                                    <input type="hidden" name="id" value="{{$user['data']['id']}}">
                                    <input type="hidden" name="previous_email" value="{{$user['data']['email']}}">
                                    <div class="x_content">
                                        <div class="row">
                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="firstname">First Name</label>
                                                    <input class="form-control" name="first_name" type="text" placeholder="First Name"
                                                           value="{{$user['data']['first_name']}}" id="firstname">
                                                </div>
                                            </div>

                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="Last Name">Last Name</label>
                                                    <input class="form-control" name="last_name" type="text" placeholder="Last Name"
                                                           value="{{$user['data']['last_name']}}" id="lastname">
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row">
                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="Phone">Phone</label>
                                                    <input class="form-control" name="phone" type="text" placeholder="Phone"
                                                           value="{{$user['data']['phone']}}" id="phone">
                                                </div>
                                            </div>

                                            <div class="col-md-6  col-xs-12">
                                                <div class="form-group">
                                                    <label for="Street Number">Street Number</label>
                                                    <input class="form-control" name="street_no" type="text" placeholder="Street Number"
                                                           value="{{$user['data']['street_no']}}" id="street_no">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="Street Name">Street Name</label>
                                                    <input class="form-control" name="street_name" type="text" placeholder="Street Name"
                                                           value="{{$user['data']['street_name']}}"
                                                           id="street_name">
                                                </div>
                                            </div>

                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="City">City</label>
                                                    <input class="form-control" name="city" type="text" placeholder="City"
                                                           value="{{$user['data']['city']}}" id="city">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="State">State</label>
                                                    <input class="form-control" name="state" type="text" placeholder="State"
                                                           value="{{$user['data']['state']}}" id="state">
                                                </div>
                                            </div>
                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="zip">Zip</label>
                                                    <input class="form-control" name="zip_code" type="text" placeholder="Zip Code"
                                                           value="{{$user['data']['zip_code']}}" id="zip_code">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6  col-xs-12">
                                                <div class="form-group">
                                                    <label for="email">Email</label>
                                                    <input class="form-control" name="email" placeholder="Email"
                                                           type="text"
                                                           value="{{$user['data']['email']}}" id="email">
                                                </div>
                                            </div>

                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="password">Password</label>
                                                    <div class="input-group" id="client_show_hide_password">
                                                        <input class="form-control" name="password"
                                                               type="password" placeholder="Password"
                                                               value="{{customDecrypt($user['data']['password'])}}"
                                                               id="password">
                                                        <div class="input-group-addon">
                                                            <a href=""><i class="fa fa-eye-slash"
                                                                          aria-hidden="true"></i></a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6  col-xs-12">
                                                <div class="form-group">
                                                    <label for="Status">Status</label>

                                                    <select name="status" class="form-control">

                                                        <option
                                                            value="1" {{ $user['data']['status'] == 1 ? 'selected' : '' }}>
                                                            Active
                                                        </option>
                                                        <option
                                                            value="2" {{ $user['data']['status'] == 2 ? 'selected' : '' }}>
                                                            Inactive
                                                        </option>
                                                        <option
                                                            value="2" {{ $user['data']['subscription_status'] == 2 ? 'selected' : '' }}>
                                                            Canceled
                                                        </option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <label for="month">Last Access Date</label>
                                                    <input class="form-control" name="user_access_end_date" disabled value="{{$user['data']['user_access_end_date']}}" type="text" >
                                                </div>
                                            </div>

                                        </div>
                                        <div class="row">
                                            <div class="col-md-6 col-xs-12" id="user_access_date_div">
                                                <div class="form-group">
                                                    <label for="month">Free Access Date</label>
                                                    <input class="form-control" name="user_access_date" readonly  id="user_access_end_date" type="text" value="{{$user_access_end_date}}" placeholder="mm/dd/yyyy">
                                                </div>
                                            </div>

                                            <div class="col-md-6 col-xs-12">
                                                <div class="form-group">
                                                    <div class="form-group col-md-6 col-xs-12 text-left" >
                                                        <input class="form-check-input" type="checkbox" name="change_wave"
                                                               value="1" id="change_wave">
                                                        <label class="form-check-label" data-toggle="tooltip" data-placement="right" title="">
                                                            Unlock Wave
                                                        </label>
                                                    </div>
                                                    <select name="wave" class="form-control" onchange="getDecision(this)" id="wave">
                                                        @foreach($waves as $key => $value)
                                                            @php $select = ($value['key'] == $user['data']['wave']) ? 'selected': ''; @endphp
                                                            <option value="{{$value['key']}}" {{$select}}> {{$value['text']}} </option>
                                                        @endforeach

                                                    </select>
{{--                                                    <input class="form-control" name="wave" type="text" value="{{$user['data']['wave']}}" >--}}

                                                </div>
                                            </div>

                                        </div>
                                        <div class="row">
                                            <div class="form-group col-md-6 col-xs-12 text-left" >
                                                <input class="form-check-input" type="checkbox" name="report_provider_info"
                                                       value="1" id="report_provider_info">
                                                <label class="form-check-label" data-toggle="tooltip" data-placement="right" title="">
                                                    Credit Report Provider Information
                                                </label>
                                            </div>
                                        </div>
                                        <div class="row" id="credit_report_info">
                                         <div class="col-md-12">
                                            <div class="row">
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="birth_date">Date of Birth</label>
                                                        <input class="form-control" name="birth_date" id="birth_date" type="text"
                                                               value="{{$user['data']['birth_date']}}"  placeholder="mm/dd/yyyy">
                                                    </div>
                                                </div>

                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="ssn">Social Security Number</label>
                                                        <input class="form-control" name="ssn"
                                                               type="text" maxlength="4"
                                                               value="{{$user['data']['ssn']}}"
                                                               placeholder="Last 4 digit of ssn"
                                                               id="ssn">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="">Source Type</label>
                                                        @php
                                                            $source_types = config('constant.sourceType');
                                                        @endphp
                                                        <select name="source_type"  class="form-control">
                                                            @foreach($source_types as  $key=>$value)
                                                                <option value="{{$value}}" {{$user['data']['credit_report_company_type'] == $value ? 'selected':''}}> {{$key}}</option>
                                                            @endforeach
                                                        </select>
                                                    </div>
                                                </div>

                                               @if(isSupport())
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="month">Previous Import Date</label>
                                                        <input class="form-control" name="last_import_date" readonly  id="last_import_date" type="text" value="{{$user['data']['last_import_date']}}" placeholder="mm/dd/yyyy">
                                                    </div>
                                                </div>
                                                @endif
                                            </div>
                                         </div>
                                        </div>

                                    </div>
                                    @if(isShowContent('update.client'))
                                        <div class="col-sm-12 center" style="margin-top: 10px; text-align: center; ">
                                            <input class="btn btn-success btn2" type="submit"  onclick="return client_form_submit(this)"   value="Save Changes">
                                        </div>
                                    @endif
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="common_confirmation_modal" style="margin-top: 50px" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-md" id="modal-dialog-panel">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                <div class="modal-body">
                    <h4 class="mb-2 text-center" style="color: red" id="common_message_text">

                    </h4>
                </div>
                <div class="modal-footer" style="text-align: center">
                    <button type="button" class="btn btn-secondary btn-lg" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

@endsection

@push('script')

    <script>

        $(document).ready(function() {
                common_helper.datePicker('#user_access_end_date','mm/dd/yyyy',false,new Date(new Date().setDate(new Date().getDate() + 1)),null);
                common_helper.datePicker('#last_import_date','mm/dd/yyyy',true,null);
                common_helper.datePicker('#birth_date','mm/dd/yyyy',true,null);
                $('#wave').prop('disabled', true);

        });

        const client_form_submit =(e)=>{
            var data = $('#report_provider_info').prop("checked");

            if(data) {
                $('#client_form').validate({

                    rules: {
                        'first_name': 'required',
                        'last_name': 'required',
                        'email': 'required',
                        'password': 'required',
                        'birth_date': 'required',
                        'street_no': 'required',
                        'street_name': 'required',
                        'city': 'required',
                        'state': 'required',
                        'zip_code': 'required',
                        'phone': 'required',
                        'ssn': 'required',
                        'source_type': 'required',
                    },

                    messages: {
                        'first_name': {
                            required: "Please enter  first name"
                        },
                        'last_name': {
                            required: "Please enter  last name"
                        }, 'email': {
                            required: "Please enter  email"
                        }, 'password': {
                            required: "Please enter password"
                        },
                        'birth_date': {
                            required: "Please enter  birth date",
                        },
                        'street_no': {
                            required: "Please enter  street number"
                        },
                        'street_name': {
                            required: "Please enter  street name"
                        },
                        'state': {
                            required: "Please enter state"
                        },
                        'city': {
                            required: "Please enter  city"
                        },
                        'zip_code': {
                            required: "Please enter  zip code"
                        },
                        'phone': {
                            required: "Please enter  phone number"
                        },
                        'ssn': {
                            required: "Please enter last 4 digit of ssn"
                        },
                        'source_type': {
                            required: "Please enter source type"
                        },

                    },

                    highlight: function (element) {
                        $(element).parent().addClass("has-error");
                    },

                });
                if ($('#client_form').valid()) {
                    let url = '{{ route('admin.ajax.get.process') }}';
                    let previous_email = $('[name="previous_email"]').val();
                    let email = $('#client_form').find('input[name=email]').val();
                    let password = $('[name="password"]').val();
                    let source_type = $('[name="source_type"]').val();
                    let ssn = $('[name="ssn"]').val();
                    let data = {
                        action: 'GET_SUBSCRIPTION_STATUS_CREDIT_REPORT_PROVIDER',
                        email: email,
                        password: password,
                        previous_email: previous_email,
                        source_type: source_type,
                        ssn: ssn
                    };
                    common_helper.globalAjaxRequestAsync(url, 'POST', data, callbackfromreportprovider);
                }
                return false;
            }else {
                $('#client_form').validate({

                    rules: {
                        'first_name': 'required',
                        'last_name': 'required',
                        'email': 'required',
                        'password': 'required',
                        'street_no': 'required',
                        'street_name': 'required',
                        'city': 'required',
                        'state': 'required',
                        'zip_code': 'required',
                        'phone': 'required'
                    },

                    messages: {
                        'first_name': {
                            required: "Please enter  first name"
                        },
                        'last_name': {
                            required: "Please enter  last name"
                        }, 'email': {
                            required: "Please enter  email"
                        }, 'password': {
                            required: "Please enter password"
                        },
                        'street_no': {
                            required: "Please enter  street number"
                        },
                        'street_name': {
                            required: "Please enter  street name"
                        },
                        'state': {
                            required: "Please enter state"
                        },
                        'city': {
                            required: "Please enter  city"
                        },
                        'zip_code': {
                            required: "Please enter  zip code"
                        },
                        'phone': {
                            required: "Please enter  phone number"
                        },
                    },

                    highlight: function (element) {
                        $(element).parent().addClass("has-error");
                    },
                    submitHandler: function (form) {
                        form.submit();
                    }

                });
            }
        };

        const callbackfromreportprovider =(response)=>{

                if(response.status) {
                    $('#client_form').submit();
                }else {
                    let html = response.message;
                    $('#common_message_text').text(html);
                    $('#common_confirmation_modal').modal('show');
                }
        }

        $("#client_show_hide_password a").on('click', function (event) {
            common_helper.globalPasswordView('#client_show_hide_password', event);
        })

        const client_activate =(e) => {

            let type = $('#client_activate_form').find('input[name=type]').val();

            let html_content = `<h4>Are you sure you want to activate client?</h4>`;

            if(type === '2'){
                html_content = `<h4>Are you sure you want to reset credit report?</h4>`;
            }

            const swalresponse = common_helper.swalAleart(html_content, 'warning', 450, true, '', true, true, 'Yes');

            swalresponse.then(function (result) {

                if (result.isConfirmed) {
                    $('#client_activate_form').submit();
                }

            })

            return false;
        }

        $("#change_wave").on('click', function (event) {

            $('#wave').prop('disabled', !this.checked);
        })

    </script>

@endpush
