<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\Module\ModuleSidebarInterface;
use Fisharebest\Webtrees\Module\ModuleTabInterface;
use Fisharebest\Webtrees\Tree;
use Illuminate\Support\Collection;

/**
 * @var string                                 $age
 * @var bool                                   $can_upload_media
 * @var Collection<int,Media>                  $individual_media
 * @var Collection<int,Fact>                   $name_records
 * @var Individual                             $record
 * @var Collection<int,Fact>                   $sex_records
 * @var Collection<int,string>                 $shares
 * @var Collection<int,ModuleSidebarInterface> $sidebars
 * @var Collection<int,ModuleTabInterface>     $tabs
 * @var Tree                                   $tree
 * @var string                                 $user_link
 */
?>

<?php if ($individual_media->isNotEmpty() || $tree->getPreference('USE_SILHOUETTE') === '1') : ?>
    <div class="col-sm-3">
        <?php if ($individual_media->isEmpty()) : ?>
            <div class="img-thumbnail">
                <i class="wt-individual-silhouette wt-individual-silhouette-<?= strtolower($record->sex()) ?> wt-icon-flip-rtl w-100"></i>
            </div>
        <?php elseif ($individual_media->count() === 1) : ?>
            <?= $individual_media->first()->displayImage(200, 260, 'crop', ['class' => 'img-thumbnail img-fluid w-100']) ?>
        <?php else : ?>
            <div id="individual-images" class="carousel slide" data-bs-interval="false">
                <div class="carousel-inner">
                    <?php foreach ($individual_media as $n => $media_file) : ?>
                        <div class="carousel-item <?= $n === 0 ? 'active' : '' ?>">
                            <?= $media_file->displayImage(200, 260, 'crop', ['class' => 'img-thumbnail img-fluid w-100']) ?>
                        </div>
                    <?php endforeach ?>
                </div>
                <button type="button" class="carousel-control-prev" data-bs-target="#individual-images" data-bs-slide="prev">
                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                    <span class="visually-hidden"><?= I18N::translate('previous') ?></span>
                </button>
                <button type="button" class="carousel-control-next" data-bs-target="#individual-images" data-bs-slide="next">
                    <span class="carousel-control-next-icon" aria-hidden="true"></span>
                    <span class="visually-hidden"><?= I18N::translate('next') ?></span>
                </button>
            </div>
        <?php endif ?>

        <?php if ($can_upload_media) : ?>
            <div class="text-center">
                <a href="<?= e(route(AddNewFact::class, ['tree' => $record->tree()->name(), 'xref' => $record->xref(), 'fact' => 'OBJE'])) ?>">
                    <?= I18N::translate('Add a media object') ?>
                </a>
            </div>
        <?php endif ?>
    </div>
<?php endif ?>
