@extends('layouts.app')
@section('content')
    <style>
        .file-drag-handle, .glyphicon-plus-sign, .kv-file-upload, .kv-file-download, .fileinput-upload {
            display: none !important;
        }
    </style>
    <?php Fun::lang() ?>

    <div class="page">
        <div class=container>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.fabric')}}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {!! Form::model($product, ['method' => 'PATCH','route' => ['fabric.update', $product->id],'enctype'=>'multipart/form-data','class'=>'jform']) !!}
            @include('administrator.setup-item.product-fabric.form')
            {!! Form::close() !!}
        </div>
        @endsection
        @section('script')
            <script>
                $(document).on('click', '.generate_row', function () {
                    let this_ = $(this).closest('tr');
                    let qty_per_unit = parseFloat(this_.find('input[name=qty_per_unit]').val());
                    let cost_usd = parseFloat(this_.find('input[name=cost_usd]').val());
                    let cost_baht = parseFloat(this_.find('input[name=cost_baht]').val());
                    let barcode = (this_.find('input[name=barcode]').val());
                    let total_row = parseFloat(this_.find('input[name=total_row]').val());
                    for (let i = 1; i <= total_row; i++) {
                        setTimeout(function () {
                            let count = $(document).find('#tbody tr').length;
                            let code = pad (count+qty_per_unit, 3);
                            let row  = '<tr class="tr2">' +
                                '<td>' + (count + 1) + '</td>' +
                                '<td><input name="qty[]" type="text" value="' + (qty_per_unit + count) + '" class="form-control input-sm number-only" placeholder="{{__('administrator.qty_per_unit')}}" required></td>' +
                                '<td><input name="cost_usd[]" value="' + (cost_usd) + '" type="text" class="form-control input-sm number-only" placeholder="{{__('administrator.cost')}}" required></td>' +
                                '<td><input name="cost_baht[]" value="' + (cost_baht) + '" type="text" class="form-control input-sm number-only" placeholder="{{__('administrator.cost')}}" required></td>' +
                                '<td><input name="barcode_child[]" value="' + (barcode +''+ code) + '" type="text" class="form-control input-sm" placeholder="{{__('administrator.barcode')}}" required></td>' +
                                '<td style="text-align: center"><span class="cursor button_danger fa fa-close remove_row" ></span></td>' +
                                '</tr>';
                            $('#tbody').append(row);
                        },100);
                    }
                });
            </script>
@endsection
