<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Send to friend form
 *
 * @var $block \Magento\SendFriend\Block\Send
 */
?>
<script id="add-recipient-tmpl" type="text/x-magento-template">
    <fieldset class="cs-form__fieldset cs-form__fieldset--level_1">
        <div class="cs-form__field | cs-input | field name required">
            <label for="recipients-name<%- data._index_ %>" class="cs-input__label"><?php /* @escapeNotVerified */ echo __('Name')?></label>
            <div class="cs-input__control">
                <input name="recipients[name][<%- data._index_ %>]" type="text" title="<?php /* @escapeNotVerified */ echo __('Name') ?>" class="cs-input__input cs-input__input--with-button"
                       id="recipients-name<%- data._index_ %>" data-validate="{required:true}"/>
                <div class="cs-input__button">
                    <button type="button" id="btn-remove<%- data._index_ %>" class="cs-button cs-button--look_default cs-button--look_on-input" title="<?php /* @escapeNotVerified */ echo $block->escapeJsQuote(__('Remove Recipent')) ?>">
                        <svg class="cs-button__icon cs-button__icon--center cs-button__icon--plus"><use xlink:href="#close"></use>
                        <span class="cs-visually-hidden"><?php /* @escapeNotVerified */ echo $block->escapeJsQuote(__('Remove')) ?></span>
                    </button>
                </div>
            </div>
        </div>

        <div class="cs-form__field | cs-input | field email required">
            <label for="recipients-email<%- data._index_ %>" class="cs-input__label"><?php /* @escapeNotVerified */ echo __('Email') ?></label>
            <div class="cs-input__control">
                <input name="recipients[email][<%- data._index_ %>]" title="<?php /* @escapeNotVerified */ echo __('Email') ?>"
                       id="recipients-email<%- data._index_ %>" type="email" class="cs-input__input"
                       data-validate="{required:true, 'validate-email':true}"/>
            </div>
        </div>
    </fieldset>
</script>

<form action="<?php /* @escapeNotVerified */ echo $block->getSendUrl() ?>" method="post" id="product-sendtofriend-form"
      data-mage-init='{
        "rowBuilder":{
            "rowTemplate":"#add-recipient-tmpl",
            "rowContainer":"#recipients-options",
            "rowParentElem":"<div></div>",
            "remEventSelector":"button",
            "btnRemoveSelector":".cs-button--look_on-input",
            "maxRows":"<?php /* @escapeNotVerified */ echo $block->getMaxRecipients() ?>",
            "maxRowsMsg":"#max-recipient-message",
            "addRowBtn":"#add-recipient-button",
            "additionalRowClass":""},
        "validation":{}}'
      class="cs-form | form send friend" data-hasRequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
    <fieldset class="cs-form__fieldset cs-form__fieldset--level_1 | fieldset sender" id="sender_options">
        <?php echo $block->getBlockHtml('formkey')?>
        <legend class="cs-title-block cs-title-block--bordered cs-title-block--space-bottom">
            <span class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light"><?php /* @escapeNotVerified */ echo __('Sender') ?></span>
        </legend>

        <div class="cs-form__field | cs-input | field sender required">
            <label for="sender-name" class="cs-input__label"><?php /* @escapeNotVerified */ echo __('Name') ?></label>
            <div class="cs-input__control">
                <input name="sender[name]" value="<?php echo $block->escapeHtml($block->getUserName()) ?>"
                       title="<?php /* @escapeNotVerified */ echo __('Name') ?>" id="sender-name" type="text" class="cs-input__input"
                       data-validate="{required:true}"/>
            </div>
        </div>

        <div class="cs-form__field | cs-input | field email required">
            <label for="sender-email" class="cs-input__label"><?php /* @escapeNotVerified */ echo __('Email') ?></label>
            <div class="cs-input__control">
                <input name="sender[email]" value="<?php echo $block->escapeHtml($block->getEmail()) ?>"
                       title="<?php /* @escapeNotVerified */ echo __('Email') ?>" id="sender-email" type="text" class="cs-input__input"
                       data-validate="{required:true, 'validate-email':true}"/>
            </div>
        </div>

        <div class="cs-form__field | cs-input | field text required">
            <label for="sender-message" class="cs-input__label"><?php /* @escapeNotVerified */ echo __('Message') ?></label>
            <div class="cs-input__control">
                <textarea name="sender[message]" class="cs-input__textarea" id="sender-message" cols="3" rows="3"
                          data-validate="{required:true}" style="min-height: 8rem"><?php echo $block->escapeHtml($block->getMessage()) ?></textarea>
            </div>
        </div>
    </fieldset>

    <fieldset class="cs-form__fieldset cs-form__fieldset--level_1 | fieldset recipients">
        <?php echo $block->getBlockHtml('formkey')?>
        <legend class="cs-title-block cs-title-block--bordered cs-title-block--space-bottom">
            <span class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light"><?php /* @escapeNotVerified */ echo __('Invitee') ?>
            </span>
        </legend>

        <div id="recipients-options"></div>

        <?php if ($block->getMaxRecipients()): ?>
            <div id="max-recipient-message" style="display: none;" class="cs-messages" role="alert">
                <div class="messages | cs-messages__inner">
                    <div class="cs-messages__message cs-messages__message--info">
                        <div class=""><?php /* @escapeNotVerified */ echo __('Maximum %1 email addresses allowed.', $block->getMaxRecipients()) ?></div>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <div class="cs-button__set cs-button__set--justify">
            <?php if (1 < $block->getMaxRecipients()): ?>
                <button type="button" id="add-recipient-button" class="cs-button cs-button--look_light">
                    <span class="cs-button__span"><?php /* @escapeNotVerified */ echo __('Add Invitee') ?></span>
                    <svg class="cs-button__icon"><use xlink:href="#arrow_next"></use></svg>
                </button>
            <?php endif; ?>
            <button type="submit" class="cs-button cs-button--look_default"<?php if (!$block->canSend()): ?> disabled="disabled"<?php endif ?>>
                <span class="cs-button__span"><?php /* @escapeNotVerified */ echo __('Send Email') ?></span>
                <svg class="cs-button__icon"><use xlink:href="#arrow_next"></use></svg>
            </button>
        </div>
    </fieldset>
</form>

<script type="text/x-magento-init">
    {
        "a[role='back']": {
            "Magento_SendFriend/back-event": {}
        }
    }
</script>
