<?php

/**
 * @var int         $id
 * @var string      $name
 * @var bool        $isEmpty
 * @var bool        $deleted
 * @var string|null $mode
 * @var bool        $moving
 * @var int|null    $moveTarget
 * @var array|null  $moveSections
 * @var int|null    $pendingMove
 * @var string|null $deleteAllResult
 */

$this->layout('system::layout/default');
?>

<?php if ($isEmpty) : ?>
    <?php if ($deleted) : ?>
        <div class="alert alert-success"><?= sprintf(__('Section "%s" has been deleted.'), $this->e($name)) ?></div>
        <div class="mt-3">
            <a href="/library/"><?= __('Back to Library') ?></a>
        </div>
    <?php else : ?>
        <div class="alert alert-danger">
            <div><?= sprintf(__('Are you sure you want to delete the section "%s"? This action cannot be undone.'), $this->e($name)) ?></div>
            <div class="mt-2">
                <a href="/library/section/<?= $id ?>/delete?yes" class="btn btn-danger btn-sm"><?= __('Yes, Delete') ?></a>
                <a href="/library/section/<?= $id ?>" class="btn btn-secondary btn-sm"><?= __('Cancel') ?></a>
            </div>
        </div>
    <?php endif; ?>
<?php else : ?>
    <?php if ($mode === 'moveaction') : ?>
        <?php if ($moving) : ?>
            <div class="alert alert-success"><?= sprintf(__('Contents of section "%s" have been moved successfully.'), $this->e($name)) ?></div>
            <div class="mt-3">
                <a href="/library/section/<?= $moveTarget ?>"><?= __('Go to Target Section') ?></a>
            </div>
        <?php else : ?>
            <div class="alert alert-danger">
                <div><?= sprintf(__('Move all contents of section "%s" to the selected section and delete it?'), $this->e($name)) ?></div>
                <div class="mt-2">
                    <a href="/library/section/<?= $id ?>/delete?movedeny&amp;do=moveaction&amp;move=<?= $pendingMove ?>" class="btn btn-danger btn-sm"><?= __('Yes, Move and Delete') ?></a>
                    <a href="/library/" class="btn btn-secondary btn-sm"><?= __('Cancel') ?></a>
                </div>
            </div>
        <?php endif; ?>
    <?php elseif ($mode === 'delmove') : ?>
        <?php if ($moveSections) : ?>
            <div class="menu">
                <form action="/library/section/<?= $id ?>/delete" method="post">
                    <div>
                        <label for="move_select"><?= sprintf(__('Move contents of "%s" to:'), $this->e($name)) ?></label>
                        <select id="move_select" name="move" class="form-control">
                            <?php foreach ($moveSections as $sectionId => $sectionName) : ?>
                                <option value="<?= $sectionId ?>"><?= $this->e($sectionName) ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div>
                        <input type="hidden" name="mode" value="moveaction">
                    </div>
                    <div class="mt-3">
                        <input type="submit" name="submit" value="<?= __('Approve') ?>" class="btn btn-primary">
                    </div>
                </form>
            </div>
        <?php else : ?>
            <div class="alert alert-danger"><?= sprintf(__('No sections available to move the contents of "%s" to.'), $this->e($name)) ?></div>
            <div class="mt-3">
                <a href="/library/"><?= __('Back to Library') ?></a>
            </div>
        <?php endif; ?>
    <?php elseif ($mode === 'delall') : ?>
        <?php if ($deleteAllResult) : ?>
            <div class="alert alert-success"><?= $deleteAllResult ?></div>
            <div class="mt-3">
                <a href="/library/"><?= __('Back to Library') ?></a>
            </div>
        <?php else : ?>
            <div class="alert alert-danger">
                <div><?= sprintf(__('Are you sure you want to delete section "%s" along with ALL its contents? This action cannot be undone.'), $this->e($name)) ?></div>
                <div class="mt-2">
                    <a href="/library/section/<?= $id ?>/delete?deldeny&amp;do=delall" class="btn btn-danger btn-sm"><?= __('Yes, Delete Everything') ?></a>
                    <a href="/library/" class="btn btn-secondary btn-sm"><?= __('Cancel') ?></a>
                </div>
            </div>
        <?php endif; ?>
    <?php else : ?>
        <div class="card border-0 shadow">
            <div class="card-body">
                <p><?= sprintf(__('Section "%s" contains subsections or articles. Choose how to delete it:'), $this->e($name)) ?></p>
                <form action="/library/section/<?= $id ?>/delete" method="post">
                    <div class="custom-control custom-radio">
                        <input type="radio" id="type1" name="mode" value="delmove" class="custom-control-input" checked="checked">
                        <label class="custom-control-label" for="type1"><?= __('Move contents to another section, then delete') ?></label>
                    </div>
                    <div class="custom-control custom-radio">
                        <input type="radio" id="type2" name="mode" value="delall" class="custom-control-input">
                        <label class="custom-control-label" for="type2"><?= __('Delete section and all its contents') ?></label>
                    </div>
                    <div class="mt-2">
                        <input type="submit" name="submit" value="<?= __('Continue') ?>" class="btn btn-danger">
                    </div>
                </form>
            </div>
        </div>
    <?php endif; ?>
<?php endif; ?>
