@extends('layouts.agencies')
@section('title', 'Create Agency')
@section('content')
<?php Fun::lang() ?>
<div class="main-content-wrapper">
    <div class="main-content-wrapper">
        <div class="breadcrumb">
            <div class="container">
                <ul class="">
                    <li><a href="{{route('dashboard-agencies.index')}}">Dashboard<span>/</span></a></li>
                    <li><a href="">Register</a></li>

                </ul>
            </div>
        </div>
    </div>>

    <div class="main-box">
        <div class="main-content">
            <div class="main-admin-dashboard">
                <div class="container">
                    <div class="page-wrapper">
                        <div class="row">
                            <div class="col-sm-12 col-xs-12">
                                <div class="form-wrapper">
                                    <div class="form-wrapper">
                                        {!! Form::open(array('route' => 'admin-agency.store','method'=>'POST','enctype'=>'multipart/form-data')) !!}
                                        <div class="row">
                                            <!-- <div class="form-group col-sm-6 col-xs-12">
                                                    <label class="required">Agency Type</label>
                                                    {!! Form::select('agency_type', $select_option, null, ['class' => 'form-control select2 agency_type']) !!}

                                                </div>
                                                <div class="form-group col-sm-6 col-xs-12 agency_group_type">
                                                    <label class="required">Agency Group Type</label>
                                                    {!! Form::select('agency_group_type', $agent_group, null, ['class' => 'form-control select2 agency_types']) !!}
                                                </div> -->
                                            @if(!empty(Auth::user()->group_id))
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label for="required">Agency Type</label>
                                                {!! Form::select('type_id',['2'=>'Group Level'],'1',['class'=>'select2 form-group','id'=>'type_id','disabled'=>'true']) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label for="required" class="required">Agency Group</label>
                                                {!! Form::select('group_id',$agent_group,null,['class'=>'select2 form-group','id'=>'group_id','required']) !!}
                                            </div>
                                            @else
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label for="required">Agency Type</label>
                                                {!! Form::select('type_id',['1'=>'Network Level'],'1',['class'=>'select2 form-group','id'=>'type_id','disabled'=>'true']) !!}
                                            </div>
                                            @endif
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label for="required">Agency Team</label>
                                                {!! Form::select('team_id',$agency_team,null,['class'=>'select2 form-group','id'=>'team_id']) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Agency ID</label>
                                                {!! Form::text('user_code', $increas, array('placeholder' => 'ID','class' => 'form-control','readonly')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">First Name</label>
                                                {!! Form::text('user_firstname', null, array('placeholder' => 'First Name','class' => 'form-control','required')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Last Name</label>
                                                {!! Form::text('user_lastname', null, array('placeholder' => 'Last Name','class' => 'form-control','required')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Gender</label>
                                                <select name="user_gender" id="" class="select2" required>
                                                    <option value="Male">Male</option>
                                                    <option value="Female">Female</option>
                                                </select>
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">

                                                <label class="required">Date OF Birth</label>
                                                {!! Form::text('user_dob', null, array('placeholder' => 'Date Of Birth','class' => 'form-control date_picker','required')) !!}

                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">ID Card Number</label>
                                                {!! Form::text('user_cardid', null, array('placeholder' => '#########','class' => 'form-control number-only','required')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Phone Number</label>
                                                <!-- {!! Form::text('user_phone', null, array('placeholder' => 'Phone Number','class' => 'form-control number-only','required')) !!} -->

                                                <input type="text" class="form-control number-only" name="user_phone" data-inputmask="'mask': ['999-999-9999', '+099 99 99 9999[9]-9999']" data-mask placeholder="Phone Number">
                                                
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Reference</label>
                                                {!! Form::text('user_reference', null, array('placeholder' => 'Reference','class' => 'form-control','required')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Email</label>
                                                {!! Form::email('email', null, array('placeholder' => 'Email','class' => 'form-control','required')) !!}
                                            </div>
                                            {{--<div class="form-group col-sm-6 col-xs-12">--}}
                                            {{--<label>Sponser</label>--}}
                                            {{--{!! Form::select('parent_id', $agencys, null, ['class' => 'form-control select2',]) !!}--}}
                                            {{--</div>--}}
                                            <div class="form-group col-sm-6 col-xs-12">

                                                <label class="required">Password</label>
                                                {!! Form::password('password', array('placeholder' => 'Password','class' => 'form-control','required')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label class="required">Confirm Password</label>
                                                {!! Form::password('confirm_password', array('placeholder' => 'Password','class' => 'form-control','required')) !!}
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-6">
                                                <label class="required">Address</label>
                                                {!! Form::textarea('address', null, array('placeholder' => 'Address','class' => 'form-control','rows'=>'2','required')) !!}
                                            </div>
                                            <div class="col-xs-6 col-sm-6 col-md-6">
                                                <div class="imageupload panel panel-default">
                                                    <img src="{{asset('assets/images/default.png')}}" class="hide_img" width="100px">
                                                    <div class="file-tab panel-body">
                                                        <label class="btn button_warning btn-file">
                                                            <span>Browse</span>
                                                            <button id="cropbutton" type="button">Crop</button>
                                                            <input type="file" name="image">
                                                        </label>
                                                        <div id="views"></div>
                                                        <button type="button" class="btn button_danger">Remove</button>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-6 col-xs-12">
                                                <label for="">Bank Account</label>
                                                {!! Form::select('bank_id',$bank_list,null,['class'=>'form-control select2','id'=>'bank_id','required']) !!}
                                            </div>
                                            <div class="col-sm-12 col-xs-12" id="bank-list">

                                            </div>
                                            
                                            <div class="col-sm-12 col-xs-12">
                                                <div class="form-group">
                                                    <button type="submit" class="button_sm button_primary pull-right"><span class="fa fa-save"></span> Save</button>
                                                </div>
                                            </div>
                                        </div>
                                        {!! Form::close() !!}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection


@section('script')
<script type="text/javascript" src="{{asset('assets/controller/location.js')}}"></script>
<!-- <script type="text/javascript" src="{{asset('assets/controller/image-cropper.js')}}"></script> -->
<script type="text/javascript">
    $(document).ready(function() {
        $(".agency_group_type").hide();
    });
    $(document).on('change', '.agency_type', function() {
        var id = $(this).find(':selected').val();

        $.ajax({
            type: 'post',
            url: "{{route('get_agency_type')}}",
            dataType: 'json',
            data: {
                "_token": "{{ csrf_token() }}",
                "id": id,
            },
            success: function(data) {
                if (data.agency_type_name == 'Agency Group') {
                    $(".agency_group_type").show();
                } else {
                    $(".agency_group_type").hide();
                }
            }
        });
    });
    $(document).on('change','#bank_id',function(){
        var id      = $(this).find(':selected').val();
        var name    = $(this).find(':selected').text();
        if(id!=""){
            $(this).find(":selected").prop('disabled',true);
            $('#bank_id').select2('destroy').select2();

            var div = `<div class="form-group row-group row">
                            <div class="col-sm-1"><label for="" class="required">Bank Name</label></div>
                            <div class="col-sm-2"><input type="text" class="form-control" value="${name}" readonly><input type="hidden" name="bank_list[]" value="${id}"></div>
                            <div class="col-sm-2"><label for="" class="required">Account Name</label></div>
                            <div class="col-sm-2"><input type="text" class="form-control" name="account_name[]" required></div>
                            <div class="col-sm-2"><label for="" class="required">Account Number</label></div>
                            <div class="col-sm-2"><input type="text" class="form-control" name="account_number[]" required></div>
                            <div class="col-sm-1"><button type="button" class="btn btn-danger btn-delete-row fa fa-trash" data-id="${id}"></button></div>
                        </div>`;
            $('#bank-list').append(div);
        }
    });
    $(document).on('click','.btn-delete-row',function(){
        var id = $(this).data('id');
        $('#bank_id option[value="'+id+'"]').prop('disabled',false);
        $('#bank_id').select2('destroy').select2();
        $(this).closest('.row-group').remove();
    });
</script>
@endsection