<?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)
 */

/** @var Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Websites $this */
?>
<div class="entry-edit">
    <div class="entry-edit-head">
        <h4><?= Mage::helper('catalog')->__('Product In Websites') ?></h4>
    </div>
    <fieldset id="grop_fields">
    <?php if($this->getProductId()): ?>
        <ul class="messages">
            <li class="notice-msg">
                <ul>
                    <li><?= Mage::helper('catalog')->__("Items that you don't want to show in the catalog or search results should have status 'Disabled' in the desired store.") ?></li>
                </ul>
            </li>
        </ul>
    <?php endif ?>
    <div class="store-scope">
        <div class="tree-store-scope">
            <?php foreach ($this->getWebsiteCollection() as $_website): ?>
            <div class="website-name">
                <input name="product[website_ids][]" value="<?= $_website->getId() ?>" <?php if ($this->isReadonly()):?> disabled="disabled"<?php endif ?> class="checkbox website-checkbox" id="product_website_<?= $_website->getId() ?>" type="checkbox"<?php if($this->hasWebsite($_website->getId())): ?> checked="checked"<?php endif ?> />
                <big><strong><label for="product_website_<?= $_website->getId() ?>"><?= $this->escapeHtml($_website->getName()) ?></label></strong></big>
            </div>
            <div class="webiste-groups" id="product_website_<?= $_website->getId() ?>_data">
            <?php foreach ($this->getGroupCollection($_website) as $_group): ?>
                <h4><?= $this->escapeHtml($_group->getName()) ?></h4>
                <div class="group-stores">
                <table>
                <?php foreach ($this->getStoreCollection($_group) as $_store): ?>
                    <tr>
                        <td><?= $this->escapeHtml($_store->getName()) ?></td>
                        <td>
                        <?php if($this->getWebsites() && !$this->hasWebsite($_website->getId())): ?>
                            <span class="website-<?= $_website->getId() ?>-select" style="display:none">
                            <?= Mage::helper('catalog')->__('(Copy data from: %s)', $this->getChooseFromStoreHtml($_store)) ?>
                            </span>
                        <?php endif ?>
                        </td>
                    </tr>
                <?php endforeach ?>
                </table>
                </div>
            <?php endforeach ?>
            </div>
            <?php endforeach ?>
        </div>
    </div>
    </fieldset>
</div>
<script type="text/javascript">
//<![CDATA[
    var productWebsiteCheckboxes = $$('.website-checkbox');

    for(var i=0;i<productWebsiteCheckboxes.length;i++){
        Event.observe(productWebsiteCheckboxes[i], 'click', toggleStoreFromChoosers);
    }

    function toggleStoreFromChoosers(event){
        var element = Event.element(event);
        var selects = $('product_website_'+element.value+'_data').getElementsBySelector('select');
        var selectBlocks = $('product_website_'+element.value+'_data').getElementsByClassName('website-'+element.value+'-select');
        for (var i=0; i<selects.length; i++) {
            selects[i].disabled=!element.checked;
        }
        for (var i=0; i<selectBlocks.length; i++) {
            if (element.checked) {
                selectBlocks[i].show();
            }
            else {
                selectBlocks[i].hide();
            }
        }
    }
//]]>
</script>
