<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\ManageTrees;
use Fisharebest\Webtrees\Http\RequestHandlers\MergeRecordsAction;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Location;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\Note;
use Fisharebest\Webtrees\Repository;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Submitter;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;

/**
 * @var Family|null     $family1
 * @var Family|null     $family2
 * @var Individual|null $individual1
 * @var Individual|null $individual2
 * @var Location|null   $location1
 * @var Location|null   $location2
 * @var Media|null      $media1
 * @var Media|null      $media2
 * @var Note|null       $note1
 * @var Note|null       $note2
 * @var Repository|null $repository1
 * @var Repository|null $repository2
 * @var Source|null     $source1
 * @var Source|null     $source2
 * @var Submitter|null  $submitter1
 * @var Submitter|null  $submitter2
 * @var string          $title
 * @var Tree            $tree
 */

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ManageTrees::class, ['tree' => $tree->name()]) => I18N::translate('Manage family trees'), $title]]) ?>

<h1><?= $title ?></h1>

<form id="merge-step-1" method="post" action="<?= e(route(MergeRecordsAction::class, ['tree' => $tree->name()])) ?>">
    <div class="row mb-3">
        <label class="col-sm-3 col-form-label" for="record-type">
            <?= I18N::translate('Select two records to merge.') ?>
        </label>
        <div class="col-sm-9">
            <select class="form-select" id="record-type">
                <option value="individual"><?= I18N::translate('Individuals') ?></option>
                <option value="family"><?= I18N::translate('Families') ?></option>
                <option value="source"><?= I18N::translate('Sources') ?></option>
                <option value="repository"><?= I18N::translate('Repositories') ?></option>
                <option value="note"><?= I18N::translate('Notes') ?></option>
                <option value="media"><?= I18N::translate('Media objects') ?></option>
                <option value="submitter"><?= I18N::translate('Submitters') ?></option>
                <option value="location"><?= I18N::translate('Locations') ?></option>
            </select>
        </div>
    </div>

    <label class="row mb-3">
        <span class="col-sm-3 col-form-label">
            <?= I18N::translate('First record') ?>
        </span>

        <span class="col-sm-9 select-record select-individual">
            <?= view('components/select-individual', ['name' => 'xref1', 'id' => 'individual-xref-1', 'individual' => $individual1, 'tree' => $tree]) ?>
        </span>

        <span class="col-sm-9 select-record select-family d-none">
            <?= view('components/select-family', ['name' => 'xref1', 'id' => 'family-xref-1', 'family' => $family1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-source d-none">
            <?= view('components/select-source', ['name' => 'xref1', 'id' => 'source-xref-1', 'source' => $source1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-repository d-none">
            <?= view('components/select-repository', ['name' => 'xref1', 'id' => 'repository-xref-1', 'repository' => $repository1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-note d-none">
            <?= view('components/select-note', ['name' => 'xref1', 'id' => 'note-xref-1', 'note' => $note1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-media d-none">
            <?= view('components/select-media', ['name' => 'xref1', 'id' => 'media-xref-1', 'media' => $media1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-submitter d-none">
            <?= view('components/select-submitter', ['name' => 'xref1', 'id' => 'submitter-xref-1', 'submitter' => $submitter1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-location d-none">
            <?= view('components/select-location', ['name' => 'xref1', 'id' => 'location-xref-1', 'location' => $location1, 'tree' => $tree, 'disabled' => true]) ?>
        </span>
    </label>

    <label class="row mb-3">
        <span class="col-sm-3 col-form-label">
            <?= I18N::translate('Second record') ?>
        </span>

        <span class="col-sm-9 select-record select-individual">
            <?= view('components/select-individual', ['name' => 'xref2', 'id' => 'individual-xref-2', 'individual' => $individual2, 'tree' => $tree]) ?>
        </span>

        <span class="col-sm-9 select-record select-family d-none">
            <?= view('components/select-family', ['name' => 'xref2', 'id' => 'family-xref-2', 'family' => $family2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-source d-none">
            <?= view('components/select-source', ['name' => 'xref2', 'id' => 'source-xref-2', 'source' => $source2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-repository d-none">
            <?= view('components/select-repository', ['name' => 'xref2', 'id' => 'repository-xref-2', 'repository' => $repository2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-note d-none">
            <?= view('components/select-note', ['name' => 'xref2', 'id' => 'note-xref-2', 'note' => $note2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-media d-none">
            <?= view('components/select-media', ['name' => 'xref2', 'id' => 'media-xref-2', 'media' => $media2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-submitter d-none">
            <?= view('components/select-submitter', ['name' => 'xref2', 'id' => 'submitter-xref-2', 'submitter' => $submitter2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>

        <span class="col-sm-9 select-record select-location d-none">
            <?= view('components/select-location', ['name' => 'xref2', 'id' => 'location-xref-2', 'location' => $location2, 'tree' => $tree, 'disabled' => true]) ?>
        </span>
    </label>

    <div class="row mb-3">
        <div class="col-sm-3">
        </div>

        <div class="col-sm-9">
            <button class="btn btn-primary" type="submit">
                <?= view('icons/save') ?>
                <?= I18N::translate('continue') ?>
            </button>
        </div>
    </div>

    <?= csrf_field() ?>
</form>

<?php View::push('javascript') ?>
<script>
  'use strict';

  webtrees.initializeIFSRO(document.getElementById('record-type'), document.getElementById('merge-step-1'));
</script>
<?php View::endpush() ?>
