<?php
/**
 * Maho
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2022 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $_width=$this->getImageWidth() ?>
<div class="product-image-popup" style="width:<?= $_width ?>px;">
    <div class="buttons-set"><a href="#" onclick="window.close(); return false;" class="button"><span><?= $this->__('Close Window') ?></span></a></div>
    <?php if($this->getPreviusImageUrl() || $this->getNextImageUrl()): ?>
        <div class="nav">
          <?php if($_prevUrl = $this->getPreviusImageUrl()): ?>
              <a href="<?= $_prevUrl ?>" class="prev">&laquo; <?= $this->__('Prev') ?></a>
          <?php endif ?>
          <?php if($_nextUrl = $this->getNextImageUrl()): ?>
              <a href="<?= $_nextUrl ?>" class="next"><?= $this->__('Next') ?> &raquo;</a>
          <?php endif ?>
        </div>
    <?php endif ?>
    <?php if($_imageTitle = $this->escapeHtml($this->getCurrentImage()->getLabel())): ?>
        <h1 class="image-label"><?= $_imageTitle ?></h1>
    <?php endif ?>
    <img src="<?= $this->helper('catalog/image')->init($this->getProduct(), 'image', $this->getImageFile()) ?>"<?php if($_width): ?> width="<?= $_width ?>"<?php endif ?> alt="<?= $this->escapeHtml($this->getCurrentImage()->getLabel()) ?>" title="<?= $this->escapeHtml($this->getCurrentImage()->getLabel()) ?>" id="product-gallery-image" class="image" />
    <div class="buttons-set"><a href="#" onclick="window.close(); return false;" class="button"><span><?= $this->__('Close Window') ?></span></a></div>
    <?php if($this->getPreviusImageUrl() || $this->getNextImageUrl()): ?>
        <div class="nav">
          <?php if($_prevUrl = $this->getPreviusImageUrl()): ?>
              <a href="<?= $_prevUrl ?>" class="prev">&laquo; <?= $this->__('Prev') ?></a>
          <?php endif ?>
          <?php if($_nextUrl = $this->getNextImageUrl()): ?>
              <a href="<?= $_nextUrl ?>" class="next"><?= $this->__('Next') ?> &raquo;</a>
          <?php endif ?>
        </div>
    <?php endif ?>
</div>
<script type="text/javascript">
    window.addEventListener('load', function() {
        const image = document.getElementById('product-gallery-image');
        const dimensions = {
            width: image.offsetWidth,
            height: image.offsetHeight
        };

        if (dimensions.width < 300) {
            dimensions.width = 300;
        }

        window.resizeTo(dimensions.width + 90, dimensions.height + 210);
    });
</script>
