<?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,
    ]
);
$form_data = $data['form_data'] ?? [];
?>

<form name="file_edit_form" action="<?= $data['action_url'] ?>" method="post">
    <?php if (! empty($data['error_message'])): ?>
        <?= $this->fetch(
            'system::app/alert',
            [
                'alert_type' => 'alert-danger border-0',
                'alert'      => $data['error_message'],
            ]
        ) ?>
    <?php endif; ?>
    <div class="form-group">
        <label for="name"><?= __('Title') ?></label>
        <input type="text" class="form-control" id="name" name="name" value="<?= $form_data['name'] ?>" minlength="3" maxlength="200" required>
    </div>
    <div class="form-group">
        <label for="description"><?= __('Description') ?></label>
        <textarea id="description" name="description" class="form-control" rows="<?= $user->config->fieldHeight ?>"><?= $form_data['description'] ?></textarea>
    </div>
    <div class="form-group">
        <label for="password"><?= __('Password') ?></label>
        <input type="text" class="form-control" id="password" name="password" value="<?= $form_data['password'] ?>">
    </div>

    <h3><?= __('Access') ?></h3>

    <div class="custom-control custom-radio">
        <input type="radio" id="all" name="access" value="4" class="custom-control-input" <?= empty($form_data['access']) || $form_data['access'] === 4 ? 'checked' : '' ?>>
        <label class="custom-control-label" for="all"><?= __('Everyone') ?></label>
    </div>
    <div class="custom-control custom-radio">
        <input type="radio" id="pass" name="access" value="2" class="custom-control-input" <?= $form_data['access'] === 2 ? 'checked' : '' ?>>
        <label class="custom-control-label" for="pass"><?= __('With Password') ?></label>
    </div>
    <div class="custom-control custom-radio">
        <input type="radio" id="for_me" name="access" value="1" class="custom-control-input" <?= $form_data['access'] === 1 ? 'checked' : '' ?>>
        <label class="custom-control-label" for="for_me"><?= __('Only for me') ?></label>
    </div>

    <div class="mt-3">
        <button type="submit" name="submit" value="1" class="btn btn-primary"><?= __('Save') ?></button>
        <a href="<?= $data['back_url'] ?>" class="btn btn-secondary"><?= __('Cancel') ?></a>
    </div>
</form>
