
<script>
    $(document).ready(function() {

        $("#{{$table['id']}}").on( 'click', 'tbody td',function (e) {

        });
        console.log($main_tab_content.find('#{{$table['id']}}'))
        $main_tab_content.find('#{{$table['id']}}').on( 'click', 'tbody td>.dropdown>.dropdown-menu a.list-ajustements',function (e) {
            {{--getAdjustmentsByWarehouse($(this).attr("data-id-stock"),'{{$type}}')--}}
        });

        $main_tab_content.find('#{{$table['id']}}').on( 'click', 'tbody td.qty-editable>span,' +
            ' tbody td>.dropdown>.dropdown-menu a.ajuster-stock', function (e) {
            {{--makeAdjustment($(this).attr("data-id-stock"),'{{$type}}');--}}
        } );

        $('#{{$table['id']}}').on( 'click', 'tbody td', function (e) {
            let tableId = "{{$table['id']}}";
            let table = $("#"+tableId).DataTable();
            let editor = updateRowStockEditor;
            let $td = $(this);
            let  index = $td.index();
            let rowData = table.row($td).data();
            let msg =  rowData.product.fullName;
            editor.s.table = "#"+tableId;

            @can('st-adjustment-create')
                if ( index === 3 ) { // colonne 'qty'
                    //  editor = createAdjustmentEditor;
                    loadEditorCreateAdjustment(rowData,tableId)
                    // editor.s.table = "#"+tableId;
                    // editor.create();
                }
            @endcan


            @can("st-stock-update")
                if ( index === 0 ) { // colonne 'lot_id'
                editor.s.ajax.url  = "{{route("admin.stocks.edit.lot-id")}}";
                    editor.bubble( $td,["lot_id"], {
                        message: msg,
                        buttons: {
                            label: '{{__("OK")}}',
                            className:"btn-primary btn-sm fs-11",
                            fn: function () {
                                this.submit(
                                    function (data) {
                                        if(typeof data === 'object' && !$.isEmptyObject(data)){
                                            if(data.success){
                                                refresh_datatable(tableId);
                                            }
                                        }
                                    },
                                );
                            },
                        },
                    } );
                }
                else if(index === 5){ // colonne 'expired_at'
                editor.s.ajax.url  = "{{route("admin.stocks.edit.expired-at")}}";
                editor.bubble( $td,["expired_at"], {
                    message: msg,
                    buttons: {
                        label: '{{__("OK")}}',
                        className:"btn-primary btn-sm fs-11",
                        fn: function () {
                            this.submit(
                                function (data) {
                                    if(typeof data === 'object' && !$.isEmptyObject(data)){
                                        if(data.success){
                                            refresh_datatable(tableId);
                                        }
                                    }
                                },
                            );
                        },
                    },
                } );
            }
            @endcan

        } );

    } );
</script>
<div class="card-body">
    <div class="col-lg-12 form-group table-responsive">
        <table class="table table-striped table-bordered" id="{{$table['id']}}" style="width: 100%">
            <thead>
                <tr>
                    <th class="left">{{__("Lot Id")}}</th>
                    <th class="left">{{__("Product Id")}}</th>
                    <th class="left">{{__("Product Name")}}</th>
                    <th class="right">{{__("Qty")}}</th>
{{--                    <th class="right">{{__("Qté Seuille")}}</th>--}}
                    <th class="left">{{__("Category")}}</th>
                    <th class="left">{{__("Expired At")}}</th>
                    @canany(["st-adjustment-create","st-adjustment-list",])
{{--                        <th class="left">{{__("Action")}}</th>--}}
                    @endcanany
                </tr>
            </thead>
        </table>
    </div>
</div>


