@extends('layouts.admin')
@section('title' ,$title)

@push("js")

    <script>
        var $card = $("#card-warehouse-management");
        var activeTableId = "table_1";

        // $card.find('.nav a[data-toggle="tab"]').on('shown.bs.tab', function(e){
        //     var $active_tab = $(e.target); // active tab
        //     let tableId = $active_tab.attr("data-table-id");
        //     activeTableId = tableId;
        //   //  let warehouseType = parseInt($active_tab.attr("data-warehouse-type"));
        //     let url = $active_tab.attr("data-url");
        //     refresh_datatable(tableId,url)
        // });

        {{--$('table.table').on('click', 'td button', function (e) {--}}
        {{--    e.preventDefault();--}}
        {{--    let table = $('#'+activeTableId).DataTable();--}}
        {{--    let editor = table.editor();--}}
        {{--    let $button = $(this);--}}
        {{--    let  $td = $button.parent();--}}
        {{--    let  index = $td.index();--}}
        {{--    let rowData = table.row($td).data();--}}

        {{--    if ( index === 7 ) { // colonne 'action'--}}
        {{--        if($button.hasClass("btn-edit-warehouse")){ // btn-edit--}}
        {{--            editor.edit( $button.closest('tr'), {--}}
        {{--                title: '{{__("Modification d'enregistrement")}}',--}}
        {{--                buttons: {--}}
        {{--                    className : "btn-primary",--}}
        {{--                    text : "{{__('Modifier')}}"+' <i class="fas fa-pencil-alt"></i>',--}}
        {{--                    action : function() { this.submit(); },--}}
        {{--                }--}}
        {{--            } );--}}
        {{--        }--}}
        {{--        if($button.hasClass("btn-remove-warehouse")){ // btn-delete--}}
        {{--            editor.remove( $button.closest('tr'), {--}}
        {{--                title: '{{__("Suppression d'enregistrement")}}',--}}
        {{--                message: '{{__("Supprimer l'enregistrement?")}}',--}}
        {{--                buttons: {--}}
        {{--                    className : "btn-danger",--}}
        {{--                    text : "{{__('Supprimer')}}"+' <i class="fas fa-trash"></i>',--}}
        {{--                    action : function() { this.submit(); },--}}
        {{--                }--}}
        {{--            } );--}}
        {{--        }--}}

        {{--    }--}}

        {{--} );--}}
    </script>
@endpush

@section('content')
<div class="card shadow mb-4" id="card-warehouse-management">
        <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
            <h6 class="m-0 font-weight-bold text-success">{{$title}}</h6>
        </div>
        <ul class="nav nav-tabs" id="tab-stocks-management" role="tablist">
            @foreach($menus as $index => $options)
                <li class="nav-item">
                    <a data-toggle="tab" role="tab"
                       class="nav-link {{($loop->first) ?"border-left-0 active show":""}}"
                       id="{{$options['id']}}"
                       href="#{{$options['href']}}"
                       data-table-id ="{{$options['content']['table']['id']}}"
                       data-warehouse-type ="{{$options['warehouse-type']}}"
                       data-url ="{{route("admin.stocks.warehouses.list",['warehouseType' => $options['warehouse-type']])}}"
                       aria-controls="{{$options['id']}}"
                       aria-selected="{{($loop->first) ?"true":"false"}}">
                        <span class="{{$options['icon'] }}"></span>
                        {{__($options['title'])}}
                    </a>
                </li>
            @endforeach
        </ul>

        <div class="tab-content" id="tab-content-warehouses-management">
            @foreach($menus as $index => $options)
                <div role="tabpanel"
                     class="tab-pane fade {{($loop->first) ?"active show":""}}"
                     id="{{$options['href']}}"
                     aria-labelledby="{{$options['id']}}">
                   <?php  $dataTable = new \App\DataTables\Warehouses\WarehouseDataTable($options['warehouse-type']);?>
                    {!! $dataTable->render("backend.stocks.warehouses.tabs.index") !!}
                </div>
            @endforeach
        </div>
    </div>
@endsection
