@extends('layouts.app')
@push('css')
    <style>
    .color-red{
       color:red
    }
    .font-bold{
        font-weight: bold;
    }
    </style>
@endpush
@section('content')
    @php
        $max_file_size= $file = config('constant.MAX_FILE_SIZE');
        $source_types = config('constant.sourceType');
        $credit_report_providers = getCache('credit_report_provider_link');
        $free_value = array_keys(config('constant.CLIENT_TYPES'),"Free");
    @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="row">
                    <div class="col-md-12">
                        <div class="panel-heading">
                            <h3>Account Info <small>Manage your account info</small></h3>
                            <div class="pull-right" style="margin-top: -30px;margin-right: 10px;">
                                <button class="btn btn-sm btn-info" style="background: #FF440A !important;border-color: #FF440A !important;" type="button" id="btn_show_hide_text" onclick="return show_hide_textbox(this)" data-toggle="tooltip" title="Show or Hide Name,Email,SSN,Phone">
                                    <i class="fa fa-eye" style="font-size: 14px; color: black;" id="show_hide_icon" aria-hidden="true"></i>
                                </button>
                            </div>
                        </div>
                    </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('manage.clients')}}" id="client_form" autocomplete="off"
                                      enctype=multipart/form-data
                                      class="input-form-section">
                                    @csrf
                                <div class="x_content">
                                    <div class="col-md-12">
                                            <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="creditreport[first_name]" type="text"
                                                               value="<?php echo auth()->user()->first_name; ?>" >
                                                    </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="creditreport[last_name]" type="text"
                                                               value="<?php echo auth()->user()->last_name; ?>" >
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="dob">Date of Birth</label>
                                                        <input class="form-control" name="creditreport[birth_date]" type="text" maxlength="10" onkeyup="birthDateCompleted()"
                                                               value="<?php echo auth()->user()->birth_date; ?>" >
                                                    </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="creditreport[ssn]"
                                                               type="text" maxlength="4"
                                                               value="<?php echo auth()->user()->ssn; ?>"
                                                               >
                                                    </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="creditreport[phone]" type="text"
                                                               value="<?php echo auth()->user()->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="creditreport[street_no]" type="text"
                                                               value="<?php echo auth()->user()->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="creditreport[street_name]" type="text"
                                                               value="<?php echo auth()->user()->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="creditreport[city]" type="text"
                                                               value="<?php echo auth()->user()->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="creditreport[state]" type="text"
                                                               value="<?php echo auth()->user()->state; ?>" >
                                                    </div>
                                                </div>
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="dob">Zip</label>
                                                        <input class="form-control" name="creditreport[zip_code]" type="text"
                                                               value="<?php echo auth()->user()->zip_code; ?>" >
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="dob">Email</label>
                                                        <input class="form-control" disabled name="creditreport[email]"
                                                               type="text"
                                                               value="<?php echo auth()->user()->email; ?>" >
                                                    </div>
                                                </div>
                                                <div class="col-md-6 col-xs-12">
                                                    <div class="form-group">
                                                        <label for="dob">Password</label>
                                                        <div class="input-group" id="manage_client_show_hide_password">
                                                            <input class="form-control" name="creditreport[password]"
                                                                   type="password"
                                                                   value="{{customDecrypt(auth()->user()->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="source_type">Source Type</label>
                                                    <select name="creditreport[credit_report_company_type]"  onchange="sourceTypeOnchange()" id="company_type"  class="form-control">
                                                        @foreach($source_types as  $key => $value)
                                                            @if(auth()->user()->is_free == (int)$free_value && $value == config('constant.sourceType.SmartCredit'))
                                                                @continue;
                                                            @endif
                                                            @if(auth()->user()->credit_report_company_type == $value)
                                                            <option value="{{$value}}" {{auth()->user()->credit_report_company_type == $value ? 'selected':''}}> {{$key}}</option>
                                                            @endif
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="x_content" id="upload-document-panel">
                                        @include('partials.upload_documents')
                                    </div>
                                    <div class="col-md-12 hidden">
                                    @if(count($question_answer) > 0 && auth()->user()->credit_report_company_type == config('constant.sourceType.SmartCredit'))
                                        @include('partials.user_identity_question_answer',['question_answers'=>$question_answer])
                                    @endif
                                    </div>
                                    @if(isClientSubscription())
                                    <div class="col-sm-12 center" style="margin-top: 10px; text-align: center; ">
                                        <input class="btn btn-success btn2" onclick="return client_form_submit(this)" type="submit" value="Save Changes">
                                    </div>
                                    @endif
                                </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    @if (!empty($upload_medias))
        @include('partials.modals.upload_doc_modal')
    @endif

    <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() {
            @if(getSession('login') == 1)
            sessionStorage.setItem('user_data_viewed','0');
            sessionStorage.setItem('video_shown','0');
            {{setSession('login',0)}};
            @endif

            if (sessionStorage.getItem("user_data_viewed") === "1") {
                $('#show_hide_icon').removeClass('fa-eye-slash');
                $('#show_hide_icon').addClass('fa-eye');
            }

            if (sessionStorage.getItem("user_data_viewed") === "0") {
                $('#show_hide_icon').removeClass('fa-eye');
                $('#show_hide_icon').addClass('fa-eye-slash');
            }

            show_hide_textbox();
            @if(!(isClientSubscription()))
                showSubscription();
            @else
                @if(isClientFirstTimeLogin())
                     common_helper.commonModalView('{{route('show.modal')}}','FIRST_TIME_LOGIN_MODAL_VIEW','first_time_login_modal');
                  // showFirstTimeLoginModalView();
                @endif
            @endif

        });

        const sourceTypeOnchange=()=>{

            let selected_value =  $("#company_type").val();

            let current_source_type = {{auth()->user()->credit_report_company_type}};

            let source_name = current_source_type == 1 ? 'SmartCredit' : "Identity IQ" ;
            sourceTypeConfigUnset()
            if( selected_value != current_source_type){

               let html = 'Set up your '+ source_name+ ' first, use the same email and password you used to set up your credit zombies account';
                $('#common_message_text').text(html);
                sourceTypeConfigSetup(current_source_type)
               $('#common_confirmation_modal').modal('show');
            }
            //$("select[name='source_type']").val(current_source_type);
        }

        const hideFirstTimeLoginModalView=()=>{

           $('#first_time_login_modal').modal('hide');

           let provider = $('#report_provider').val();
           let providers = [];

           let go_to_url = '';

           providers = @php echo json_encode($credit_report_providers);@endphp;

           go_to_url = providers[parseInt(provider)];

           window.open(go_to_url,'_blank') ;

           firstTimeLoginUserUpdate();
       }

        const client_form_submit =(e)=>{
            $('.has-error').removeClass('has-error')
            if($('#client_form').valid()) {
                let url = '{{ route('admin.ajax.get.process') }}';
                let email = $('#client_form').find('input[name="creditreport[email]"]').val();
                let password = $('[name="creditreport[password]"]').val();
                let source_type =  $("#company_type").val();
                let ssn = $('[name="creditreport[ssn]"]').val();

                let data = {
                    action: 'GET_SUBSCRIPTION_STATUS_CREDIT_REPORT_PROVIDER',
                    email: email,
                    password: password,
                    source_type: source_type,
                    ssn: ssn,
                };
                common_helper.globalAjaxRequestAsync(url, 'get', data, callbackfromreportprovider);
            }
            return false;
        }

        const file_delete = (title,image)=>{
            let action = 'DELETE_CLIENT_DOC_FILE';
            let html_content = `<h4>Are you sure you want to delete </h4>`;
            html_content += `<h4>`+ title + ` file?` +`</h4>`;
            const swalresponse = common_helper.swalAleart(html_content, 'warning', 450, true, '', true, true, 'Yes');
            swalresponse.then(async function (result) {
                if (result.isConfirmed) {
                    let response = await common_helper.globalAjaxRequest('<?php echo e(route('process.ajax')); ?>', 'POST', {
                        action: action,
                        userData: image,
                        _token: "<?php echo e(csrf_token()); ?>"
                    });
                    if (response.status) {
                        Swal.fire({icon: response.type, title: response.message, width: 450,closeOnConfirm: true});
                        window.location = `<?php echo e(route('manage.clients')); ?>`;
                    } else {
                        Swal.fire({icon: response.type, title: response.message, width: 450,closeOnConfirm: true});
                    }
                }
            })
        };

        const showSubscription=()=> {
            common_helper.commonModalView('{{route('show.modal')}}','RECURRING_VIEW_MODAL','recurring_view_modal');
        }

        const show_hide_textbox = (e)=>{
            $return_data = common_helper.show_hide_textbox($('#show_hide_icon'),
                $('[name="creditreport[phone]"]'),$('[name="creditreport[email]"]'),
                $('[name="creditreport[first_name]"]'),$('[name="creditreport[last_name]"]'),
                $('[name="creditreport[ssn]"]'),$('[name="creditreport[birth_date]"]'),
                $('[name="creditreport[street_no]"]'),$('[name="creditreport[street_name]"]'),
                $('[name="creditreport[city]"]'),$('[name="creditreport[state]"]'),
                $('[name="creditreport[zip_code]"]')
            );

            sessionStorage.setItem('user_data_viewed',$return_data);

        }

    </script>

    <script src="{{asset('/')}}js/accountinfo/clientinfo.js?v=1.0.2"></script>
@endpush
