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

/** @var Mage_Catalog_Block_Product_View $this */
?>
<div class="page-title">
    <h1><?= $this->__('Share Your Wishlist') ?></h1>
</div>
<?= $this->getMessagesBlock()->toHtml() ?>
<form action="<?= $this->getSendUrl() ?>" id="form-validate" method="post">
    <div class="fieldset">
        <?= $this->getBlockHtml('formkey') ?>
        <h2 class="legend"><?= $this->__('Sharing Information') ?></h2>
        <ul class="form-list">
            <li class="wide">
                <label for="email_address" class="required"><em>*</em><?= $this->__('Up to 5 email addresses, separated by commas') ?></label>
                <div class="input-box">
                    <textarea name="emails" cols="60" rows="5" id="email_address" class="validate-emails required-entry"><?= $this->getEnteredData('emails') ?></textarea>
                </div>
            </li>
            <li class="wide">
                <label for="message"><?= $this->__('Message') ?></label>
                <div class="input-box">
                    <textarea id="message" name="message" cols="60" rows="3"><?= $this->getEnteredData('message') ?></textarea>
                </div>
            </li>
            <?php if($this->helper('wishlist')->isRssAllow()): ?>
            <li class="control">
                <div class="input-box">
                    <input type="checkbox" name="rss_url" id="rss_url" value="1" title="<?= Mage::helper('core')->quoteEscape($this->__('Check this checkbox if you want to add a link to an rss feed to your wishlist.')) ?>" class="checkbox" />
                </div>
                <label for="rss_url"><?= $this->__('Check this checkbox if you want to add a link to an rss feed to your wishlist.') ?></label>
            </li>
            <?php endif ?>
            <?= $this->getChildHtml('wishlist.sharing.form.additional.info') ?>
        </ul>
    </div>
    <div class="buttons-set form-buttons">
        <p class="required"><?= $this->__('* Required Fields') ?></p>
        <p class="back-link"><a href="<?= $this->getBackUrl() ?>"><small>&laquo; </small><?= $this->__('Back') ?></a></p>
        <button type="submit" title="<?= Mage::helper('core')->quoteEscape($this->__('Share Wishlist')) ?>" class="button"><?= $this->__('Share Wishlist') ?></button>
    </div>
</form>
<script type="text/javascript">
    Validation.add('validate-emails',
        '<?= Mage::helper('core')->jsQuoteEscape($this->__('Please enter a valid email addresses, separated by commas. For example johndoe@domain.com, johnsmith@domain.com.')) ?>',
        function (v) {
            if(Validation.get('IsEmpty').test(v)) {
                return true;
            }

            const valid_regexp = /^[a-z0-9\._-]{1,30}@([a-z0-9_-]{1,30}\.){1,5}[a-z]{2,4}$/i;
            const emails = v.split(',');

            for (let i = 0; i < emails.length; i++) {
                if(!valid_regexp.test(emails[i].trim())) {
                    return false;
                }
            }

            return true;
        }
    );

    var dataForm = new VarienForm('form-validate', true);
</script>
