@extends('backend.layout.main') @section('content')
@if(session()->has('create_message'))
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('create_message') }}</div>
@endif
@if(session()->has('edit_message'))
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('edit_message') }}</div>
@endif
@if(session()->has('import_message'))
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('import_message') }}</div>
@endif
@if(session()->has('not_permitted'))
    <div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('not_permitted') }}</div>
@endif
@if(session()->has('message'))
    <div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('message') }}</div>
@endif
@if($errors->any())
    <div class="alert alert-danger alert-dismissible text-center">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        {{ $errors->first() }}
    </div>
@endif

<section>
    <div class="container-fluid">
        @if(in_array("Tailoring-add", $all_permission))
            <a href="{{route('tailoringproducts.create')}}" class="btn btn-info add-product-btn"><i class="dripicons-plus"></i> {{__('file.add_order')}}</a>
        @endif
    </div>
    <div class="table-responsive">
        <table id="product-data-table" class="table" style="width: 100%">
            <thead>
                <tr>
                    <th class="not-exported"></th>
                    <th>{{trans('file.Code')}}</th>
                    <th>{{trans('file.Customer Name')}}</th>
                    <th>{{trans('file.Customer Phone')}}</th>
                    <th>{{trans('file.category')}}</th>
                    <th>{{trans('file.Status')}}</th>
                    <th>{{trans('file.Total_Price')}}</th>
                    <th>{{trans('file.Paid Amount')}}</th>
                    <th>{{trans('file.Due Amount')}}</th>
                    <th>{{trans('file.Issue Date')}}</th>
                    <th>{{trans('file.Completion Date')}}</th>
                    <th class="not-exported">{{trans('file.action')}}</th>
                </tr>
            </thead>
        </table>
    </div>
</section>



<div id="product-details" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
    <div role="document" class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 id="exampleModalLabel" class="modal-title">{{trans('Product Details')}}</h5>
          <a id="print-btn" target="_blank" class="btn btn-default btn-sm ml-3" href="">
                <i class="fa fa-print"></i> {{trans('file.Print')}}
            </a>

          <button type="button" id="close-btn" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true"><i class="dripicons-cross"></i></span></button>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-5 offset-1" id="product-content"></div>
                <div class="col-md-5 offset-1" id="customer-content"></div>
            </div>

            <h5 id="combo-header"></h5>
            <div class="row" style="background-color: #f3f2f7;">
                <div class="col-1 border py-2">#</div>
                <div class="col-3 border py-2">{{ trans('file.Order') }}</div>
                <div class="col-2 border py-2">{{ trans('file.Tailors') }}</div>
                <div class="col-2 border py-2">{{ trans('file.Unit Price') }}</div>
                <div class="col-1 border py-2">{{ trans('file.Qty') }}</div>
                <div class="col-2 border py-2">{{ trans('file.Total') }}</div>
                <div class="col-1 border py-2">{{ trans('file.details') }}</div>
            </div>
            <div class="details_rows_container" id="details_rows_container">

            </div>

        </div>
      </div>
    </div>
</div>

