@extends("layouts.members")
@section('page_title')
    Add Category
@endsection
@section('page_category')
    Content
@endsection
<!-- HEADER -->
@section('page_action')
    <!-- Button -->
    <a href="{{ route('binshopsblog.admin.categories.index') }}" class="btn btn-primary lift">
        All Categories
    </a>
@endsection
@section("content")

    <div class="container-fluid">
        <div class="row">
            <form method='post' action='{{route("binshopsblog.admin.categories.create_category")}}'
                  enctype="multipart/form-data">

                @csrf

                <div class="form-group">
                    <label for="language_list">Select Language</label>
                    <select id="language_list" name='lang_id' class='form-control'>
                        @foreach($language_list as $language)
                            <option value='{{$language->id}}'
                                    @if($language->id == $language_id)selected="selected" @endif>
                                {{$language->name}}
                            </option>
                        @endforeach


                    </select>
                </div>
                {{--{{dd($language_id)}}--}}
                <div class="form-group">
                    <label for="category_category_name">Category Name</label>

                    <input type="text"
                           class="form-control"
                           id="category_name"
                           oninput="populate_slug_field();"
                           required
                           aria-describedby="category_category_name_help"
                           name='category_name'
                           value="{{old("category_name",$category_translation->category_name)}}"
                    >

                    <small id="category_category_name_help" class="form-text text-muted">The name of the category
                    </small>
                </div>


                <div class="form-group">
                    <label for="category_slug">Category slug</label>
                    <input
                            maxlength='100'
                            pattern="[a-zA-Z0-9-]+"
                            type="text"
                            required
                            class="form-control"
                            id="category_slug"
                            oninput="SHOULD_AUTO_GEN_SLUG=false;"
                            aria-describedby="category_slug_help"
                            name='slug'
                            value="{{old("slug",$category_translation->slug)}}"
                    >

                    <small id="category_slug_help" class="form-text text-muted">
                        Letters, numbers, dash only. The slug
                        i.e. {{route("binshopsblog.view_category",[app('request')->get('locale'),""])}}
                        /<u><em>this_part</em></u>. This must be unique (two categories can't
                        share the same slug).

                    </small>
                </div>

                <div class="form-group">
                    <label for="category_slug">Category Tree</label>
                    <ul class="wtree">
                        @include("binshopsblog_admin::categories._category_partial", ['category_tree' => $cat_roots])
                    </ul>
                </div>

                <div class="form-group">
                    <label for="category_slug">Parent Category</label>
                    <select id="parent_id" name='parent_id' class='form-control'>
                        <option selected='selected' value='0'>
                            Root
                        </option>
                        @foreach($category_tree as $category)
                            <option value='{{$category->categoryTranslations[0]['category_id']}}'>
                                {{$category->categoryTranslations[0]['category_name']}}
                            </option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group">
                    <label for="category_description">Category Description (optional)</label>
                    <textarea name='category_description'
                              class='form-control'
                              id='category_description'>{{old("category_description",$category_translation->category_description)}}</textarea>

                </div>

                <button type="button" class='btn btn-primary' id="submit-btn">Add new category</button>
            </form>
        </div>
    </div>

@endsection

@section('page_script')
    @include('includes.customjs')
@endsection
