<?php

use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Http\RequestHandlers\AddSpouseToFamilyPage;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;

/**
 * @var Family $family
 */

?>
<div class="d-flex">
    <div class="align-self-center">
        <div class="d-flex">
            <div class="wt-chart-horizontal-spacer">
                <div class="wt-chart-horizontal-first-parent"></div>
            </div>

            <div class="align-self-center">
                <?php if ($family->husband() instanceof Individual) : ?>
                    <?= view('chart-box', ['individual' => $family->husband()]) ?>
                <?php else : ?>
                <div class="wt-chart-box">
                    <?php if ($family->canEdit()) : ?>
                        <a class="btn btn-link" href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'M'])) ?>">
                            <?= I18N::translate('Add a husband')?>
                        </a>
                    <?php endif ?>
                </div>
                <?php endif ?>
            </div>

            <?= view('family-page-grandparents', ['family' => $family, 'parent_family' => $family->husband() ? $family->husband()->childFamilies()->first() : null, 'individual' => $family->husband()]) ?>
        </div>

        <div class="d-flex">
            <div class="wt-chart-horizontal-spacer">
                <div class="wt-chart-horizontal-last-parent"></div>
            </div>

            <div class="align-self-center">
                <?php if ($family->wife() instanceof Individual) : ?>
                    <?= view('chart-box', ['individual' => $family->wife()]) ?>
                <?php else : ?>
                    <div class="wt-chart-box">
                        <?php if ($family->canEdit()) : ?>
                            <a class="btn btn-link" href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'F'])) ?>">
                                <?= I18N::translate('Add a wife')?>
                            </a>
                        <?php endif ?>
                    </div>
                <?php endif ?>
            </div>

            <?= view('family-page-grandparents', ['family' => $family, 'parent_family' => $family->wife() ? $family->wife()->childFamilies()->first() : null, 'individual' => $family->wife()]) ?>
        </div>
    </div>
</div>

