@extends('adminlte::page')

@section('content')
<?php Fun::lang() ?>
<div class="title-add">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li> <a class="ng-binding" href="#"><i class="fa fa-dashboard"></i> Dashboard</a> </li>
            <li><a href="#">Manage Condition Commission Company</a></li>
        </ul>
    </div>
</div>
<div class="page">
    <div class="top-content">
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="title-page">
                    <div class="pull-left">
                        <h3>Edit Condition Commission Company</h3>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12">
            <div class="form-wrapper">
                {!! Form::model($agency_group, ['method' => 'PATCH','route' => ['admin-commission.update', $agency_group->id]]) !!}
                <div class="row">
                    <br>
                    <div class="col-sm-12">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="col-sm-5 control-label">Condition Commission Amount</label>
                                <div class="col-sm-7">
                                    {!! Form::text('agency_company_amount_get', null, array('class' => 'form-control number-only')) !!}
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group" id="condition_com_option">
                                <label class="col-md-5 control-label">Condition Withdraw</label>
                                <div class="col-md-7">
                                    {!! Form::select('agency_company_conid', $condition, null, ['class' => 'form-control select2 agent_id']) !!}
                                    <input type="hidden" name="agency_company_condition" class="form-control agent_condition">
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-4">
                            <div class="form-group" id="condition_option">
                                <label class="col-md-5 control-label">Commission Withdraw</label>
                                <div class="col-md-7">
                                    {!! Form::select('agency_company_percentage', $commission, null, ['class' => 'form-control select2 conditions']) !!}
                                </div>
                            </div>
                        </div>
                    </div>
                    {{--<div class="col-sm-6">--}}
                    {{--<div class="form-group">--}}
                    {{--<label class="col-sm-5 required control-label">Agency Close Sale</label>--}}
                    {{--<div class="col-sm-7">--}}
                    {{--{!! Form::text('agency_close_sale_name', null, array('placeholder' => 'Close Sale Name','class' => 'form-control','required')) !!}--}}
                    {{--</div>--}}
                    {{--</div>--}}
                    {{--</div>--}}

                    <div class="col-sm-12 col-xs-12">
                        <br>
                        <div class="form-group">
                            <button type="submit" class="button_sm button_primary pull-right"><span class="fa fa-save"></span> Update</button>
                            <button type="button" onClick="javascript:history.go(-1)" class="button_sm button_warning pull-right">
                                <span class=" fa fa-arrow-circle-left"></span> Back</button>
                        </div>
                    </div>
                </div>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>
@endsection
@section('js')
<script type="text/javascript">
    $(document).on('change', '#condition_com_option', function() {
        var id = $(this).find(':selected').val();
        $(".conditions").empty();
        $.ajax({
            type: 'post',
            url: "{{route('get_commission_network_condition')}}",
            dataType: 'json',
            data: {
                "_token": "{{ csrf_token() }}",
                "id": id,
            },
            success: function(data) {
                $(".conditions").empty();
                var opt = '<option>please select</option>';

                $.each(data, function(index, value) {
                    opt = '<option value="' + value.commission + '">' + value.commission + '</option>';
                    $('.agent_condition').val(value.condition);
                });
                $('.conditions').append(opt);

            }
        });

    });
    $(document).ready(function() {
        var id = $('.agent_id').find(':selected').val();
        $.ajax({
            type: 'post',
            url: "{{route('get_commission_network_condition')}}",
            dataType: 'json',
            data: {
                "_token": "{{ csrf_token() }}",
                "id": id,
            },
            success: function(data) {
                $.each(data, function(index, value) {
                    $('.agent_condition').val(value.condition);
                });
            }
        });
    });
</script>
@endsection