<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Http\RequestHandlers\AddChildToFamilyPage;
use Fisharebest\Webtrees\Http\RequestHandlers\ReorderChildrenPage;
use Fisharebest\Webtrees\I18N;

/**
 * @var Family $family
 */

?>

<div class="align-self-center">
    <div class="badge bg-secondary m-2">
        <?php if ($family->children()->count() === 0) : ?>
            <?= I18N::translate('No children') ?>
        <?php else : ?>
            <?= I18N::plural('%s child', '%s children', $family->children()->count(), I18N::number($family->children()->count())) ?>
        <?php endif ?>
    </div>
    <?php foreach ($family->children() as $n => $child) : ?>
        <div class="d-flex">
            <?= view('chart-box', ['individual' => $child]) ?>
            <div class="wt-chart-horizontal-spacer">
                <?php if ($family->children()->count() === 1) : ?>
                    <div class="wt-chart-horizontal-line"></div>
                <?php elseif ($n === 0) : ?>
                    <div class="wt-chart-horizontal-first-child"></div>
                <?php elseif ($n + 1 === $family->children()->count()) : ?>
                    <div class="wt-chart-horizontal-last-child"></div>
                <?php else : ?>
                    <div class="wt-chart-horizontal-middle-child"><div class="wt-chart-horizontal-line"></div></div>
                <?php endif ?>
            </div>
        </div>
    <?php endforeach ?>
    <?php if ($family->canEdit()) : ?>
        <div class="wt-chart-box">
            <a class="btn btn-link" href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'M'])) ?>">
                <?= I18N::translate('Add a son') ?>
            </a>
            |
            <a class="btn btn-link" href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'F'])) ?>">
                <?= I18N::translate('Add a daughter') ?>
            </a>
            <br>
            <?php if ($family->numberOfChildren() > 1) : ?>
                <a class="btn btn-link" href="<?= e(route(ReorderChildrenPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref()])) ?>">
                    <?= I18N::translate('Re-order children') ?>
                </a>
            <?php endif ?>
        </div>
    <?php endif ?>
</div>
<?php if ($family->children()->count() !== 1) : ?>
    <div class="wt-chart-horizontal-spacer">
        <div class="wt-chart-horizontal-line"></div>
    </div>
<?php endif ?>
