<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\EmailPreferencesAction;
use Fisharebest\Webtrees\Http\RequestHandlers\UserListPage;
use Fisharebest\Webtrees\I18N;

/**
 * @var string        $body
 * @var UserInterface $from
 * @var string        $subject
 * @var string        $title
 * @var UserInterface $to
 */

?>

<?= view('components/breadcrumbs', ['links' => [
    route(ControlPanel::class) => I18N::translate('Control panel'),
    route(UserListPage::class) => I18N::translate('User administration'),
    $title,
]]) ?>

<h1><?= $title ?></h1>

<form method="post" action="<?= e(route(EmailPreferencesAction::class, ['to' => $to->userName()])) ?>">
    <div class="row mb-3">
        <label class="col-sm-3 col-form-label" for="from">
            <?= I18N::translateContext('Email sender', 'From') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" id="from" type="text" value="<?= e('"' . $from->realName() . '" <' . $from->email() . '>') ?>" dir="auto" disabled>
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-sm-3 col-form-label" for="to">
            <?= I18N::translateContext('Email recipient', 'To') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" id="to" type="text" value="<?= e('"' . $to->realName() . '" <' . $to->email() . '>') ?>" dir="auto" disabled>
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-sm-3 col-form-label" for="subject">
            <?= I18N::translate('Subject') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" id="subject" type="text" name="subject" value="<?= e($subject) ?>" required="required">
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-sm-3 col-form-label" for="body">
            <?= I18N::translate('Message') ?>
        </label>
        <div class="col-sm-9">
            <textarea class="form-control" id="body" type="text" name="body" dir="auto" rows="5" required="required"><?= e($body) ?></textarea>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-sm-3 col-form-label"></div>
        <div class="col-sm-9">
            <button type="submit" class="btn btn-primary">
                <?= I18N::translate('Send') ?>
            </button>
            <a class="btn btn-link" href="<?= e(route(UserListPage::class)) ?>">
                <?= I18N::translate('cancel') ?>
            </a>
        </div>
    </div>

    <?= csrf_field() ?>
</form>
