@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 Agency Group</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-add">
                    <div class="pull-left">
                      <h3>Agency Group</h3>
                    </div>
                </div>
                <div class="pull-right">
                    @can('Agency-GroupType-Create')
                        <a class="button_sm button_primary" href="{{ route('agency-group.create') }}"><span class="fa fa-plus"></span>  Create New</a>
                    @endcan
                </div>
            </div>
        </div>
    </div>
    <div class="box-body table-responsive">
        <table id="datatable" class="table  table-bordered table-hover nowrap">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Agency Group</th>
                    <th>Agency Group Amount</th>
                    <th>Condition Group</th>
                    <th>Percentage Group</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            @foreach($data as $key => $value)
                <tr>
                    <td>{{$value->id}}</td>
                    <td>{{$value->agency_group_name}}</td>
                    <td>{{$value->agency_group_amount_get}} %</td>
                    <td>{{$value->agency_group_condition}}</td>
                    <td>{{$value->agency_group_percentage}}</td>
                    <td>
                        @can('Agency-GroupType-Edit')
                            <a href="{{route("agency-group.edit", $value->id)}}"><span class="button_success fa fa-edit"></span></a>
                        @endcan
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </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);

                }
            });

        });
    </script>
@endsection


