<?php

use Fisharebest\Webtrees\Http\RequestHandlers\ContactAction;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Tree;

/**
 * @var string $body
 * @var string $captcha
 * @var string $from_email
 * @var string $from_name
 * @var string $subject
 * @var string $title
 * @var string $to
 * @var string $to_name
 * @var string $url
 * @var Tree   $tree
 */

?>

<h2><?= $title ?></h2>

<form method="post" action="<?= e(route(ContactAction::class, ['tree' => $tree->name()])) ?>">
    <?= csrf_field() ?>
    <?= $captcha ?>
    <input type="hidden" name="tree" value="<?= e($tree->name()) ?>">
    <input type="hidden" name="url" value="<?= e($url) ?>">

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

    <div class="row form-group mb-3">
        <label class="col-sm-3 col-form-label" for="from-name">
            <?= I18N::translate('Your name') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" id="from-name" type="text" name="from_name" value="<?= e($from_name) ?>" required="required">
        </div>
    </div>
    <div class="row form-group mb-3">
        <label class="col-sm-3 col-form-label" for="from-email">
            <?= I18N::translate('Email address') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" id="from-email" type="email" name="from_email" value="<?= e($from_email) ?>" required="required">
        </div>
    </div>

    <div class="row form-group 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 form-group 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" rows="5" dir="auto" required="required"><?= e($body) ?></textarea>
        </div>
    </div>

    <div class="row form-group 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($url) ?>">
                <?= I18N::translate('cancel') ?>
            </a>
        </div>
    </div>
</form>
