@extends('layouts.master')
  @section('page_title')
      @if(isset($page_title))
          {{ $page_title }}
      @endif
  @endsection

@section('content')
  <div class="">
      <div class="page-title">
        <div class="title_left">
          <div class="title_left">
            <ol class="breadcrumb">
              <li><a href="{!! url('dashboard') !!}">Dashboard</a></li>
              <li><a href="{!! url('clients') !!}">Clients</a></li>
              <li class="active">Short Codes </li>
            </ol>
          </div>
        </div>

        <div class="title_right">

          <div class="row">
              <div class="col-sm-12">
              <div class="pull-right">
              </div>
              </div>
          </div>
        </div>
      </div>

      <div class="clearfix"></div>
      <div class="row">
        @include('commons.notifications')
        <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
          <div class="x_title">
            <h2> Client Short Codes </h2>
            <div class="pull-right">
                <!-- <a class="btn btn-primary btn-sm" href="{!! url('clients/create') !!}"><i class="fa fa-plus-circle"></i> Add Client</a> -->
            </div>
            <div class="clearfix"></div>
          </div>

          <div class="x_content">
            <div class="col-md-12" style="border: 1px solid; min-height: 500px;">
                <div role="tabpanel" class="tab-pane fade active in" id="tabSmsShortCode" aria-labelledby="smsshortcode-tab">
                      <h4 class="lead"><strong>
                      @if($type == 'voice')
                        {{ ucfirst($type) }} Short Code
                      @else
                        {{ strtoupper($type) }} Short Code
                      @endif
                    </strong></h4>
                    <?php //dump($codes_data) ?>
                      @include('client.partials.shortcode-index')
                    </div>
              </div>
          </div>
        </div>
      </div>
    </div>
</div>

@endsection

@section('javascript')
<script src="{!! url('public/assets/vendors/tabulator/js/tabulator.js') !!}"></script>
<script type="text/javascript" src="{!! url('public/assets/vendors/tabulator/js/xlsx.full.min.js') !!}"></script>
<script type="text/javascript" src="{!! url('public/assets/vendors/tabulator/js/jspdf.min.js') !!}"></script>
<script type="text/javascript" src="{!! url('public/assets/vendors/tabulator/js/jspdf.plugin.autotable.js') !!}"></script>

<script type="text/javascript">
  $(document).ready(function(){
    function link(cell, formatterParams){
      var url = cell.getValue();
      var rowID = cell.getData().id
      return "<a href='"+ base_url + "/clients/"+rowID+"' class='btn btn-link'>"+url+"</a>";
      //return '<a href="'+ base_url + '"/clients/"'+rowID+'" class="btn btn-link">'+ url +'</a>';
    }
    var table = new Tabulator("#clientsTable", {
        ajaxURL: "clients/all",
        paginationSize: 15,
        layout: "fitColumns",
        pagination: "remote",
        selectable: false,
        printAsHtml: true,
        ajaxLoaderLoading: $('#logo_spinner').html(),
        columns: [
            {
                title: "Client",
                field: "name",
                sorter: "string",
                formatter:link,
            },
            {
                title: "Account Manager",
                field: "accountMgr",
                sorter: "string",
            },
            /*
            {   title:"Onboarding Progress Score",
                field:"progress_indicator_score",
                sorter:"number",
                hozAlign:"left",
                formatter:"progress",
                width:200,
                editable:true
            },
            */
            {   title:"Onboarding %",
                field:"progress_indicator_score",
                sorter:"number",
            },
            {
                title: "Status",
                field: "status",
                sorter: "string",
            },
            {
                title: "Country",
                field: "country",
                sorter: "string",
            },
            {
                title: "Flag",
                field: "theflag",
                download: false,
                formatter:"image", formatterParams:{
                    height:"20px",
                    width:"30px",
                    // urlPrefix:"http://website.com/images/",
                    // urlSuffix:".png",
                  }
            },
            {
                title: "Last Modified By",
                field: "modifiedBy",
                sorter: "string",
            }
        ],
        // $('#clients-download-xlsx').click(function(){
        //   table.download("xlsx", "client-list.xlsx", {sheetName:"Sheet 1"});
        // });

        rowClick:function(e, row){
        var userID = row.getData().id;
        //$('#userEditModal').modal('show');
        },
    });
    document.getElementById("clients-download-xlsx").addEventListener("click", function(){
      table.download("xlsx", "client-list.xlsx", {sheetName:"Sheet 1"});
    });
        //trigger download of data.pdf file
    document.getElementById("clients-download-pdf").addEventListener("click", function(){
      table.download("pdf", "client-list.pdf", {
          orientation:"portrait", //set page orientation to portrait
          title:"Click Mobile - Clients", //add title to report
      });
    });

    $('#keywordField').on('keyup', function(){
      console.log('up');
      var keyword = $(this).val();
      table.setData("clients/all?keyword=" + keyword);

    });

});

</script>
@endsection
