@extends('canteen.layouts.container')

@section('content')
    <div class="side-title">
        <h3>{{ $head ?? '' }}</h3>
    </div>

    <div class="border-item">
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}">
            @CSRF

            <div class="form-group col-lg-6">
                <label>{{ __('stocks.category_id') }} </label>
                <select onchange="categorySelect(this)" class="form-control {{ $errors->has('category_id') ? 'is-invalid' : '' }}" id="category_id" name="category_id">
                    <option value="">{{__('dashboard.select')}}</option>
                    @foreach($categories as $row)
                        <option value="{{$row->id}}">{{$row->title}}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ __('stocks.product_id') }} </label>
                <select class="form-control {{ $errors->has('product_id') ? 'is-invalid' : '' }}" id="product_id" name="product_id">
                    <option value="">{{__('dashboard.select')}}</option>
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('date', getCurrentLocale()) ?? __('stocks.date') }} </label>
                <input type="date" class="form-control {{ $errors->has('date') ? 'is-invalid' : '' }}" name="date" placeholder="{{ meta('date', getCurrentLocale()) ??__('stocks.date') }}" value='{{ old("date", $stock->date ?? "") }}'/>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ __('products.status') }} </label>
                <select class="form-control {{ $errors->has('status') ? 'is-invalid' : '' }}" id="status" name="status">
                    @foreach($statuses as $row)
                        <option value="{{$row}}">{{ __('stocks.statuses_action,'.$row) }}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('count', getCurrentLocale()) ?? __('stocks.count') }} </label>
                <input type="number" class="form-control {{ $errors->has('count') ? 'is-invalid' : '' }}" name="count" placeholder="{{ meta('count', getCurrentLocale()) ?? __('stocks.count') }}" value='{{ old("count", $stock->count ?? "") }}'/>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('price', getCurrentLocale()) ?? __('stocks.price') }} </label>
                <input type="number" step=".01" class="form-control {{ $errors->has('price') ? 'is-invalid' : '' }}" name="price" placeholder="{{ meta('price', getCurrentLocale()) ?? __('stocks.price') }}" value='{{ old("price", $stock->price ?? "") }}'/>
            </div>



            <div class="text-center mt-5 col-12">
                <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
            </div>
        </form>
    </div>

@endsection

@section('inner_js')
    <!-- Editor JS orders -->
    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
    <script>
        function categorySelect(elem)
        {
            let category_id = $(elem).val()
            $.ajax({
                url : url_products,
                type : 'GET',
                data : 'category_id='+category_id,
                success:function(data)
                {
                    $('#product_id').html(data)
                }
            })
        }
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_products = "{{route('canteen.product.fetch')}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
