@extends('adminlte::page')

@section('content')
@include('administrator.commission-condition-one.form-add-condition')
@include('administrator.commission-condition-one.form-edit-condition')
@include('administrator.commission-condition-one.form-remove-condition')
<?php Fun::lang() ?>
<div class="title-page">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="#">Manage Withdraw Condition</a></li>
            <li><a href="#">Withdraw Condition Generate</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>Withdraw Condition Generate</h3>
                    </div>
                    @can('Withdraw-One-Condition-Create')
                    <span class="button_success btn-circle pull-right btn-add-condition" style="cursor: pointer;"><i class="fa fa-plus"></i> Create New</span>
                    @endcan
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12">
            <div class="box-body table-responsive">
                <table id="datatable_get_condition" class="table table-striped table-bordered table-hover nowrap">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Condition Name</th>
                            <th>Condition</th>
                            <th>Gettable Percentage</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

@endsection
@section('js')

<script type="text/javascript">
    $(document).ready(function() {
        $('#datatable_get_condition').DataTable({
            ordering: false,
            "serverSide": true,
            ajax: "{{ route('get-commission-condition-one') }}",
            columns: [{
                    data: 'DT_RowIndex'
                },
                {
                    data: 'condition_name'
                },
                {
                    data: 'condition'
                },
                {
                    data: 'commission'
                },
                {
                    data: 'action'
                },
            ],
        });
    });
    $(document).on('click', '.btn-add-condition', function() {
        $('#add-condition').modal('show');
    });
    $(document).on('change', '.checkbox', function() {
        var id = $(this).attr('id');
        var route = "{{route('update-condition-status',':id')}}";
        route = route.replace(':id',id);
        $.ajax({
            type: 'GET',
            url: route,
            dastaType: 'text',
            data: {
                "_token": "{{ csrf_token() }}",
                "id": id,
            },
            success: function(data) {
                $('#commission_option').append(data);
            }
        });
    });
    $(document).on('click','.btn_edit_condition_one',function(){
        var id = $(this).data('id');
        var commission = $(this).data('commission');
        var condition = $(this).data('condition');
        var condition_name = $(this).data('condition-name');
        var route = "{{route('edit-commission-condition-one',':id')}}";
        route = route.replace(':id',id);
        $('#form-edit-condition-one').attr('action',route);
        $('#condition-one').val(condition);
        $('#condition_name_one').val(condition_name);
        $('#commission-one').val(commission);
        $('#edit-condition-one').modal('show');
    });
    $(document).on('click','.btn_remove_condition',function(){
        var id = $(this).data('id');
        var route = "{{route('commission-condition.destroy',':id')}}";
        route = route.replace(':id',id);
        $('#form-remove-condition').attr('action',route);
        $('#remove-condition').modal('show');
    });
</script>

@endsection