@extends('layouts.admin.app')
@section('title', __('trans.course.add_new'))

@section('content')
    <div class="card">

        <h5 class="card-header">

            <a href="@if (request('category_id')) {{ url('admin/courses') }}?category_id={{ request('category_id') }}
                    @else {{ url('admin/courses') }} @endif"
                class="btn rounded-pill btn-label-primary">
                <i class="ti me-2 ti-arrow-forward-up"></i> {{ __('trans.course.title') }}
            </a>
            @yield('title')
        </h5>

        <div class="card-body">

            <form action="{{ route('courses.store') }}" method="POST" enctype="multipart/form-data" id="myForm">
                @csrf
                <div class="row">

                    <div class="col-md-6 mb-3">
                        <label class="form-label">{{ __('trans.course.name') }} <b class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="title" value="{{ old('title') }}"
                            placeholder="{{ __('trans.course.name') }}" />
                    </div>

                    @if (!empty($categories))
                        <div class="col-md-6 mb-3">
                            <label class="form-label">{{ __('trans.category.name') }} <b class="text-danger">*</b></label>
                            <select name="category_id" class="form-select select2" required>
                                @foreach ($categories as $category)
                                    <option value="{{ $category->id }}">
                                        {{ $category->name }}
                                    </option>
                                @endforeach
                            </select>
                        </div>
                    @endif

                    @if (!empty($existedCategory))
                        <div class="col-md-6 mb-3">
                            <label class="form-label">{{ __('trans.category.name') }} <b class="text-danger">*</b></label>
                            <input type="hidden" name="category_id" value="{{ $existedCategory->id }}">
                            <input type="text" class="form-control" required value="{{ $existedCategory->name }}"
                                placeholder="{{ __('trans.category.name') }}" readonly />
                        </div>
                    @endif

                    <div class="col-md-6 mb-3">
                        <label class="form-label">{{ __('trans.course.popular') }}</label>
                        <select name="popular" class="form-select" required>
                            <option value="0" @selected(old('popular') == 0)>No</option>
                            <option value="1" @selected(old('popular') == 1)>Yes</option>
                        </select>
                    </div>

                    <div class="col-md-6 mb-3">
                        <label class="form-label">{{ __('trans.course.price') }} <b class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="price" value="{{ old('price') }}"
                            placeholder="{{ __('trans.course.price') }}"
                            oninput="this.value = this.value.replace(/[^0-9.]/g, '')" />
                    </div>

                    <div class="col-md-12 mb-3">
                        <label class="form-label">{{ __('trans.course.description') }}</label>
                        <textarea name="description" class="form-control" rows="4" placeholder="{{ __('trans.course.description') }}">{{ old('description') }}</textarea>
                    </div>


                    <div class="col-md-12 mb-3">
                        <div class="input-group">
                            <label>{{ __('trans.course.img') }}</label>

                            <div class="input-group">
                                <span class="input-group-btn">
                                    <a id="lfm" data-input="thumbnail" data-preview="holder"
                                        class="UploadFile btn btn-primary">
                                        <i class="fa fa-picture-o"></i> {{ __('trans.choose') }}
                                    </a>
                                </span>
                                <input id="thumbnail" class="form-control" type="text" name="img"
                                    value="{{ old('img', '/admin/img/doctorito-logo.png') }}" readonly />
                            </div>
                        </div>

                        <div id="holder" style="margin-top:15px;max-height:100px;">
                            @if (!empty(old('img', '/admin/img/doctorito-logo.png')))
                                <img src="{{ old('img', '/admin/img/doctorito-logo.png') }}" style="height: 5rem;">
                            @endif
                        </div>
                    </div>


                    <div class="row">
                        <div class="col-md-12">
                            <button class="btn btn-primary btn-create w-100">{{ __('trans.save') }}</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection

{{-- @section('js')

    <script>
        $(document).ready(function() {
            $('#myForm').submit(function() {
                $('select').removeAttr('disabled');
            });
        })
    </script>

@endsection --}}
