<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Individual;

/**
 * @var Family $family
 * @var int    $generations
 */

?>

<div class="d-flex">
    <div class="wt-chart-horizontal-spacer">
        <div class="wt-chart-horizontal-line"></div>
    </div>
    <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">
                <?= view('chart-box', ['individual' => $family->husband()]) ?>
            </div>

            <?php if ($family->husband() instanceof Individual && $family->husband()->childFamilies()->first() instanceof Family) : ?>
                <?php if ($generations > 1) : ?>
                    <?= view('modules/hourglass-chart/parents', ['family' => $family->husband()->childFamilies()->first(), 'generations' => $generations - 1]) ?>
                <?php else : ?>
                    <div class="align-self-center">
                        <div class="hourglass-arrow" data-wt-chart-xref="<?= route('module', ['module' => 'hourglass_chart', 'action' => 'Ancestors', 'xref' => $family->husband()->childFamilies()->first()->xref(), 'tree' => $family->husband()->childFamilies()->first()->tree()->name()]) ?>">
                            <?= view('icons/arrow-right') ?>
                        </div>
                    </div>
                <?php endif ?>
            <?php endif ?>
        </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">
                <?= view('chart-box', ['individual' => $family->wife()]) ?>
            </div>

            <?php if ($family->wife() instanceof Individual && $family->wife()->childFamilies()->first() instanceof Family) : ?>
                <?php if ($generations > 1) : ?>
                    <?= view('modules/hourglass-chart/parents', ['family' => $family->wife()->childFamilies()->first(), 'generations' => $generations - 1]) ?>
                <?php else : ?>
                    <div class="align-self-center">
                        <div class="align-self-center">
                            <div class="hourglass-arrow" data-wt-chart-xref="<?= route('module', ['module' => 'hourglass_chart', 'action' => 'Ancestors', 'xref' => $family->wife()->childFamilies()->first()->xref(), 'tree' => $family->wife()->childFamilies()->first()->tree()->name()]) ?>">
                                <?= view('icons/arrow-right') ?>
                            </div>
                        </div>
                    </div>
                <?php endif ?>
            <?php endif ?>
        </div>
    </div>
</div>
