<?php

/**
 * This file is part of JohnCMS Content Management System.
 *
 * @copyright JohnCMS Community
 * @license   https://opensource.org/licenses/GPL-3.0 GPL-3.0
 * @link      https://johncms.com JohnCMS Project
 */

$this->layout('system::layout/default');
?>
<?php if ($success) : ?>
    <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-success', 'alert' => __('Article added')]) ?>
    <?php if ($approved) : ?>
        <div class="mt-3"><a href="<?= $article_url ?>"><?= __('To Article') ?></a></div>
    <?php else : ?>
        <div class="alert alert-info mt-2"><?= __('Thank you for what we have written. After checking moderated, your Article will be published in the library.') ?></div>
        <div class="mt-3"><a href="<?= $cat_url ?>"><?= __('To Section') ?></a></div>
    <?php endif; ?>
<?php else : ?>
    <?php foreach ($errors as $e) : ?>
        <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-danger', 'alert' => $e]) ?>
    <?php endforeach; ?>
    <form name="form" action="<?= $form_url ?>" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="name"><?= __('Title') ?></label>
            <input type="text" name="name" class="form-control" id="name" value="<?= htmlspecialchars($name) ?>" placeholder="<?= __('Title') ?>" required>
        </div>

        <div class="form-group">
            <label for="announce"><?= __('Announce') ?></label>
            <textarea class="form-control" rows="<?= $user->config->fieldHeight ?>" name="announce" id="announce"><?= htmlspecialchars($announce) ?></textarea>
        </div>

        <div class="form-group">
            <?= $this->fetch(
                'system::app/ckeditor',
                [
                    'label'        => __('Text'),
                    'errors'       => '',
                    'value'        => htmlspecialchars($text, ENT_QUOTES, 'UTF-8'),
                    'name'         => 'text',
                    'allow_upload' => false,
                ]
            ) ?>
        </div>

        <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" name="comments" value="1" id="comments" checked="checked">
            <label class="custom-control-label" for="comments"><?= __('Commenting on the Article') ?></label>
        </div>

        <div class="custom-file mt-3">
            <input type="file" class="custom-file-input" id="image" name="image" accept="image/*">
            <label class="custom-file-label" for="image"><?= __('To upload a photo') ?></label>
        </div>

        <div class="custom-file mt-3">
            <input type="file" class="custom-file-input" id="textfile" name="textfile" accept="text/plain">
            <label class="custom-file-label" for="textfile"><?= __('Select the text file') ?></label>
            <div class="text-muted small"><?= __('Text entry field will be ignored') ?></div>
        </div>

        <div class="form-group mt-2">
            <label for="tags"><?= __('Tags') ?></label>
            <input name="tags" class="form-control" type="text" id="tags" value="<?= htmlspecialchars($tag) ?>">
        </div>

        <div class="mt-3">
            <input type="submit" name="submit" value="<?= __('Save') ?>" class="btn btn-primary">
            <a href="<?= $cat_url ?>" class="btn btn-secondary"><?= __('Cancel') ?></a>
        </div>
    </form>
<?php endif; ?>
