@extends('admin.layouts.app')
@section('panel')
    <div class="col-lg-12">
        <form action="{{ route('admin.file.update', $file->id) }}" method="POST" enctype="multipart/form-data">
            @csrf
            <div class="card border">
                <h5 class="card-header">{{ $pageTitle }}</h5>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="">
                                @if ($file->width > $file->height)
                                    <img class="custom-rounded"
                                        src="{{ getImage(getFilePath('file') . '/' . $file->file) }}" alt=""
                                        width="800">
                                @else
                                    <img class="custom-rounded"
                                        src="{{ getImage(getFilePath('file') . '/' . $file->file) }}" alt=""
                                        width="300">
                                @endif
                            </div>
                        </div>
                        <div class="col-lg-8">
                            <div class="col-lg-12 col-12 mb-3">
                                <div class="form-group">
                                    <label class="form--label">@lang('Status')</label>
                                    <select class="form-control select" name="status" required>
                                        <option value="0" {{ $file->status == 0 ? 'selected' : '' }}>@lang('Pending')</option>
                                        <option value="1" {{ $file->status == 1 ? 'selected' : '' }}>@lang('Published')</option>
                                    </select>
                                </div>
                            </div>

                            <div class="col-lg-12 col-12 mb-3">
                                <label class="form--label">@lang('Product Title')</label>
                                <input type="text" value="{{ $file->title }}" class="form-control" name="title"
                                    placeholder="Enter" required>
                            </div>

                            <div class="col-lg-12 col-12 mb-3">
                                <div class="form-group">
                                    <label class="form--label">@lang('Category')</label>
                                    <select class="form-control select" name="category_id" required>
                                        <option value="">@lang('Select Category')</option>
                                        @foreach ($categories as $item)
                                            <option value="{{ $item->id }}"
                                                {{ $file->category_id == $item->id ? 'selected' : '' }}>{{ $item->name }}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="col-lg-12 col-12 mb-3">
                                <div class="form-group multiSelectParentDiv">
                                    <label class="form--label">@lang('Tags')</label>
                                    <select name="tags[]" class="form-control form-select select2-auto-creating"
                                        multiple="multiple" required>
                                        @foreach ($tags as $item)
                                            <option value="{{ $item->id }}"
                                                {{ in_array($item->id, $file->tags) ? 'selected' : '' }}>
                                                {{ __($item->name) }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="col-lg-12 col-12 mb-3">
                                <label class="form--label">@lang('Description')</label>
                                <textarea rows="5" class="form-control" name="description" placeholder="Write a description about your file."
                                    required>{{ $file->description }}</textarea>
                            </div>

                            <div class="col-lg-12 col-12 mb-3">
                                <label class="switch m-0" for="progress">
                                    <input type="checkbox" class="toggle-switch myCheckbox" name="isPremium" id="isPremium" value="1" {{ $file->is_premium == 1 ? 'checked' : '' }}>
                                    <span class="boll-bg slider round"></span>
                                </label>
                                <label class="fw-bold handle-label mx-2" for="isPremium">@lang('Is Premium')?</label>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col text-end mt-3">
                            <button type="submit" class="btn btn--primary btn-global">@lang('Update')</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection

@push('script')
    <script>
        (function($) {
            "use strict";
            $('.select2-auto-creating').select2({
                dropdownParent: $('.multiSelectParentDiv'),
                tags: true,
                tokenSeparators: [',']
            });
        })(jQuery);
    </script>
@endpush
