<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2024 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)
 */
?>
<script type="text/javascript">
var added = false;
function addProduct(closeAfter) {
    if(window.opener != null && !added) {
        if (window.opener.superProduct) {
            <?php if($this->isEdit()): ?>
            window.opener.superProduct.updateProduct(<?= $this->getProductId() ?>, <?= $this->getAttributesJson() ?>);
            <?php else: ?>
            window.opener.superProduct.addNewProduct(<?= $this->getProductId() ?>, <?= $this->getAttributesJson() ?>);
            window.opener.superProduct.showNoticeMessage();
            <?php endif ?>
            added = true;
        } else if (window.opener.catalog_category_productsJsObject) {
            window.opener.catalog_category_productsJsObject.reload(null);
        }
    }

    if(closeAfter)
    {
        closeWindow();
    }
}

function closeWindow()
{
    if (window.opener) {
        window.opener.focus();
    }
    window.close();
}

addProduct(false);
setTimeout(closeWindow, 3000);
</script>
<div class="a-center">
<?= $this->getCloseButtonHtml() ?>
</div>
