@extends('layouts.appback')

@section('content')
    <h1>Modifica Promozione</h1>

    <form action="{{ route('promotions.update', $promotion) }}" method="POST" enctype="multipart/form-data">
        @csrf
        @method('PUT')

        <div class="mb-3">
            <label for="title">Titolo</label>
            <input type="text" name="title" class="form-control" value="{{ old('title', $promotion->title) }}" required>
        </div>

        <div class="mb-3">
            <label for="content">Contenuto</label>
            <textarea name="content" id="ckeditor" class="form-control">{{ old('content', $promotion->content) }}</textarea>
        </div>

        <div class="mb-3">
            <label for="image">Immagine Principale</label>
            <input type="file" name="image" class="form-control">
            @if ($promotion->image)
                <img src="{{ asset('storage/' . $promotion->image) }}" class="mt-2" width="150">
            @endif
        </div>

        <button type="submit" class="btn btn-success">Aggiorna</button>
    </form>
@endsection

@push('scripts')
    <script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
    <script>
        ClassicEditor
            .create(document.querySelector('#ckeditor'), {});
    </script>
@endpush