<div id="reorder-modal" tabindex="-1" role="dialog" aria-labelledby="reorder-modal-title" aria-hidden="true" class="modal fade text-left">
    <div role="document" class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <form id="reorder-form" method="POST" action="">
                @csrf
                <div class="modal-header">
                    <div>
                        <h5 id="reorder-modal-title" class="modal-title">{{ trans('file.Re-order') }}</h5>
                        <small class="text-muted">{{ trans('file.Order') }} <span id="reorder-order-code"></span></small>
                    </div>
                    <button type="button" data-dismiss="modal" aria-label="{{ trans('file.Close') }}" class="close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group mb-0">
                        <label for="reorder-note">{{ trans('file.Re-order Note') }} *</label>
                        <textarea id="reorder-note" name="note" rows="5" maxlength="2000" required
                                  class="form-control"
                                  placeholder="{{ trans('file.Describe the changes the tailor must make') }}"></textarea>
                        <small class="form-text text-muted">{{ trans('file.This note will be visible to the tailor') }}</small>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">{{ trans('file.Cancel') }}</button>
                    <button type="submit" class="btn btn-warning">
                        <i class="fa fa-repeat"></i> {{ trans('file.Send Back to Tailor') }}
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div id="reorder-history-modal" tabindex="-1" role="dialog" aria-labelledby="reorder-history-title" aria-hidden="true" class="modal fade text-left">
    <div role="document" class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <div>
                    <h5 id="reorder-history-title" class="modal-title">{{ trans('file.Re-order History') }}</h5>
                    <small class="text-muted">{{ trans('file.Order') }} <span id="reorder-history-code"></span></small>
                </div>
                <button type="button" data-dismiss="modal" aria-label="{{ trans('file.Close') }}" class="close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div id="reorder-history-content" class="modal-body"></div>
        </div>
    </div>
</div>
@endsection
@push('scripts')
<script>
    $("ul#tailoring").siblings('a').attr('aria-expanded','true');
    $("ul#tailoring").addClass("show");
    $("ul#tailoring #tailoringproductcompleted-list-menu").addClass("active");


