@extends('admin.layouts.master')

@section('title')
    Agents
@stop

@section('style')

@stop

@section('content')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-users"></span> Agents
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-users"></i> Admin Panel</a></li>
                <li class="active">Agents</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 10%;">
            <div class="page-header">
                <a href="{{route('agents.new')}}" class="btn btn-primary"><i class="fa fa-plus-circle"></i> New Agent</a>
            </div>

            <table class="table table-hover" id="user_table" width="100%">
                <thead>
                <tr style="background: grey ;color:#fff; font-weight: bold">
                    <td>ID</td>
                    <td>Code</td>
                    <td>Agent Name</td>
                    <td>Team</td>
                    <td>Position</td>
                    <td>Email</td>
                    <td>Active</td>
                    <td style="text-align: center">Deleted At</td>
                    <td>Actions</td>
                </tr>
                </thead>
                @foreach($agents as $agent)
                    {{--<tr>
                        <td>{{$agent}}</td>
                    </tr>--}}
                    <tr>
                        <td>{{$agent->id}}</td>
                        <td>{{strtoupper($agent->code)}}</td>
                        <td width="20%"><a href="{{ route('agents.info',[$agent->id]) }}">{{$agent->fullname ?? '' }}</a></td>
                        <td>{{$agent->team->name ?? '-'}}</td>
                        <td width="15%">{{$agent->position}}</td>
                        <td>{{$agent->email_ad}}</td>
                        <td style="text-align: center">
                            @if ($agent->active == "Yes")
                                <span class="label label-success">{{$agent->active}}</span>
                            @else
                                <span class="label label-warning">{{$agent->active}}</span>
                            @endif
                        </td>
                        <td width="12%" style="text-align: center">
                            {{$agent->deleted_at ?? '-' }}
                        </td>
                        <td class="btn btn-default ">
                            <a href="{{ route('agents.edit',[$agent->id]) }}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a>
                            <a href="#" data-toggle="modal" data-target="#d{{$agent->id}}" class="text-danger btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                            <!-- Delete Modal -->
                            <div class="modal fade" id="d{{$agent->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <form method="post" action="{{route('agents.delete')}}">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title" id="myModalLabel"><i class="fa fa-warning"></i> confirm delete agent account</h4>
                                        </div>
                                        <div class="modal-body text-danger">
                                            <input type="hidden" name="id" value="{{$agent->id}}">
                                            Are you sure want to delete agent "{{$agent->fullname}}"
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                            <button type="submit" class="btn btn-primary">Confirm</button>
                                        </div>

                                    </div>
                                        {{csrf_field()}}
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                    @endforeach
            </table>
            @if(Session('info'))
                <div class="row">
                    <div class="col-md-6 col-md-offset-3 text-center">
                        <div class="tem alert alert-success navbar-fixed-bottom"><span class="glyphicon glyphicon-ok-circle"></span> {{Session('info')}}</div>
                    </div>
                </div>
            @endif
        </section>

    </div>
@stop

@section('script')
    <script>
        $(document).ready(function() {
            $('#user_table').DataTable( {
                "bDestroy": true,
                "order": [[ 0, "desc" ]]
            });
        });
        /*$("#btnAdd").on("click", function(){
            $('#addModal').modal('toggle');
        });*/
    </script>
@stop