<?php

$pageTitle =
    'Viết bài mới - PET SPA';

$pageStyles = [
    'owner.css'
];

$activeOwnerPage =
    'posts';


$errorMessage =
    $_SESSION['flash_error']
    ?? null;

unset(
    $_SESSION['flash_error']
);


require BASE_PATH
    . '/app/views/layouts/header.php';

require BASE_PATH
    . '/app/views/layouts/navbar.php';

?>

<main class="owner-area">

<div class="container-fluid">

<div class="row g-4">

<div class="col-xl-2 col-lg-3">

    <?php require BASE_PATH
        . '/app/views/layouts/owner-sidebar.php';
    ?>

</div>


<div class="col-xl-10 col-lg-9">

    <div class="owner-page-header">

        <div>

            <a
                href="<?= BASE_URL ?>/?url=owner/posts"
                class="small text-decoration-none"
            >
                ← Bài viết
            </a>

            <h1 class="mt-2">
                Viết bài mới
            </h1>

        </div>

    </div>


    <?php if ($errorMessage): ?>

        <div class="alert alert-danger">

            <?= htmlspecialchars(
                $errorMessage
            ) ?>

        </div>

    <?php endif; ?>


    <form
        method="POST"
        action="<?= BASE_URL ?>/?url=owner/post/store"
        enctype="multipart/form-data"
    >

        <input
            type="hidden"
            name="_token"
            value="<?= htmlspecialchars(
                $_SESSION['csrf_token']
            ) ?>"
        >


        <div class="row g-4">

            <div class="col-xl-8">

                <section class="owner-card">

                    <div class="mb-3">

                        <label class="form-label fw-semibold">
                            Tiêu đề *
                        </label>

                        <input
                            type="text"
                            name="title"
                            class="form-control form-control-lg"
                            maxlength="255"
                            required
                        >

                    </div>


                    <div class="mb-3">

                        <label class="form-label">
                            Mô tả ngắn
                        </label>

                        <textarea
                            name="excerpt"
                            class="form-control"
                            rows="3"
                            maxlength="500"
                        ></textarea>

                    </div>


                    <div>

                        <div>

    <div>

    <label class="form-label fw-semibold mb-2">
        Nội dung *
    </label>

    <?php

    $editorContent = '';

    require BASE_PATH
        . '/app/views/owner/posts/_editor.php';

    ?>

</div>

</div>

                    </div>

                </section>


                <section class="owner-card mt-4">

                    <h2>
                        Ảnh đại diện
                    </h2>

                    <input
                        type="file"
                        name="featured_image"
                        class="form-control"
                        accept="image/jpeg,image/png,image/webp"
                    >

                    <small class="text-muted">
                        JPG, PNG, WEBP. Tối đa 5MB.
                    </small>

                </section>

            </div>


            <div class="col-xl-4">

                <section class="owner-card">

                    <h2>
                        Xuất bản
                    </h2>

                    <div class="mb-3">

                        <label class="form-label">
                            Trạng thái
                        </label>

                        <select
                            name="status"
                            class="form-select"
                        >

                            <option value="draft">
                                Lưu bản nháp
                            </option>

                            <option value="published">
                                Đăng ngay
                            </option>

                            <option value="hidden">
                                Ẩn bài viết
                            </option>

                        </select>

                    </div>


                    <div>

                        <label class="form-label">
                            Danh mục
                        </label>

                        <select
                            name="category_id"
                            class="form-select"
                        >

                            <option value="0">
                                Chưa phân loại
                            </option>

                            <?php foreach (
                                $categories
                                as $category
                            ): ?>

                                <option
                                    value="<?= (int)
                                        $category['id']
                                    ?>"
                                >
                                    <?= htmlspecialchars(
                                        $category['name']
                                    ) ?>
                                </option>

                            <?php endforeach; ?>

                        </select>

                    </div>

                </section>


                <button
                    type="submit"
                    class="btn btn-primary btn-lg w-100 mt-4"
                >
                    Lưu bài viết
                </button>

            </div>

        </div>

    </form>

</div>

</div>

</div>

</main>


<?php

require BASE_PATH
    . '/app/views/layouts/footer.php';

?>