@extends('admin.layouts.app')


@section('content')
    <section class="section">
        <div class="section-header">
            <h1>{{ $pageTitle }}</h1>
            <div class="section-header-breadcrumb">
                <div class="breadcrumb-item active"><a href="/admin/">{{ trans('admin/main.dashboard') }}</a></div>
                <div class="breadcrumb-item">{{ $pageTitle }}</div>
            </div>
        </div>

        <div class="section-body">

            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-8 col-lg-6">
                                    <form action="/admin/store/settings" method="post">
                                        {{ csrf_field() }}
                                        <input type="hidden" name="page" value="general">
                                        <input type="hidden" name="name" value="{{ \App\Models\Setting::$storeSettingsName }}">

                                        <h5 class="mb-3">{{ trans('update.books_settings') }}</h5>

                                        <div class="form-group custom-switches-stacked">
                                            <label class="custom-switch pl-0 d-flex align-items-center">
                                                <input type="hidden" name="value[books_status]" value="0">
                                                <input type="checkbox" name="value[books_status]" id="booksStatusSwitch" value="1" {{ (!empty($itemValue) and !empty($itemValue['books_status']) and $itemValue['books_status']) ? 'checked="checked"' : '' }} class="custom-switch-input"/>
                                                <span class="custom-switch-indicator"></span>
                                                <label class="custom-switch-description mb-0 cursor-pointer" for="booksStatusSwitch">{{ trans('update.books_enable') }}</label>
                                            </label>
                                            <div class="text-muted text-small">{{ trans('update.books_enable_hint') }}</div>
                                        </div>

                                        <div class="form-group">
                                            <label for="books_per_page">{{ trans('update.books_per_page') }}</label>
                                            <input type="number" name="value[books_per_page]" id="books_per_page" value="{{ (!empty($itemValue) and !empty($itemValue['books_per_page'])) ? $itemValue['books_per_page'] : 24 }}" class="form-control text-center" min="1" max="100"/>
                                            <div class="text-muted text-small mt-1">{{ trans('update.books_per_page_hint') }}</div>
                                        </div>

                                        <div class="form-group">
                                            <label for="booksProductsSelect">{{ trans('update.books_products') }}</label>
                                            <select name="value[books_products][]" id="booksProductsSelect" class="form-control select2" multiple>
                                                @foreach($allProducts as $product)
                                                    <option value="{{ $product->id }}" {{ (in_array($product->id, $selectedBooksProducts)) ? 'selected' : '' }}>
                                                        {{ $product->title }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            <div class="text-muted text-small mt-1">{{ trans('update.books_products_hint') }}</div>
                                        </div>

                                        <button type="submit" class="btn btn-primary mt-1">{{ trans('admin/main.submit') }}</button>
                                    </form>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

@push('scripts_bottom')
    <script>
        $(document).ready(function() {
            $('#booksProductsSelect').select2({
                placeholder: '{{ trans('update.select_products') }}',
                allowClear: true,
                width: '100%'
            });
        });
    </script>
@endpush
