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

@section('title', 'Add 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 Poetry for {{ $poet->name }}</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('poetries.all_poetry_store') }}" method="POST">
                @csrf
                <input type="hidden" name="poet_id" value="{{ $poet->id }}">

                <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="alphabit" class="form-control" required>
                                <option value="">انتخاب</option>
                                @foreach($alphabits as $row)
                                    <option value="{{ $row->name }}" {{ old('alphabit') == $row->name ? 'selected' : '' }}>{{ $row->name }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <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->title_ps }}</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('poets.show', $poet->id) }}" 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'
            });
        });

        // Active menu
        $(".app-menu").removeClass("active");
        $("#nav_poetsi").addClass("active");
        $("#poetsi").addClass("is-expanded");
        $("#poets_history").addClass("active");
    </script>
@endsection
