<?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
 */

/**
 * @var $title
 * @var $page_title
 * @var $data
 */

$this->layout(
    'system::layout/default',
    [
        'title'      => $title,
        'page_title' => $page_title ?? $title,
    ]
);
?>
<?php if (isset($_POST['submit']) && ! $error) : ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-success',
            'alert'      => __('Article added'),
        ]
    ) ?>
    <?php if ($md) : ?>
        <div class="mt-3"><a href="?id=<?= $cid ?>"><?= __('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="?do=dir&amp;id=<?= $id ?>"><?= __('To Section') ?></a></div>
    <?php endif; ?>
<?php else : ?>

    <?php if ($error) : ?>
        <?= $this->fetch(
            'system::app/alert',
            [
                'alert_type' => 'alert-danger',
                'alert'      => $error,
            ]
        ) ?>
    <?php endif; ?>
    <form name="form" action="?act=addnew&amp;id=<?= $id ?>" 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="<?= $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"><?= $announce ?></textarea>
        </div>

        <div class="form-group">
            <label for="text"><?= __('Text') ?></label>
            <div><?= $bbcode ?></div>
            <textarea class="form-control" rows="<?= $user->config->fieldHeight ?>" name="text" id="text"><?= $text ?></textarea>
        </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="<?= $tag ?>">
        </div>

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