<?php
defined('_JEXEC') or die('Restricted access');

JHtml::_('jquery.framework');
$doc = JFactory::getDocument();
$doc->addScript(JURI::base(true) . '/public/js/lightbox_2.js');
$doc->addStylesheet(JURI::base(true) . '/public/css/lightbox_2_1.css');
?>

<style>
    .vote-form {
        margin-top: 5px;
        margin-bottom: 10px;
        text-align: center;
    }

    .btn-vote {
        background-color: #e67e22 !important;
        border-color: #e67e22 !important;
        font-weight: bold !important;
    }

    .btn-vote:hover:not(.disabled) {
        background-color: rgba(230, 126, 34, 0.75) !important;
        border-color: rgba(230, 126, 34, 0.75) !important;
    }

    .disabled {
        cursor: not-allowed;
    }

    .winner-text {
        text-align: center;
        font-size: 18px;
        text-transform: uppercase;
    }
</style>

<div class="container">
    <!-- Winners -->
    <?php if (date('Y-m-d') >= '2023-02-29') : ?>
        <div class="sppb-row">
            <div class="sppb-col-md-2"></div>

            <div class="sppb-col-md-8">
                <div class="winner-text">
                    <b><?= JText::_('MOD_AL_VOTE_FIRST_PLACE') ?></b>
                </div>
                <a class="example-image-link" href="https://www.archlinexp.com/<?php echo $winners[0]->source->original; ?>" data-title="<?php echo $winners[0]->title; ?>" data-lightbox="example-1"><img class="example-image" src="https://www.archlinexp.com/<?php echo $winners[0]->source->original; ?>"></a>

                <?= JText::_('MOD_AL_VOTE_VOTE') ?>: <?= $winners[0]->voteCount ?>
            </div>

            <div class="sppb-col-md-2"></div>
        </div>
        <br>

        <div class="sppb-row">
            <div class="sppb-col-md-2"></div>

            <div class="sppb-col-md-4">
                <div class="winner-text">
                    <b><?= JText::_('MOD_AL_VOTE_SECOND_PLACE') ?></b>
                </div>
                <a class="example-image-link" href="https://www.archlinexp.com/<?php echo $winners[1]->source->original; ?>" data-title="<?php echo $winners[1]->title; ?>" data-lightbox="example-1"><img class="example-image" src="https://www.archlinexp.com/<?php echo $winners[1]->source->original; ?>"></a>

                <?= JText::_('MOD_AL_VOTE_VOTE') ?>: <?= $winners[1]->voteCount ?>
            </div>

            <div class="sppb-col-md-4">
                <div class="winner-text">
                    <b><?= JText::_('MOD_AL_VOTE_THIRD_PLACE') ?></b>
                </div>
                <a class="example-image-link" href="https://www.archlinexp.com/<?php echo $winners[2]->source->original; ?>" data-title="<?php echo $winners[2]->title; ?>" data-lightbox="example-1"><img class="example-image" src="https://www.archlinexp.com/<?php echo $winners[2]->source->original; ?>"></a>

                <?= JText::_('MOD_AL_VOTE_VOTE') ?>: <?= $winners[2]->voteCount ?>
            </div>

            <div class="sppb-col-md-2"></div>
        </div>
        <br>
        <br>
    <?php endif; ?>

    <div class="winner-text">
        <b><?= JText::_('MOD_AL_VOTE_MORE_PICTURES') ?></b>
    </div>
    <br>

    <div class="sppb-row">
        <?php foreach ($album->images as $key => $item->image) : ?>
            <?php $source = json_decode($item->image->images); ?>

            <div class="sppb-col-md-3">
                <a class="example-image-link" href="https://www.archlinexp.com/<?php echo $source->original; ?>" data-title="<?php echo $item->image->title; ?>" data-lightbox="example-1"><img class="example-image" src="https://www.archlinexp.com/<?php echo $source->thumb; ?>"></a>

                <?php echo $item->image->title; ?>
                <br>
                <?= JText::_('MOD_AL_VOTE_VOTE') ?>: <?= $item->image->voteCount ?>

                <?php if (/*$user->id > 0 && !ModAlVoteHelper::isVoted($item->image->id, $album->id, $user->nUserID) && date('Y-m-d H:i:s') >= '2023-02-14 00:01:00'*/false) : ?>
                    <form class="vote-form" action="<?= JUri::current(); ?>" method="post">
                        <input type="hidden" name="picture_id" value="<?= $item->image->id ?>">
                        <input type="hidden" name="album_id" value="<?= $album->id ?>">

                        <input type="submit" class="btn btn-success btn-vote" name="picture_vote_btn" value="<?= JText::_('MOD_AL_VOTE_VOTE_2') ?>">
                    </form>
                <?php else : ?>
                    <!--<div class="vote-form">
                        <button class="btn btn-success btn-vote disabled" disabled><?= JText::_('MOD_AL_VOTE_VOTE_2') ?></button>
                    </div>-->
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<script>
    lightbox.option({
        'resizeDuration': 700,
        'wrapAround': true,
        'alwaysShowNavOnTouchDevices': true
    });
</script>