@extends('layouts.app')

@section('content')
    <section class="page-header row">
        <h2> {{ $pageTitle }} </h2>
        <ol class="breadcrumb">
            <li><a href="{{ url('') }}"> Dashboard </a></li>
            <li><a href="{{ url('/manage/'.$pageModule) }}"> {{ $pageTitle }} </a></li>
            <li class="active"> Form</li>
        </ol>
    </section>
    <div class="page-content row">
        <div class="page-content-wrapper no-margin">

            {!! Form::open(array('url'=>'/manage/usersdata?return='.$return, 'class'=>'form-vertical validated','files' => true )) !!}
            <input type="hidden" name="status_type" value="{{ $pageTitle }}"/>

            <div class="sbox-title clearfix">
                <div class="sbox-tools pull-right">
                    <a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" class="tips btn btn-sm "
                       title="{{ __('core.btn_back') }}"><i class="fa  fa-times"></i></a>
                </div>
                <div class="sbox-tools1 pull-left1">
                    <button name="apply" class="btn btn-sm btn-primary  " title="{{ __('core.btn_back') }}"><i
                                class="fa  fa-check"></i> {{ __('core.sb_apply') }} </button>
                    <button name="save" class="btn btn-sm btn-success" title="{{ __('core.btn_back') }}"><i
                                class="fa  fa-paste"></i> {{ __('core.sb_save') }} </button>
                    <?php if ($frontendSlug != '') {
                        $fsconfig = explode('@', $frontendSlug);
                        if (($row[$fsconfig[1]]))
                            echo '<a  class="btn btn-sm btn-outline-primary" target="_blank"  title="FrontEnd" href="' . (config('website.cnf_appurl') . '/' . config('website.cnf_lang') . str_replace('//', '/', ('/' . $fsconfig[0] . '/' . $row[$fsconfig[1]]))) . '"><i class="fa  fa-desktop"></i> FrontEnd</a>';
                    } ?>
                </div>
            </div>
            <div class="sbox1">
                <div class="sbox-content clearfix row">
                    <div class="col-xs-12">
                        <ul class="parsley-error-list">
                            @foreach($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>

                        <?php $curTime = time();?>

                        <div class="sbox1">
                            <div class="col-md-6">
                                <fieldset class="sbox" style="border-top:0; border-radius: 5px;">
                                    <legend> usersdata</legend>
                                    <?php if (!isset($row['user_id'])) $row['user_id'] = null;   ?>
                                    <input type='hidden' name='user_id' id='user_id' value='{{$row['user_id']}}'/>

                                    <div class="form-group  depen-  wrap-first_name  ">
                                        <label for="ipt" class=" control-label "> First Name </label>


                                        <?php if (!isset($row['first_name'])) $row['first_name'] = null;   ?>
                                        <input type='text' name='first_name' id='first_name'
                                               value='{{ $row['first_name'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-last_name  ">
                                        <label for="ipt" class=" control-label "> Last Name </label>


                                        <?php if (!isset($row['last_name'])) $row['last_name'] = null;   ?>
                                        <input type='text' name='last_name' id='last_name'
                                               value='{{ $row['last_name'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-email  ">
                                        <label for="ipt" class=" control-label "> Email <span class="asterix"> * </span>
                                        </label>


                                        <?php if (!isset($row['email'])) $row['email'] = null;   ?>
                                        <input type='text' name='email' id='email' value='{{ $row['email'] }}'
                                               required class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-user_token  ">
                                        <label for="ipt" class=" control-label "> User Token </label>


                                        <?php if (!isset($row['user_token'])) $row['user_token'] = null;   ?>
                                        <input type='text' name='user_token' id='user_token'
                                               value='{{ $row['user_token'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-phone_number  ">
                                        <label for="ipt" class=" control-label "> Phone Number </label>


                                        <?php if (!isset($row['phone_number'])) $row['phone_number'] = null;   ?>
                                        <input type='text' name='phone_number' id='phone_number'
                                               value='{{ $row['phone_number'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-social_id  ">
                                        <label for="ipt" class=" control-label "> Social Id </label>


                                        <?php if (!isset($row['social_id'])) $row['social_id'] = null;   ?>
                                        <input type='text' name='social_id' id='social_id'
                                               value='{{ $row['social_id'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-social_avatar  ">
                                        <label for="ipt" class=" control-label "> Social Avatar </label>


                                        <?php if (!isset($row['social_avatar'])) $row['social_avatar'] = null;   ?>
                                        <input type='text' name='social_avatar' id='social_avatar'
                                               value='{{ $row['social_avatar'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-remember_token  ">
                                        <label for="ipt" class=" control-label "> Remember Token </label>


                                        <?php if (!isset($row['remember_token'])) $row['remember_token'] = null;   ?>
                                        <input type='text' name='remember_token' id='remember_token'
                                               value='{{ $row['remember_token'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-email_verified_at  ">
                                        <label for="ipt" class=" control-label "> Email Verified At </label>


                                        <?php if (!isset($row['email_verified_at'])) $row['email_verified_at'] = null;   ?>

                                        <div class="input-group m-b" style="width:150px !important;">

                                            <input type='text' name='email_verified_at' id='email_verified_at'
                                                   value='{{ $row['email_verified_at'] }}'
                                                   class='form-control input-sm @if(trim('  ')!='readonly') datetime @endif '/>

                                            <span class="input-group-addon calwrap"><i
                                                        class="fa fa-calendar"></i></span>
                                        </div>

                                    </div>
                                    <div class="form-group  depen-  wrap-referral_percent  ">
                                        <label for="ipt" class=" control-label "> Referral Percent <span
                                                    class="asterix"> * </span> </label>


                                        <?php if (strlen($row['referral_percent']) < 1) $row['referral_percent'] = '0';      ?>
                                        <input type='number' name='referral_percent' id='referral_percent'
                                               value='{{ $row['referral_percent'] }}'
                                               required class='form-control is_number'/>
                                    </div>
                                </fieldset>
                            </div>

                            <div class="col-md-6">
                                <fieldset class="sbox" style="border-top:0; border-radius: 5px;">
                                    <legend></legend>

                                    <div class="form-group  depen-  wrap-referral_code  ">
                                        <label for="ipt" class=" control-label "> Referral Code </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom" title="readonly"><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['referral_code'])) $row['referral_code'] = null;   ?>
                                        <input type='text' name='referral_code' id='referral_code'
                                               value='{{ $row['referral_code'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-referrer_code  ">
                                        <label for="ipt" class=" control-label "> Referrer Code </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom" title="readonly"><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['referrer_code'])) $row['referrer_code'] = null;   ?>
                                        <input type='text' name='referrer_code' id='referrer_code'
                                               value='{{ $row['referrer_code'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-referrer_id  ">
                                        <label for="ipt" class=" control-label "> Referrer Id </label>


                                        <?php if (!isset($row['referrer_id'])) $row['referrer_id'] = null;   ?>
                                        <input type='number' name='referrer_id' id='referrer_id'
                                               value='{{ $row['referrer_id'] }}'
                                               class='form-control is_number'/>
                                    </div>
                                    <div class="form-group  depen-  wrap-referral_validity  ">
                                        <label for="ipt" class=" control-label "> Referral Validity </label>


                                        <?php if (!isset($row['referral_validity'])) $row['referral_validity'] = null;   ?>
                                        <input type='text' name='referral_validity' id='referral_validity'
                                               value='{{ $row['referral_validity'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-signup_via  ">
                                        <label for="ipt" class=" control-label "> Signup Via <span
                                                    class="asterix"> * </span> </label>


                                        <?php if (strlen($row['signup_via']) < 1) $row['signup_via'] = 'email';      ?>
                                        <?php $signup_via = (isset($row['signup_via'])) ? $row['signup_via'] : null; ?>

                                        <input type='radio' name='signup_via' value='email' required
                                               @if( $signup_via == 'email') checked="checked"
                                               @endif class='minimal-red'> Email

                                        <input type='radio' name='signup_via' value='google' required
                                               @if( $signup_via == 'google') checked="checked"
                                               @endif class='minimal-red'> Google

                                        <input type='radio' name='signup_via' value='facebook' required
                                               @if( $signup_via == 'facebook') checked="checked"
                                               @endif class='minimal-red'> Facebook

                                        <input type='radio' name='signup_via' value='apple' required
                                               @if( $signup_via == 'apple') checked="checked"
                                               @endif class='minimal-red'> Apple
                                    </div>
                                    <div class="form-group  depen-  wrap-signup_via  ">
                                        <label for="type" class=" control-label "> Type <span
                                                    class="asterix"> * </span> </label>

                                        <?php $userType = (isset($row['type'])) ? $row['type'] : null; ?>

                                        <input type='radio' name='type' value='normal' required
                                               @if( $userType == 'normal') checked="checked"
                                               @endif class='minimal-red'> Normal

                                        <input type='radio' name='type' value='affiliate' required
                                               @if( $userType == 'affiliate') checked="checked"
                                               @endif class='minimal-red'> Affiliate
                                    </div>
                                    <div class="form-group  depen-  wrap-user_lang  ">
                                        <label for="ipt" class=" control-label "> User Lang <span
                                                    class="asterix"> * </span> </label>


                                        <?php if (strlen($row['user_lang']) < 1) $row['user_lang'] = 'ar';      ?>
                                        <input type='text' name='user_lang' id='user_lang'
                                               value='{{ $row['user_lang'] }}'
                                               required class='form-control input-sm '/>
                                    </div>

                                    <div class="form-group  depen-  wrap-is_merchant ">
                                        <label for="ipt" class=" control-label ">Is Merchant</label>
                                        <?php if (!isset($row['is_merchant'])) $row['is_merchant'] = null;   ?>
                                        <div class='switch-wrap'>
                                            <label class='switch'>
                                                <input type='hidden' name='is_merchant' value='0'/>
                                                <input type='checkbox' name='is_merchant' id='is_merchant' value='1' @if($row['is_merchant']) checked="checked" @endif />
                                                <span class="slider round"></span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group  depen-  wrap-valid_merchant ">
                                        <label for="ipt" class=" control-label ">Valid Merchant</label>
                                        <?php if (!isset($row['valid_merchant'])) $row['valid_merchant'] = null;   ?>
                                        <div class='switch-wrap'>
                                            <label class='switch'>
                                                <input type='hidden' name='valid_merchant' value='0'/>
                                                <input type='checkbox' name='valid_merchant' id='valid_merchant' value='1'  @if($row['valid_merchant']) checked="checked" @endif />
                                                <span class="slider round"></span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group  depen-  wrap-revoked_merchant ">
                                        <label for="ipt" class=" control-label ">Revoke Merchant</label>
                                        <?php if (!isset($row['revoked_merchant'])) $row['revoked_merchant'] = null;   ?>
                                        <div class='switch-wrap'>
                                            <label class='switch'>
                                                <input type='hidden' name='revoked_merchant' value='0'/>
                                                <input type='checkbox' name='revoked_merchant' id='revoked_merchant' value='1'  @if($row['revoked_merchant']) checked="checked" @endif />
                                                <span class="slider round"></span>
                                            </label>
                                        </div>
                                    </div>

                                    <div class="form-group  depen-  wrap-active  ">
                                        <label for="ipt" class="control-label">Active</label>
                                        <?php if (!isset($row['active'])) $row['active'] = null;   ?>
                                        <div class='switch-wrap'><label class='switch'>
                                                <input type='hidden' name='active' value='0'/>
                                                <input type='checkbox' name='active' value='1'
                                                       @if($row['active']) checked @endif
                                                /> <span class="slider round"></span></label></div>
                                    </div>

                                    <div class="form-group  depen-  wrap-gender  ">
                                        <label for="ipt" class=" control-label "> Gender </label>


                                        <?php if (!isset($row['gender'])) $row['gender'] = null;   ?>
                                        <?php $gender = (isset($row['gender'])) ? $row['gender'] : null; ?>

                                        <input type='radio' name='gender' value='Male'
                                               @if( $gender == 'Male') checked="checked" @endif class='minimal-red'>
                                        Male

                                        <input type='radio' name='gender' value='Female'
                                               @if( $gender == 'Female') checked="checked" @endif class='minimal-red'>
                                        Female
                                    </div>
                                    <div class="form-group  depen-  wrap-photo  ">
                                        <label for="ipt" class=" control-label "> Photo </label>


                                        <?php if (!isset($row['photo'])) $row['photo'] = null;   ?>
                                        <input type='hidden' name='photo' id='photo' value='{{ $row['photo'] }}'
                                               class='photo    form-control input-sm '/>


                                        <div class='photo_preview'></div>
                                        <div class='photoPreview'>
                                            <div class='img-preview'>@if(Storage::disk(config('filesystems.website_default'))->exists($row['photo']))
                                                    {!! SiteHelpers::showUploadedFile(Storage::disk(config('filesystems.website_default'))->url($row['photo']),'/public/user/photos') !!}
                                                @endif</div>
                                        </div>

                                    </div>
                                </fieldset>
                            </div>


                        </div>


                    </div>
                </div>
            </div>
            @include('/manage/'.$pageModule.'/subform')


            <div class="sbox-title clearfix">
                <div class="sbox-tools pull-right">
                    <a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" class="tips btn btn-sm "
                       title="{{ __('core.btn_back') }}"><i class="fa  fa-times"></i></a>
                </div>
                <div class="sbox-tools pull-left">
                    <button name="apply" class=" btn btn-sm btn-primary  " title="{{ __('core.btn_back') }}"><i
                                class="fa  fa-check"></i> {{ __('core.sb_apply') }} </button>
                    <button name="save" class=" btn btn-sm btn-success" title="{{ __('core.btn_back') }}"><i
                                class="fa  fa-paste"></i> {{ __('core.sb_save') }} </button>
                </div>
            </div>


            <input type="hidden" name="action_task" value="save"/>
            {!! Form::close() !!}
        </div>
    </div>


<style>
    .wrap-revoked_merchant input:checked + .slider {
    background-color: #f24d23;
    }

    .wrap-revoked_merchant input:focus + .slider {
    box-shadow: 0 0 1px #f24d23;
    }
</style>
    <script type="text/javascript">

        $(document).ready(function () {
            @if($row['is_merchant']==0)
                $('#valid_merchant').prop('disabled',true);
                $('.wrap-valid_merchant').hide();
                $('.wrap-revoked_merchant').hide();
            @else
                $('#valid_merchant').prop("disabled", false) ;
                $('.wrap-valid_merchant').show();
                $('.wrap-revoked_merchant').show();
            @endif
        });



        $('#is_merchant:checkbox').click(function () {
            var checkStatus = $(this).is(':checked');
            if(!checkStatus){
                $('#valid_merchant').prop("checked", false);
                $('#valid_merchant').prop('disabled',true) ;

                $('.wrap-valid_merchant').hide();
                //$('.wrap-revoked_merchant').hide();
            }else{
                $('#valid_merchant').prop("disabled", false);
                if($('#revoked_merchant:checkbox').is(':checked')){
                    $('#revoked_merchant').prop("checked", false);
                    $('.wrap-revoked_merchant').show();
                }

                $('.wrap-valid_merchant').show();
            }
        });
        $('#valid_merchant:checkbox').click(function () {
            var checkStatus = $(this).is(':checked');
            if(!checkStatus){
                $('#is_merchant').prop("checked", false);
                $('#valid_merchant').prop('disabled',true) ;
            }else{

                if($('#revoked_merchant:checkbox').is(':checked')){
                    $('#revoked_merchant').prop("checked", false);
                }
            }
        });
        $('#revoked_merchant:checkbox').click(function () {
            var checkStatus = $(this).is(':checked');
            if(checkStatus){
               // $('#revoked_merchant').prop("checked", false);
                $('#is_merchant').prop("checked", false);
                $('#valid_merchant').prop("checked", false);
                $('.wrap-valid_merchant').hide();
              //  $('.wrap-revoked_merchant').hide();
                $('.wrap-revoked_merchant').show();
            }else{
                $('#revoked_merchant').prop("checked", true);
                $('.wrap-revoked_merchant').show();
            }
        });


        $(document).ready(function () {


            $('.removeMultiFiles').on('click', function () {
                var removeUrl = '{{ url("usersdata/removefiles?file=")}}' + $(this).attr('url');
                $(this).parent().remove();
                $.get(removeUrl, function (response) {
                });
                $(this).parent('div').empty();
                return false;
            });

        });
    </script>
@stop