<?= $this->include('themes/_commonPartialsBs/select2bs5') ?>
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
<?= $this->extend('themes/vuexy/wiki/layout') ?>
<?php

use CodeIgniter\I18n\Time;
?>
<?= $this->section('content');  ?>
<div class="row">
    <div class="col-md-12">

        <div class="card card-info">
            <div class="card-header">
                <div class="row">
                    <div class="col-md-10 col-xs-12 col-sm-12 d-flex flex-row flex-wrap justify-content-start align-items-center pb-2 gap-2">
                        <?php if ($section->content()?->published_data): ?>
                            <span class="badge badge-center rounded-pill text-bg-success"><i class="ti ti-check"></i></span>
                            <strong><?= lang('Wiki.published') ?></strong>
                            <strong><?= $section->content()->published_at ? Time::createFromFormat('Y-m-d H:i:s', $section->content()->published_at)->format('d/m/Y H:i') : "" ?></strong>
                            <strong class="text-secondary"><?= $section->content()->publish_by() ?></strong>

                        <?php else: ?>
                            <span class="badge badge-center rounded-pill text-bg-danger"><i class="ti ti-alert-circle"></i></span>
                            <strong><?= lang('Wiki.not_published') ?></strong>
                        <?php endif; ?>


                    </div>
                    <?php if (auth()->user()->inGroup('admin')): ?>
                        <div class="col-md-2 d-flex flex-row flex-wrap justify-content-end align-items-stretch pb-2 gap-2">
                            <div class="btn-sm-group">
                                <button type="button" class="btn btn-sm btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
                                    <i class="icon-base ti ti-dots-vertical"></i>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><button type="button" class="dropdown-item btn btn-success btn-xs col-xs-12 " id="new-section"><i class="icon-base ti ti-plus icon-xs me-2"></i><?= lang('Wiki.new_section') ?></button></li>
                                    <li><button type="button" class="dropdown-item btn btn-warning btn-xs col-auto " id="edit-section"><i class="icon-base ti ti-pencil icon-xs me-2"></i><?= lang('Wiki.edit_section') ?></button></li>
                                    <li><button type="button" class="dropdown-item btn btn-danger btn-xs col-auto " id="delete-section"><i class="icon-base ti ti-trash icon-xs me-2"></i><?= lang('Wiki.delete_section') ?></button></li>

                                    <li>
                                        <hr class="dropdown-divider">
                                    </li>
                                    <li><button type="button" class="dropdown-item btn btn-primary btn-xs col-auto " id="save-editor"><i class="icon-base ti ti-device-floppy icon-xs me-2"></i><?= lang('App.global_save') ?></button></li>
                                    <li><button type="button" class="dropdown-item btn btn-danger btn-xs col-auto " id="release-editor"><i class="icon-base ti ti-upload icon-xs me-2"></i><?= lang('Wiki.release') ?></button></li>
                                    <li><button type="button" class="dropdown-item btn btn-secondary btn-xs d-none col-auto " id="preview-editor"><i class="icon-base ti ti-eye icon-xs me-2"></i><?= lang('Wiki.preview') ?></button></li>
                                    <li><button type="button" class="dropdown-item btn btn-warning btn-xs col-auto " id="edit-editor"><i class="icon-base ti ti-pencil icon-xs me-2"></i><?= lang('Wiki.edit') ?></button></li>
                                </ul>
                            </div>
                            <div class="btn-sm-group">
                                <button type="button" class="btn btn-sm btn-warning btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown" title="<?=lang('Wiki.dropdown_roles')?>">
                                    <i class="icon-base ti ti-users"></i>
                                </button>
                                <ul class="dropdown-menu">
                                <?php foreach ($section->roles() as $key => $roleEntity): ?>
                                    <li><span class="dropdown-item badge bg-label-success"><?=config("AuthGroups")->groups[$roleEntity->role]["title"]?></span></li>
                                <?php endforeach; ?>
                                </ul>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div><!--//.card-header -->

            <div class="card-body">
                <div class="row">
                    <form action="POST" id="form-wiki">
                        <input type="hidden" name="slug" id="section-slug">
                        <input type="hidden" name="wiki_page_id" id="wiki-section-id" value="<?= $section->id ?>">
                        <input type="hidden" name="wiki_page_id" id="wiki-page-id">
                        <input type="hidden" name="wiki_page_id" id="wiki-content-id">
                    </form>
                    <div class="col-md-12">
                        <div id="editorjs" ></div>
                    </div>
                </div>
            </div><!--//.card-body -->
            <div class="card-footer">

            </div><!--//.card-footer -->
        </div><!--//.card -->
    </div><!--//.col -->
</div><!--//.row -->
<?= view("themes/vuexy/components/modals/modalSection") ?>

<?= $this->endSection() ?>

<?= $this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/editorjs.css') ?>" />
<?= $this->endSection() ?>

<?= $this->section("additionalExternalJs") ?>

<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
<?php if (auth()->user()->inGroup('admin')) : ?>
    <script type="module" src="<?= site_url('assets/js/safekat/pages/wiki/home.js') ?>"></script>
<?php else : ?>
    <script type="module" src="<?= site_url('assets/js/safekat/pages/wiki/viewOnly.js') ?>"></script>
<?php endif; ?>

<?= $this->endSection() ?>