@extends('layouts.masterDashboard')
@section('content')
    <style>
/*        .table thead th{
            border-top : 0;
        }*/
    </style>
    <div class="row">
        <div class="col-md">
            <div class="card card-user shadow">
                <div class="card-header d-flex justify-content-center border-0 py-2">
                    @if(!isset($roleList) && !isset($roleType))
                        <h3>Pick One Role</h3>
                    @else
                        @if($roleType == 'client' || $roleType == 'vendor')
                            <h3>{{ 'Mapped '. $roleType .' List' }}</h3>
                        @elseif($roleType == 'sitemarshal')
                            <h3>Mapped Team FK List</h3>
                        @endif
                    @endif
                </div>
                @if(isset($roleType))
                <div class="border-bottom-0 px-4">
                    <div class="container">
                        <div class="row px-4 d-flex justify-content-end">
                            <div>
                                <input type="text" onkeyup="search(event);" placeholder="Search by name.." class="form-control p-2 h-75" />
                            </div>
                        </div>
                    </div>
                </div>
                @endif
                <div class="card-body py-2">
                    <div class="row justify-content-center">
                        @if(!isset($roleType))
                            <a href="{{ url('existingMap/client') }}" class="peterriver text-decoration-none text-white mx-4">Client</a>
                            <a href="{{ url('existingMap/sitemarshal') }}" class="peterriver text-decoration-none text-white mx-4">Team FK</a>
                            <a href="{{ url('existingMap/vendor') }}" class="peterriver text-decoration-none text-white mx-4">Vendor</a>
                        @elseif(isset($roleType))
                            <div class="table-responsive px-2" style="overflow-x: scroll; overflow-y: hidden;">
                                <table class="table table-hover">
                                    <thead class="text-dark">
                                        <tr>
                                            <th class="text-center" scope="col">S.No.</th>
<!--                                            <th class="text-center" scope="col">Name</th>-->
                                            @if($roleType == 'client')
                                              <th class="text-center" scope="col">Client Name</th>
                                              <th class="text-center" scope="col">Client Code</th>
                                            @elseif($roleType == 'vendor')
                                              <th class="text-center" scope="col">Vendor Name</th>
                                              <th class="text-center" scope="col">Vendor Code</th>
                                            @elseif($roleType == 'sitemarshal')
                                              <th class="text-center" scope="col">Marshal Name</th>
                                                <th class="text-center" scope="col">Employee ID</th>
                                            @endif
                                            @if($roleType == 'client' || $roleType == 'vendor')
                                                <th class="text-center" scope="col">Contact Person</th>
                                            @endif
                                            <th class="text-center" scope="col">Mobile No</th>
                                            <th class="text-center" scope="col">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody id="render">
                                        <td colspan="7" align="center" id="load_data" style="display: none;">
                                            <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
                                               width="24px" height="30px" viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">
                                              <rect x="0" y="0" width="4" height="10" fill="#333">
                                                <animateTransform attributeType="xml"
                                                  attributeName="transform" type="translate"
                                                  values="0 0; 0 20; 0 0"
                                                  begin="0" dur="0.6s" repeatCount="indefinite" />
                                              </rect>
                                              <rect x="10" y="0" width="4" height="10" fill="#333">
                                                <animateTransform attributeType="xml"
                                                  attributeName="transform" type="translate"
                                                  values="0 0; 0 20; 0 0"
                                                  begin="0.2s" dur="0.6s" repeatCount="indefinite" />
                                              </rect>
                                              <rect x="20" y="0" width="4" height="10" fill="#333">
                                                <animateTransform attributeType="xml"
                                                  attributeName="transform" type="translate"
                                                  values="0 0; 0 20; 0 0"
                                                  begin="0.4s" dur="0.6s" repeatCount="indefinite" />
                                              </rect>
                                            </svg>
                                        </td>
                                    </tbody>
                                </table>
                            </div>
                            @section('customscript')
                                <script>
                                    var roleType = "{{ $roleType }}".toLowerCase();
                                    $(function () {
                                        var link = "{{ url('mapped_roles') . '/' . $roleType }}";
                                        request_role_data(link);
                                    });
                                    function search(e){
                                        console.log(e.target.value);
                                        var search = e.target.value.trim();
                                        if(search !== null || search !== ""){
                                            var link = "{{ url('mapped_roles') . '/' . $roleType }}" + "/" + search;
                                            request_role_data(link);
                                        }
                                    }
                                    function request_role_data(link){
                                        $roles = $.ajax({
                                            type        : 'GET',
                                            url         : link,
                                            beforeSend: function(){
                                                $("td#load_data").css({'display': 'table-cell'});
                                            },
                                            success     : function(res){
                                                console.log(res);
                                                $("tbody#render").html(res);
                                            },
                                            complete:function(data){
                                                $("td#load_data").css({'display': 'none'});
                                            },
                                            error       : function(xhr, textStatus, errorThrown){
                                                console.log(errorThrown, textStatus);
                                            }
                                        });
                                    }
                                </script>
                            @endsection
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection