@extends('back-end.master.app')

@section('title', 'Add Folk Poetry')

@section('pageCSS')
    <link href="{{ asset('back-end/vendor/summernote/summernote-bs4.css') }}" rel="stylesheet">
    <style>
        .form-control, option { direction: rtl !important; }
    </style>
@endsection

@section('body')
<main class="app-content">
    <div class="card">
        <div class="card-header">
            <h4>Add New Folk Poetry</h4>
        </div>
        <div class="card-body">
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul class="mb-0">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <form action="{{ route('publicPoetries.store') }}" method="POST">
                @csrf
                <div class="row">
                    <div class="col-md-9">
                        <div class="form-group">
                            <label>لومړی بیت <span class="text-danger">*</span></label>
                            <input type="text" name="title" class="form-control" value="{{ old('title') }}" required>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>کټګورۍ <span class="text-danger">*</span></label>
                            <select name="cat_id" class="form-control" required>
                                <option value="">-- انتخاب --</option>
                                @foreach($categories as $cat)
                                    <option value="{{ $cat->id }}" {{ old('cat_id') == $cat->id ? 'selected' : '' }}>{{ $cat->name_en }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>شعر <span class="text-danger">*</span></label>
                            <textarea name="body" id="summernote" class="form-control">{{ old('body') }}</textarea>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <button type="submit" class="btn btn-primary">Save</button>
                        <a href="{{ route('publicPoetries.index') }}" class="btn btn-secondary">Cancel</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</main>
@endsection

@section('pageJs')
    <script src="{{ asset('back-end/vendor/summernote/summernote-bs4.js') }}"></script>
    <script>
        $(document).ready(function() {
            $('#summernote').summernote({
                height: 300,
                direction: 'rtl'
            });
        });

        $(".app-menu").removeClass("active");
        $("#nav_plpoetries").addClass("active");
        $("#plpoetries").addClass("is-expanded");
        $("#plpoetries_history").addClass("active");
    </script>
@endsection
