<?php require_once ('model.php'); ?>
<form action="<?=ADMIN_URL?>/store" class="needs-validation" novalidate method="POST">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']['value']; ?>">
<input type="hidden" name="model" value="<?=$model?>">
<div class="row">
    <div class="col-xxl-10">
        <div class="card">
            <div class="card-header align-items-center d-flex">
                <h4 class="card-title mb-0 flex-grow-1 text-muted"><?=lang('form_detail')?></h4>
            </div><!-- end card header -->
            <div class="card-body">
                <div class="live-preview">
                    <div class="row">


                        <div class="col-md-12">
                            <div class="mb-3 input-group-v ">
                                <label for="title" class="form-label"><?=lang('form_input_title')?></label>
                                <input type="text" name="title"  class="form-control input-group-flat" id="title"  value="<?php echo htmlspecialchars(m_get_session('title')); ?>"  placeholder="<?=lang('form_input_title_placeholder')?>" required>
                                <div class="invalid-feedback">
                                    <?=lang('form_vali_title')?>
                                </div>
                            </div>
                        </div>
                        <!--end col-->
                        <div class="col-md-12">
                            <div class="mb-3">
                                <label for="sef" class="form-label"><?=lang('form_input_sef')?></label>
                                <div class="input-group sef">
                                    <span class="input-group-text border-end-0 " style="background: none" id="sef"><?=DOMAIN?>/</span>
                                    <input type="text" name="sef" class="form-control  input-group-flat border-start-0" id="slug"   required>
                                    <div class="invalid-feedback">
                                        <?=lang('form_vali_sef')?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="mb-3 input-group-v ">
                                <label for="description" class="form-label"><?=lang('table_description')?></label>
                                <textarea class="form-control input-group-flat " name="description" maxlength="400" placeholder="<?=lang('table_description')?>" id="description" ></textarea>
                                <p class="character_count">Kalan Karakter: <small id="description_Remaining">400</small></p>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header align-items-center d-flex">
                <h4 class="card-title mb-0 flex-grow-1"><?=lang('seo_title')?></h4>
                <div class="flex-shrink-0">
                    <div class="form-check form-switch form-switch-right form-switch-md">
                        <label for="vertical-form-showcode" class="form-label text-muted show-seo"><?=lang('show_seo')?></label>
                        <input class="form-check-input code-switcher" type="checkbox" id="vertical-form-showcode">
                    </div>
                </div>
            </div><!-- end card header -->
            <div class="card-body">
                <div class="seo-preview">
                    <p class="default-seo-description ">
                        <?=lang('seo_desc')?>
                    </p>
                    <div class="existed-seo-meta hidden">
                        <span class="page-title-seo" id="seo_title_preview"></span>
                        <div class="page-url-seo ws-nm">
                            <p><?=DOMAIN?>/<span id="seo_link_preview"></span></p>
                        </div>
                        <div>
                            <span style="color: #70757a;"><?=m_date_tr($db->now())?> - </span>
                            <span id="seo-description-preview"></span>
                        </div>
                    </div>
                </div>
                <div class="live-preview">
                </div>
                <div class="d-none code-view">
                    <hr>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="mb-3 input-group-v ">
                                <label for="seo_title" class="form-label"><?=lang('form_input_seo_title')?></label>
                                <input type="text" name="seo_title"  class="form-control input-group-flat" maxlength="50" placeholder="<?=lang('form_input_seo_title_placeholder')?>" id="seo_title"  value="">
                                <p class="character_count">Kalan Karakter: <small id="seo_title_Remaining">60</small></p>

                            </div>
                        </div>

                        <div class="col-md-12">
                            <div class="mb-3 input-group-v ">
                                <label for="seo_description" class="form-label"><?=lang('form_input_seo_description')?></label>
                                <textarea class="form-control input-group-flat " name="seo_description" maxlength="160" placeholder="<?=lang('form_input_seo_description_placeholder')?>" id="seo_description" ></textarea>
                                <p class="character_count">Kalan Karakter: <small id="seo_description_Remaining">160</small></p>

                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="mb-3 input-group-v ">
                                <label for="seo_keywords" class="form-label"><?=lang('form_input_seo_keywords')?></label>
                                <input class="form-control input-group-flat" name="seo_keywords" id="seo_keywords" data-choices="" data-choices-limit="3" data-choices-removeitem="" type="text" value="">
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>

    </div> <!-- end col -->

    <div class="col-xxl-2">
        <div class="card card-body">
            <h4 class="card-title  flex-grow-1 text-muted"><?=lang('published')?></h4>
            <hr>
            <div class="saved">
                <button class="btn btn-primary" type="submit" value="save_and_edit" name="save_and_edit">
                <span class="icon-tabler-wrapper icon-left">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-floppy" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                      <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                      <path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2"></path>
                      <path d="M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"></path>
                      <path d="M14 4l0 4l-6 0l0 -4"></path>
                    </svg>
                </span>
                    <?=lang('save_and_edit')?>
                </button>
                <button class="btn btn-light" type="submit" name="save" value="save">
                <span class="icon-tabler-wrapper icon-left">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-transfer-in" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                      <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                      <path d="M4 18v3h16v-14l-8 -4l-8 4v3"></path>
                      <path d="M4 14h9"></path>
                      <path d="M10 11l3 3l-3 3"></path>
                    </svg>
                </span>
                    <?=lang('save')?>
                </button>
            </div>
        </div>
        <div class="card card-body">
            <h4 class="card-title  flex-grow-1 text-muted"><?=lang('status')?></h4>
            <hr>
            <select class="form-select mb-3" name="status">
                <option selected="selected" value="1"><?=lang('status_option_published')?> </option>
                <option value="2"><?=lang('status_option_draft')?> </option>
                <option value="0"><?=lang('status_option_unpublished')?> </option>
            </select>
        </div>
        <div class="card card-body">
            <h4 class="card-title  flex-grow-1 text-muted"><?=lang('page_title_post_categories')?></h4>
            <hr>
            <div id="categoryContainer" class="form-select mb-3">
                <div class="selected-option"><?=lang('form_input_category_select')?> </div>
                <div class="options-list">
                    <?php
                    function display_category_options($categories, $parent_id = 0, $level = 0) {
                        foreach ($categories as $category) {
                            if ($category['parent_id'] == $parent_id) {
                                $indent = str_repeat('&nbsp;', $level * 1);
                                ?>
                                <div class="option" data-value="<?= $category['id'] ?>" data-level="<?= $level ?>">
                                    <?= $indent . $category['title'] ?>
                                </div>
                                <?php
                                display_category_options($categories, $category['id'], $level + 1);
                            }
                        }
                    }
                    $categories = posts('data', 'post_categories', lang_is_default('lang_code'));
                    display_category_options($categories);
                    ?>
                </div>
                <input type="hidden" name="category_id" id="selectedCategory">
            </div>
        </div>
        <div class="card card-body">
            <div class="mb-3">
                <label for="title" class="form-label"><?=lang('table_image')?></label>
                <input type="hidden"  data-v-image name="image" id="featured-image-input" value="">
                <img data-v-image src="<?=ADMIN_THEME_URL?>/assets/images/placeholder.svg" alt="" id="featured-image-thumb"  data-media-gallery data-target-input="#featured-image-input" data-target-thumb="#featured-image-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle">
                <div class="py-3 text-center">
                    <div class="btn-group w-100">
                        <button type="button" class="btn btn-primary btn-icon btn-sm w-100" data-media-gallery data-target-input="#featured-image-input" data-target-thumb="#featured-image-thumb" data-type="single">
                            <i class="la la-image la-lg"></i> <?=lang('set_media')?>
                        </button>

                        <button type="button" class="btn btn-outline-secondary btn-icon btn-sm" onclick="clearFeaturedMedia()">
                            <i class="la la-times"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div> <!-- end col -->
</div>


</form>