<?php

use Ess_M2ePro_Helper_Component_Amazon_Configuration as Config;

/** @var Ess_M2ePro_Block_Adminhtml_Amazon_Configuration_General_Form $this */

$magentoAttributes = $this->getMagentoAttributes();
$config = $this->getConfigurationHelper();

?>

<script type="text/javascript">

    M2ePro.url.add(<?php echo json_encode(array(
        'formSubmit' => $this->getUrl('M2ePro/adminhtml_amazon_general/save'),
    )); ?>);

    Event.observe(window, 'load', function() {
        editForm = new varienForm('<?php echo $this->getForm()->getId(); ?>', '<?php echo $this->getValidationUrl(); ?>');

        AmazonConfigurationObj = new AmazonConfiguration();
        $('general_id_mode')
            .observe('change', AmazonConfigurationObj.generalIdModeChange)
            .simulate('change');

        $('worldwide_id_mode')
            .observe('change', AmazonConfigurationObj.worldwideIdModeChange)
            .simulate('change');

    });

</script>

<form id="<?php echo $this->getForm()->getId(); ?>" action="<?php echo $this->getForm()->getData('action'); ?>" method="post" enctype="multipart/form-data">

    <input name="form_key" value="<?php echo $this->getFormKey(); ?>" type="hidden" />

    <div class="entry-edit" id="magento_block_amazon_configuration_general_business" collapseable="no">

        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Business (B2B)'); ?></h4>
        </div>

        <div class="fieldset">
            <div class="hor-scroll">

                <table class="form-list" cellspacing="0" cellpadding="0">

                    <colgroup class="label"></colgroup>
                    <colgroup class="value"></colgroup>

                    <tbody>

                        <tr>
                            <td class="label">
                                <label for="business_mode"><?php echo Mage::helper('M2ePro')->__('Price, QTY Discounts'); ?>: </label>
                            </td>
                            <td class="value">
                                <select id="business_mode" name="business_mode">
                                    <option value="0" <?php if (!$config->isEnabledBusinessMode()) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Disabled'); ?></option>
                                    <option value="1" <?php if ($config->isEnabledBusinessMode()) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Enabled'); ?></option>
                                </select>
                                <p class="note">
                                    <span><?php echo Mage::helper('M2ePro')->__('
                                        After you <strong>Enable</strong> this option, you can provide the settings for <strong>Business Price</strong> and <strong >Quantity Discounts</strong> within M2E Pro Selling Policy.<br />
                                        <strong>Note:</strong> your Business Account must be approved by Amazon.'
                                    ); ?></span>
                                </p>
                            </td>
                        </tr>

                    </tbody>

                </table>

            </div>
        </div>

    </div>

    <div class="entry-edit" collapseable="no">

        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Product Identifiers'); ?></h4>
        </div>

        <div class="fieldset">
            <div class="hor-scroll">

                <table class="form-list" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="label">
                            <label for="general_id"><?= Mage::helper('M2ePro')->__('ASIN / ISBN'); ?>: </label>
                        </td>
                        <td class="value">
                            <input type="hidden" id="general_id_custom_attribute" name="general_id_custom_attribute" value="<?= $config->getGeneralIdCustomAttribute() ?>"/>
                            <select id="general_id_mode" name="general_id_mode" class="M2ePro-custom-attribute-can-be-created" allowed_attribute_types="text,select">
                                <option value="<?= Config::GENERAL_ID_MODE_NONE ?>"  <?= $config->isGeneralIdModeNone() ? ' selected="selected"' : '' ?>><?= Mage::helper('M2ePro')->__('Not Set')?></option>
                                <optgroup class="M2ePro-custom-attribute-optgroup" label="Magento Attribute" new_option_value="<?= Config::GENERAL_ID_MODE_CUSTOM_ATTRIBUTE; ?>">
                                    <?php foreach($magentoAttributes as $attribute) : ?>
                                        <option attribute_code="<?php echo $attribute['code']; ?>" value="<?= Config::GENERAL_ID_MODE_CUSTOM_ATTRIBUTE; ?>" <?php if ($config->getGeneralIdCustomAttribute() && $attribute['code'] == $config->getGeneralIdCustomAttribute()): ?>selected="selected"<?php endif; ?>>
                                            <?php echo Mage::helper('M2ePro')->escapeHtml($attribute['label']); ?>
                                        </option>
                                    <?php endforeach; ?>
                                </optgroup>
                            </select>
                            <p class="note">
                               <span>
                                   <?= Mage::helper('M2ePro')->__('This setting is a source for ASIN/ISBN value which will be used at the time of Automatic Search of Amazon Products.'); ?>
                               </span>
                            </p>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">
                            <label for="worldwide_id"><?= Mage::helper('M2ePro')->__('UPC / EAN'); ?>: </label>
                        </td>
                        <td class="value">
                            <input type="hidden" id="worldwide_id_custom_attribute" name="worldwide_id_custom_attribute" value="<?= $config->getWorldwideCustomAttribute() ?>"/>
                            <select id="worldwide_id_mode" name="worldwide_id_mode" class="M2ePro-custom-attribute-can-be-created" allowed_attribute_types="text,select">
                                <option value="<?= Config::WORLDWIDE_ID_MODE_NONE ?>" <?= $config->isWorldwideIdModeNone() ? ' selected="selected"' : '' ?>><?= Mage::helper('M2ePro')->__('Not Set')?></option>
                                <optgroup class="M2ePro-custom-attribute-optgroup" label="Magento Attribute" new_option_value="<?= Config::WORLDWIDE_ID_MODE_CUSTOM_ATTRIBUTE; ?>">
                                    <?php foreach($magentoAttributes as $attribute) : ?>
                                        <option attribute_code="<?php echo $attribute['code']; ?>" value="<?= Config::WORLDWIDE_ID_MODE_CUSTOM_ATTRIBUTE; ?>" <?php if ($config->getWorldwideCustomAttribute() && $attribute['code'] == $config->getWorldwideCustomAttribute()): ?>selected="selected"<?php endif; ?>>
                                            <?php echo Mage::helper('M2ePro')->escapeHtml($attribute['label']); ?>
                                        </option>
                                    <?php endforeach; ?>
                                </optgroup>
                            </select>
                            <p class="note">
                               <span>
                                   <?= Mage::helper('M2ePro')->__('Amazon uses these Product IDs to associate your Item with its catalog or to create a new ASIN/ISBN. Select the attribute where the UPC/EAN values are stored.'); ?>
                               </span>
                            </p>
                        </td>
                    </tr>
                </table>

            </div>
        </div>
</form>
