@extends(branchMenu())
@section('content')
    <?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.new_product')}}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {!! Form::open(array('route' => 'cut-piece.store','method'=>'POST','enctype'=>'multipart/form-data','class'=>'jform')) !!}
            <div class="row" id="tabs">
                <div class="tab-content">
                    <div id="home" class="tab-pane fade in active">
                        <div class="col-sm-12">
                            <div class="master-form">
                                <div class="title-note">
                                    <h3>
                                        <span class="fa fa-exclamation-triangle"></span> {{__('administrator.create')}}
                                        <i>({{__('administrator.fields_in_red_are_required')}})</i></h3>
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-2 col-xs-12 ">
                                        <label class="required" for="name">{{__('administrator.item_name')}} </label>
                                    </div>
                                    <div class="col-sm-10 col-xs-12">
                                        {!! Form::text('product_name', null, array('placeholder' => __('administrator.item_name'),'class' => 'form-control input-sm','','maxlength'=>'50')) !!}
                                    </div>
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-2 col-xs-12 ">
                                        <label for="name" class="required">{{__('administrator.currency')}}</label>
                                    </div>
                                    <div class="col-sm-10 paddin-0">
                                        <div class="col-sm-12">
                                            {!! Form::select('currency', getCurrency(), @$product->currency, ['placeholder' => __('administrator.please_select'),'class' => 'form-control select2','']) !!}
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-10 col-xs-10 col-md-10 col-sm-offset-2 col-xs-offset-2 col-md-offset-2">
                                        <table class="table table-bordered">
                                            <thead>
                                            <tr>
                                                <th>#</th>
                                                <th><label for=""
                                                           class="required">{{__('administrator.qty_per_unit')}}</label>
                                                </th>
                                                <th><label for="" class="required">{{__('administrator.size')}}</label>
                                                </th>
                                                <th width="10%"><label for="" class="required">{{__('administrator.cost')}}</label> </th>
                                                <th><label for="" class="required">{{__('administrator.barcode')}}</label></th>
                                                <th style="text-align: center" width="5%"><span class="cursor button_success fa fa-plus" id="add_unit"></span></th>
                                            </tr>
                                            </thead>
                                            <tbody id="tbody">

                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-2 col-xs-12 ">
                                        <label for="name">{{__('administrator.qty_alert') }}<span id="unit_name" style="color:#c53d3d"></span></label>
                                    </div>
                                    <div class="col-sm-10 col-xs-12">
                                        {!! Form::text('qty_alert', @$product->qty_alert, array('placeholder' => __('administrator.qty_alert'),'class' => 'form-control input-sm')) !!}
                                    </div>
                                </div>
                                <div class="col-sm-12 col-xs-12 ">
                                    <div class="form-group footer-save">
                                        <button type="submit" class=" button_primary pull-right"><span
                                                    class="fa fa-save"></span> {{__('administrator.save')}}</button>
                                        <button type="button" onClick="history.go(-1)"
                                                class=" button_warning pull-right">
                                            <span class=" fa fa-arrow-circle-left"></span> {{__('administrator.back')}}
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {!! Form::close() !!}
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $(document).ready(function () {
            add_unit();
            $('#add_unit').on('click', function () {
                add_unit();
            });
            $(document).on('click', '.remove_row', function () {
                $(this).closest("tr").remove();
            });
        });
        $(document).on('change', '#get_selectUnit select', function () {
            let data = $(this).find(":selected").text();
            if (data != '') {
                $('#unit_name').text('(' + data + ')');
            }
        });
        function add_unit() {
            let count = $('#tbody tr').length;
            let row = `<tr>
                                        <td class="count_index` + (count + 1) + `">` + (count + 1) + `</td>
                                        <td><input name="qty[]" type="text" class="form-control input-sm number-only" value="1" placeholder="{{__('administrator.qty_per_unit')}}" readonly ></td>
                                        <td>
                                                   {!! Form::select('size_id[]', $size,null, ['placeholder' => __('administrator.size'),'class' => 'form-control size_id','']) !!}
                                        </td>
                                        <td><input name="cost[]" type="text" class="form-control input-sm number-only cost" placeholder="{{__('administrator.cost')}}" required></td>
                                        <td><input name="barcode_child[]" type="text" class="form-control input-sm number-only barcode_child" value="" placeholder="{{__('administrator.barcode')}}"></td>
                                        <td style="text-align: center"><span class="cursor button_danger fa fa-close remove_row" ></span></td>
                             </tr>`;
            $('#tbody').append(row);
            $('select').select2();
        }

    </script>
@endsection