<?php

/** @var Ess_M2ePro_Block_Adminhtml_Amazon_Template_Shipping_Edit_Form $this */

$formData = $this->getFormData();
$duplicateHeaderText = $this->getDuplicateHeaderText();
$accountOptions = $this->getAccountOptions();
$dictionaryOptions = $this->getDictionaryOptions();

?>

<script type="text/javascript">

    M2ePro.url.add(<?php echo json_encode(array(
        'formSubmit'    => $this->getUrl('M2ePro/adminhtml_amazon_template_shipping/save', array('id' => $this->getRequest()->getParam('id'))),
        'formSubmitNew' => $this->getUrl('M2ePro/adminhtml_amazon_template_shipping/save'),
        'deleteAction'  => $this->getUrl('M2ePro/adminhtml_amazon_template_shipping/delete', array('id' => $this->getRequest()->getParam('id'))),
        'refresh'  => $this->getUrl('M2ePro/adminhtml_amazon_template_shipping/refresh'),
        'getTemplates'  => $this->getUrl('M2ePro/adminhtml_amazon_template_shipping/getTemplates'),
    )); ?>);

    M2ePro.translator.add(<?php echo json_encode(array(
        'Add Shipping Policy' => Mage::helper('M2ePro')->__($duplicateHeaderText),
        'The specified Title is already used for other Policy. Policy Title must be unique.' => Mage::helper('M2ePro')->__('The specified Title is already used for other Policy. Policy Title must be unique.'),
    )); ?>);

    M2ePro.formData.id = '<?php echo $this->getRequest()->getParam('id'); ?>';
    M2ePro.formData.title = '<?php echo Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml($formData['title'])); ?>';

    Event.observe(window, 'load', function() {
        AmazonTemplateShippingObj = new AmazonTemplateShipping();
        AmazonTemplateShippingObj.initObservers();

        editForm = new varienForm('edit_form', '<?php echo $this->getValidationUrl(); ?>');
    });
    //-----------------------------

</script>

<div id="block_notice_amazon_template_shipping" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Shipping Policy'); ?>">
    <?php
    echo Mage::helper('M2ePro')->__(
        'Shipping Policy allows applying Amazon Shipping Templates to your offers via M2E Pro.<br /><br />
         More details can be found <a href="%url%" target="_blank">here</a>.',
        Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, 'shipping-policies')
    ); ?>
</div>

<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_template_shipping_general">

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

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

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

                <tr>
                    <td class="label">
                        <label for="title"><?php echo Mage::helper('M2ePro')->__('Title'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value">
                        <input id="title" name="title" value="<?php echo $this->escapeHtml($formData['title']); ?>" type="text" class="input-text required-entry M2ePro-shipping-tpl-title"/>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Short meaningful Policy Title for your internal use.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr>
                    <td class="label">
                        <label for="account"><?php echo Mage::helper('M2ePro')->__('Account'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value">
                        <select id="account_id" name="account_id" class="required-entry" <?= $this->getAttributesForAccountSelect() ?> >
                            <?php foreach($accountOptions as $option) : ?>
                                <option value="<?= $option['value'] ?>" <?= $option['attrs'] ?> >
                                    <?= $option['label']; ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>

            </table>

        </div>
    </div>

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

    <div class="fieldset">
        <div class="hor-scroll">
            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr id="template_name_custom_value_tr">
                    <td class="label">
                        <label for="template_id"><?php echo Mage::helper('M2ePro')->__('Template'); ?>: <span class="required">*</span></label>
                    </td>
                    <td class="value">
                        <select id="template_id" name="template_id" class="required-entry">
                            <?php foreach($dictionaryOptions as $option) : ?>
                                <option value="<?= $option['value'] ?>" <?= $option['attrs'] ?> >
                                    <?= $option['label']; ?>
                                </option>
                            <?php endforeach; ?>
                        </select>

                        <button id="refresh_templates" style="margin-left: 50px;">
                            <?php echo Mage::helper('M2ePro')->__('Refresh Templates'); ?>
                        </button>
                    </td>
                </tr>

            </table>
        </div>
    </div>

</div>

</form>