$(document).ready(function () {
    // Hide all toggler sections initially
    $('#details_rows_container').find('.order_details_toggler').hide();

    // Delegate click event for dynamically added toggles
    $('#details_rows_container').on('click', '.order_details_toggle', function () {
        const toggler = $(this).parent().next('.order_details_toggler');
        const icon = $(this).find('i');

        // Hide all togglers and reset icons
        $('.order_details_toggler').hide(100);
        $('#details_rows_container .order_details_toggle i').removeClass('fa-minus').addClass('fa-plus');

        // Toggle the clicked one
        if (toggler.is(':visible')) {
            toggler.hide(300);
            icon.removeClass('fa-minus').addClass('fa-plus');
        } else {
            toggler.show(300);
            icon.removeClass('fa-plus').addClass('fa-minus');
        }


    });
});







    // @if(config('database.connections.winsoft'))
    //     if(localStorage.getItem("message")) {
    //         alert(localStorage.getItem("message"));
    //         localStorage.removeItem("message");
    //     }

    //     numberOfProduct = <?php echo json_encode($numberOfProduct)?>;
    //     $.ajax({
    //         type: 'GET',
    //         async: false,
    //         url: '{{route("package.fetchData", $general_setting->package_id)}}',
    //         success: function(data) {
    //             if(data['number_of_product'] > 0 && data['number_of_product'] <= numberOfProduct) {
    //                 $("a.add-product-btn").addClass('d-none');
    //             }
    //         }
    //     });
    // @endif

    function confirmDelete() {
        if (confirm("Are you sure want to delete?")) {
            return true;
        }
        return false;
    }

    var warehouse = [];
    var variant = [];
    var qty = [];
    var htmltext;
    var slidertext;
    var product_id = [];
    var all_permission = <?php echo json_encode($all_permission) ?>;
    var role_id = <?php echo json_encode($role_id) ?>;
    var user_verified = <?php echo json_encode(env('USER_VERIFIED')) ?>;
    var logoUrl = <?php echo json_encode(url('logo', $general_setting->site_logo)) ?>;

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(document).on('click', '.reorder-order', function() {
        var routeTemplate = @json(route('tailoringproducts.reorder', ':id'));
        $('#reorder-form').attr('action', routeTemplate.replace(':id', $(this).data('id')));
        $('#reorder-order-code').text($(this).data('code'));
        $('#reorder-note').val('');
        $('#reorder-modal').modal('show');
    });

    $(document).on('click', '.view-reorder-history', function() {
        var routeTemplate = @json(route('tailoringproducts.reorders', ':id'));
        var content = $('#reorder-history-content').empty();
        $('#reorder-history-code').text($(this).data('code'));
        content.append($('<p>', { class: 'text-muted mb-0', text: @json(trans('file.Loading')) }));
        $('#reorder-history-modal').modal('show');

        $.get(routeTemplate.replace(':id', $(this).data('id')), function(response) {
            content.empty();
            if (!response.reorders.length) {
                content.append($('<p>', { class: 'text-muted mb-0', text: @json(trans('file.No re-order history')) }));
                return;
            }

            response.reorders.forEach(function(item) {
                var entry = $('<div>', { class: 'border-bottom pb-3 mb-3' });
                entry.append($('<div>', { class: 'd-flex justify-content-between mb-2' })
                    .append($('<strong>').text(item.reordered_at))
                    .append($('<span>', { class: 'text-muted' }).text(item.reordered_by)));
                entry.append($('<p>', { class: 'mb-2', css: { whiteSpace: 'pre-wrap' } }).text(item.note));
                entry.append($('<small>', { class: item.resolved_at ? 'text-success' : 'text-warning' })
                    .text(item.resolved_at
                        ? @json(trans('file.Correction finished on')) + ' ' + item.resolved_at
                        : @json(trans('file.Waiting for correction'))));
                content.append(entry);
            });
        });
    });

    $( "#select_all" ).on( "change", function() {
        if ($(this).is(':checked')) {
            $("tbody input[type='checkbox']").prop('checked', true);
        }
        else {
            $("tbody input[type='checkbox']").prop('checked', false);
        }
    });

    $(document).on("click", "tr.product-link td:not(:first-child, :last-child)", function() {
        productDetails( $(this).parent().data('product') );
    });

    $(document).on("click", ".view", function(){
        var product = $(this).parent().parent().parent().parent().parent().data('product');
        productDetails(product);
    });



    function productDetails(product) {
        htmltext = customertext = detailscontainer = '';

        htmltext = '<p><strong>{{trans("file.Code")}}: </strong>'+product[0]+'</p><p><strong>{{trans("file.category")}}: </strong>'+product[1]+ '</p><p><strong>{{trans("file.order type")}}: </strong>'+product[2]+ '</p><p><strong>{{trans("file.Total_Price")}}: </strong>'+product[3]+'</p><p><strong>{{trans("file.Paid Amount")}}: </strong>'+product[4]+'</p><p><strong>{{trans("file.Due Amount")}}: </strong>'+product[5]+'</p><p><strong>{{trans("file.Issue Date")}}: </strong>'+product[6]+'</p><p><strong>{{trans("file.Completion Date")}}: </strong>'+product[7]+'</p>';
        customertext =`<h3 class='mb-2 mt-1'><strong>{{trans("file.Customer Information")}}</strong></h3><p class='mt-3'><strong>{{trans("file.Customer Name")}}: </strong>${product[8]}</p><p><strong>{{trans("file.Customer Phone")}}: </strong>${product[9]}</p><p><strong>{{trans("file.Address")}}: </strong>${product[10]}, ${product[11]}</p>`;

        if(product[1] == 'Suit'){
            if(product[13]){

                detailscontainer = `<div class="row">
                <div class="col-1 border py-2">${Number(product[14])}</div>
                <div class="col-3 border py-2">${product[15].toString()}</div>
                <div class="col-2 border py-2">${product[16]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2">${product[88]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2 text-center order_details_toggle"><button><i class="fa fa-plus"></i></button></div>
                </div>
                <div class="row order_details_toggler" style='display:none;'>
                    <div class="col-12 px-3">
                        <div class="row" style="background-color: #f3f2f7;">
                            <div class="col-6 border py-2">{{ trans('file.Waiscoat Size') }}</div>
                            <div class="col-6 border py-2">{{ trans('file.Waiscoat Design') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Waiscoat Height') }}</div>
                            <div class="col-2 border py-2 text-center">${product[18]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design V-Neck Collar') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[24] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Waiscoat Shoulder') }}</div>
                            <div class="col-2 border py-2 text-center">${product[19]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design Round Neck Collar') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[25] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Waiscoat Side') }}</div>
                            <div class="col-2 border py-2 text-center">${product[20]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design Pakistani Collar') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[26] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Waiscoat Waist') }}</div>
                            <div class="col-2 border py-2 text-center">${product[21]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design Zippered Pocket') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[27] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Waiscoat Abdomen') }}</div>
                            <div class="col-2 border py-2 text-center">${product[22]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design Plain Pocket') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[28] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Waiscoat Hip') }}</div>
                            <div class="col-2 border py-2 text-center">${product[23]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design Four Side Pockets') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[29] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.vest_chest_circumference') }}</div>
                            <div class="col-2 border py-2 text-center">${product[96]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Design Two Side Pockets') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[30] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Order Details') }}</div>
                            <div class="col-10 border py-2">${product[84]} </div>
                        </div>

                    </div>

                </div>`;
            }
            if(product[31]) {

                detailscontainer += `<div class="row">
                <div class="col-1 border py-2">${Number(product[32])}</div>
                <div class="col-3 border py-2">${product[33].toString()}</div>
                <div class="col-2 border py-2">${product[34]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2">${product[90]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2 text-center order_details_toggle"><button><i class="fa fa-plus"></i></button></div>
                </div>
                <div class="row order_details_toggler" style='display:none;'>
                    <div class="col-12 px-3">
                        <div class="row" style="background-color: #f3f2f7;">
                            <div class="col-6 border py-2">{{ trans('file.Coat Size') }}</div>
                            <div class="col-6 border py-2">{{ trans('file.Coat Design') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Height') }}</div>
                            <div class="col-2 border py-2 text-center">${product[36]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Coat Style One Button') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[50] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Shoulder') }}</div>
                            <div class="col-2 border py-2 text-center">${product[37]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Coat Style Two Button') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[51] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Sleeve') }}</div>
                            <div class="col-2 border py-2 text-center">${product[38]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Coat Style three Button') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[52] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Armhole Circumference') }}</div>
                            <div class="col-2 border py-2 text-center">${product[39]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Bicep Circumference') }}</div>
                            <div class="col-2 border py-2 text-center">${product[40]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Cuff') }}</div>
                            <div class="col-2 border py-2 text-center">${product[41]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Side Width') }}</div>
                            <div class="col-2 border py-2 text-center">${product[42]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Waist') }}</div>
                            <div class="col-2 border py-2 text-center">${product[43]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Abdomen Circumference') }}</div>
                            <div class="col-2 border py-2 text-center">${product[44]} {{ trans('file.(cm)') }}</div>
                        </div><div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Hip Width') }}</div>
                            <div class="col-2 border py-2 text-center">${product[45]} {{ trans('file.(cm)') }}</div>
                        </div><div class="row">
                            <div class="col-4 border py-2">{{ trans('file.UpperBody Front Length') }}</div>
                            <div class="col-2 border py-2 text-center">${product[46]} {{ trans('file.(cm)') }}</div>
                        </div><div class="row">
                            <div class="col-4 border py-2">{{ trans('file.UpperBody Back Length') }}</div>
                            <div class="col-2 border py-2 text-center">${product[47]} {{ trans('file.(cm)') }}</div>
                        </div><div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Chest Distance') }}</div>
                            <div class="col-2 border py-2 text-center">${product[48]} {{ trans('file.(cm)') }}</div>
                        </div><div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Coat Collar') }}</div>
                            <div class="col-2 border py-2 text-center">${product[49]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Order Details') }}</div>
                            <div class="col-10 border py-2">${product[85]} </div>
                        </div>

                    </div>

                </div>`;
            }

            if(product[53]) {
                detailscontainer += `<div class="row">
                <div class="col-1 border py-2">${Number(product[54])}</div>
                <div class="col-3 border py-2">${product[55].toString()}</div>
                <div class="col-2 border py-2">${product[56]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2">${product[92]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2 text-center order_details_toggle"><button><i class="fa fa-plus"></i></button></div>
                </div>
                <div class="row order_details_toggler" style='display:none;'>
                    <div class="col-12 px-3">
                        <div class="row" style="background-color: #f3f2f7;">
                            <div class="col-6 border py-2">{{ trans('file.Pant Size') }}</div>
                            <div class="col-6 border py-2">{{ trans('file.Pant Design') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Pant Length') }}</div>
                            <div class="col-2 border py-2 text-center">${product[58]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Pant Straight Loose') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[64] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-3 border py-2">{{ trans('file.Pant Waist') }}</div>
                            <div class="col-3 border py-2 text-center">${product[59]}</div>
                            <div class="col-5 border py-2">{{ trans('file.Pant Straight Medium') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[65] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Pant Thigh') }}</div>
                            <div class="col-2 border py-2 text-center">${product[60]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Pant Straight Military') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[66] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Pant Rise') }}</div>
                            <div class="col-2 border py-2 text-center">${product[61]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Pant Straight Cuban Pocket') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[67] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Pant Hem') }}</div>
                            <div class="col-2 border py-2 text-center">${product[62]} {{ trans('file.(cm)') }}</div>
                            <div class="col-5 border py-2">{{ trans('file.Pant Straight Classic') }}</div>
                            <div class="col-1 border py-2 text-center"><i class="${product[68] == '1' ? 'fa fa-check': 'dripicons-cross'}"></i></div>{{-- dripicons-cross --}}
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Pant Hip') }}</div>
                            <div class="col-2 border py-2 text-center">${product[63]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.trouser_crotch_depth') }}</div>
                            <div class="col-2 border py-2 text-center">${product[97]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Order Details') }}</div>
                            <div class="col-10 border py-2">${product[86]} </div>
                        </div>

                    </div>

                </div>`;
            }

        }else if(product[1] == 'Curtain'){
            detailscontainer += `<div class="row">
                <div class="col-1 border py-2">${Number(product[100])}</div>
                <div class="col-3 border py-2">${product[101].toString()}</div>
                <div class="col-2 border py-2">${product[102]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2">${product[118]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2 text-center order_details_toggle"><button><i class="fa fa-plus"></i></button></div>
                </div>
                <div class="row order_details_toggler" style='display:none;'>
                    <div class="col-12 px-3">
                        <div class="row" style="background-color: #f3f2f7;">
                            <div class="col-12 border py-2 text-center">{{ trans('file.Curtain Information') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Fabric Type') }}</div>
                            <div class="col-2 border py-2 text-center">${product[104]}</div>
                            <div class="col-4 border py-2">{{ trans('file.Netting Type') }}</div>
                            <div class="col-2 border py-2 text-center">${product[105]}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Window Count') }}</div>
                            <div class="col-2 border py-2 text-center">${product[120]}</div>
                            <div class="col-4 border py-2">{{ trans('file.Door Count') }}</div>
                            <div class="col-2 border py-2 text-center">${product[121]}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Curtain Panels') }}</div>
                            <div class="col-2 border py-2 text-center">${product[106]}</div>
                            <div class="col-4 border py-2">{{ trans('file.Panel Meter') }}</div>
                            <div class="col-2 border py-2 text-center">${product[107]}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Window Measurements') }}</div>
                            <div class="col-10 border py-2">${product[122] || ''}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Door Requirements') }}</div>
                            <div class="col-10 border py-2">${product[124] || ''}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Middle Netting') }}</div>
                            <div class="col-2 border py-2 text-center">${product[108]}</div>
                            <div class="col-4 border py-2">{{ trans('file.Sewing Type') }}</div>
                            <div class="col-2 border py-2 text-center">${[product[109], product[110]].filter(Boolean).join('، ')}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Curtain Model') }}</div>
                            <div class="col-8 border py-2 text-center">${product[111]}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Mattress Count') }}</div>
                            <div class="col-2 border py-2 text-center">${product[112]}</div>
                            <div class="col-4 border py-2">{{ trans('file.Pillow Count') }}</div>
                            <div class="col-2 border py-2 text-center">${product[113]}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Bolster Count') }}</div>
                            <div class="col-2 border py-2 text-center">${product[114]}</div>
                            <div class="col-4 border py-2">{{ trans('file.Mattress & Pillow Size') }}</div>
                            <div class="col-2 border py-2 text-center">${product[115]}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Pillow & Mattress Model') }}</div>
                            <div class="col-8 border py-2">${product[116]}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Bedding Details') }}</div>
                            <div class="col-10 border py-2">${product[123] || ''}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Order Details') }}</div>
                            <div class="col-10 border py-2">${product[117]} </div>
                        </div>
                    </div>
                </div>`;
        }else{
            detailscontainer += `<div class="row">
                <div class="col-1 border py-2">${Number(product[69])}</div>
                <div class="col-3 border py-2">${product[70].toString()}</div>
                <div class="col-2 border py-2">${product[71]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2">${product[94]}</div>
                <div class="col-2 border py-2">${product[3]}</div>
                <div class="col-1 border py-2 text-center order_details_toggle"><button><i class="fa fa-plus"></i></button></div>
                </div>
                <div class="row order_details_toggler" style='display:none;'>
                    <div class="col-12 px-3">
                        <div class="row" style="background-color: #f3f2f7;">
                            <div class="col-12 border py-2 text-center">{{ trans('file.Dress Size') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Dress Shirt Length') }}</div>
                            <div class="col-2 border py-2 text-center">${product[73]} {{ trans('file.(cm)') }}</div>
                            <div class="col-4 border py-2">{{ trans('file.Dress Sleeve') }}</div>
                            <div class="col-2 border py-2 text-center">${product[74]} {{ trans('file.(cm)') }}</div>

                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Dress Shoulder Width') }}</div>
                            <div class="col-2 border py-2 text-center">${product[75]} {{ trans('file.(cm)') }}</div>
                            <div class="col-4 border py-2">{{ trans('file.Dress Collar') }}</div>
                            <div class="col-2 border py-2 text-center">${product[76]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Dress Side Width') }}</div>
                            <div class="col-2 border py-2 text-center">${product[77]} {{ trans('file.(cm)') }}</div>
                            <div class="col-4 border py-2">{{ trans('file.Dress Armhole Circumference') }}</div>
                            <div class="col-2 border py-2 text-center">${product[78]} {{ trans('file.(cm)') }}</div>

                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Dress Waist') }}</div>
                            <div class="col-2 border py-2 text-center">${product[79]} {{ trans('file.(cm)') }}</div>
                            <div class="col-4 border py-2">{{ trans('file.Dress Hem') }}</div>
                            <div class="col-2 border py-2 text-center">${product[80]} {{ trans('file.(cm)') }}</div>

                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Dress Skirt Length') }}</div>
                            <div class="col-2 border py-2 text-center">${product[81]} {{ trans('file.(cm)') }}</div>
                            <div class="col-4 border py-2">{{ trans('file.Dress Cuff') }}</div>
                            <div class="col-2 border py-2 text-center">${product[82]} {{ trans('file.(cm)') }}</div>

                        </div>
                        <div class="row">
                            <div class="col-4 border py-2">{{ trans('file.Dress Skirt Width') }}</div>
                            <div class="col-2 border py-2 text-center">${product[83]} {{ trans('file.(cm)') }}</div>
                            <div class="col-4 border py-2">{{ trans('file.shirt_trouser_crotch_depth') }}</div>
                            <div class="col-2 border py-2 text-center">${product[98]} {{ trans('file.(cm)') }}</div>
                        </div>
                        <div class="row">
                            <div class="col-2 border py-2">{{ trans('file.Order Details') }}</div>
                            <div class="col-10 border py-2">${product[87]} </div>
                        </div>

                    </div>

                </div>`;
        }

        $("#combo-header").text('');
        $("table.item-list thead").remove();
        $("table.item-list tbody").remove();
        const printRouteTemplate = "{{ route('tailoringproducts.print', ':id') }}";
        const productId = product[12]; // or however you're storing the ID
        const printUrl = printRouteTemplate.replace(':id', productId);

        // Assign to button
        $('#print-btn').attr('href', printUrl);

        $('#product-content').html(htmltext);
        $('#customer-content').html(customertext);
        $('#details_rows_container').html(detailscontainer);
        $('#product-details').modal('show');
        $('#product-img-slider').carousel(0);
    }
    $('#print-select').on('change', function() {
        var printUrl = $(this).val(); // full route is stored in value

        if (printUrl) {
            var printWindow = window.open(printUrl, 'PrintWindow', 'width=600,height=400,top=100,left=100,resizable=yes,scrollbars=yes');
            if (printWindow) {
                printWindow.focus();
            }
        }
    });



    $(document).ready(function() {
        var table = $('#product-data-table').DataTable( {
            responsive: true,
            fixedHeader: {
                header: true,
                footer: true
            },
            "processing": true,
            "serverSide": true,
            "ajax":{
                url:"tailoringproductscompleted/product-data",
                data:{
                    all_permission: all_permission
                },
                dataType: "json",
                type:"post"
            },
            "createdRow": function( row, data, dataIndex ) {
                $(row).addClass('product-link');
                $(row).attr('data-product', data['product']);
            },
            "columns": [
                {"data": "key"},
                {"data": "code"},
                {"data": "customer_name"},
                {"data": "customer_phone"},
                {"data": "category"},
                {"data": "status"},
                {"data": "total_price"},
                {"data": "paid_amount"},
                {"data": "due_amount"},
                {"data": "issue_date"},
                {"data": "completion_date"},
                {"data": "options"},
            ],
            'language': {
                'searchPlaceholder': "{{trans('Type Customer Name, phone or Code...')}}",
                'lengthMenu': '_MENU_ {{trans("file.records per page")}}',
                 "info":      '<small>{{trans("file.Showing")}} _START_ - _END_ (_TOTAL_)</small>',
                "search":  '{{trans("file.Search")}}',
                'paginate': {
                        'previous': '<i class="dripicons-chevron-left"></i>',
                        'next': '<i class="dripicons-chevron-right"></i>'
                }
            },
            order:[['2', 'asc']],
            'columnDefs': [
                {
                    "orderable": false,
                    'targets': [ 0,1,3,4, 11]
                },
                {
                    'render': function(data, type, row, meta){
                        if(type === 'display'){
                            data = '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>';
                        }

                       return data;
                    },
                    'checkboxes': {
                       'selectRow': true,
                       'selectAllRender': '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>'
                    },
                    'targets': [0]
                }
            ],
            'select': { style: 'multi', selector: 'td:first-child'},
            'lengthMenu': [[10, 25, 50, -1], [10, 25, 50, "All"]],
            dom: '<"row"lfB>rtip',
            buttons: [
                {
                    extend: 'pdf',
                    text: '<i title="export to pdf" class="fa fa-file-pdf-o"></i>',
                    exportOptions: {
                        columns: ':visible:not(.not-exported)',
                        rows: ':visible',
                        stripHtml: false
                    },
                    customize: function(doc) {
                        for (var i = 1; i < doc.content[1].table.body.length; i++) {
                            if (doc.content[1].table.body[i][0].text.indexOf('<img src=') !== -1) {
                                var imagehtml = doc.content[1].table.body[i][0].text;
                                var regex = /<img.*?src=['"](.*?)['"]/;
                                var src = regex.exec(imagehtml)[1];
                                var tempImage = new Image();
                                tempImage.src = src;
                                var canvas = document.createElement("canvas");
                                canvas.width = tempImage.width;
                                canvas.height = tempImage.height;
                                var ctx = canvas.getContext("2d");
                                ctx.drawImage(tempImage, 0, 0);
                                var imagedata = canvas.toDataURL("image/png");
                                delete doc.content[1].table.body[i][0].text;
                                doc.content[1].table.body[i][0].image = imagedata;
                                doc.content[1].table.body[i][0].fit = [30, 30];
                            }
                        }
                    },
                },
                {
                    extend: 'excel',
                    text: '<i title="export to excel" class="dripicons-document-new"></i>',
                    exportOptions: {
                        columns: ':visible:not(.not-exported)',
                        rows: ':visible',
                        format: {
                            body: function ( data, row, column, node ) {
                                if (column === 0 && (data.indexOf('<img src=') !== -1)) {
                                    var regex = /<img.*?src=['"](.*?)['"]/;
                                    data = regex.exec(data)[1];
                                }
                                return data;
                            }
                        }
                    }
                },
                {
                    extend: 'csv',
                    text: '<i title="export to csv" class="fa fa-file-text-o"></i>',
                    exportOptions: {
                        columns: ':visible:not(.not-exported)',
                        rows: ':visible',
                        format: {
                            body: function ( data, row, column, node ) {
                                if (column === 0 && (data.indexOf('<img src=') !== -1)) {
                                    var regex = /<img.*?src=['"](.*?)['"]/;
                                    data = regex.exec(data)[1];
                                }
                                return data;
                            }
                        }
                    }
                },
                {
                    extend: 'print',
                    title: '',
                    text: '<i title="print" class="fa fa-print"></i>',
                    exportOptions: {
                        columns: ':visible:not(.not-exported)',
                        rows: ':visible',
                        stripHtml: false
                    },
                    repeatingHead: {
                        logo: logoUrl,
                        logoPosition: 'left',
                        logoStyle: '',
                        title: '<h3>Product List</h3>'
                    }
                    /*customize: function ( win ) {
                        $(win.document.body)
                            .prepend(
                                '<img src="http://datatables.net/media/images/logo-fade.png" style="margin:10px;" />'
                            );
                    }*/
                },
                {
                    text: '<i title="delete" class="dripicons-cross"></i>',
                    className: 'buttons-delete',
                    action: function ( e, dt, node, config ) {
                        if(user_verified == '1') {
                            product_id.length = 0;
                            $(':checkbox:checked').each(function(i){
                                if(i){
                                    var product_data = $(this).closest('tr').data('product');
                                    product_id[i-1] = product_data[13];
                                }
                            });
                            if(product_id.length && confirmDelete()) {
                                $.ajax({
                                    type:'POST',
                                    url:'{{ route("tailoringproducts.deletebyselection") }}',
                                    data:{
                                        productIdArray: product_id
                                    },
                                    success:function(data){
                                        //dt.rows({ page: 'current', selected: true }).deselect();
                                        dt.rows({ page: 'current', selected: true }).remove().draw(false);
                                    }
                                });
                            }
                            else if(!product_id.length)
                                alert('No product is selected!');
                        }
                        else
                            alert('This feature is disable for demo!');
                    }
                },
                {
                    extend: 'colvis',
                    text: '<i title="column visibility" class="fa fa-eye"></i>',
                    columns: ':gt(0)'
                },
            ],
        } );

    } );

    $('#print-btn').on('click', function(e) {
        e.preventDefault();
        var href = $(this).attr('href');
        var printWindow = window.open(href, 'PrintWindow', 'width=600,height=400,top=100,left=100,resizable=yes,scrollbars=yes');
        if (printWindow) {
            printWindow.focus();
        }
    });

    if(all_permission.indexOf("tailoring-delete") == -1)
        $('.buttons-delete').addClass('d-none');

    $('select').selectpicker();

</script>
@endpush
