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

// @codingStandardsIgnoreFile

/**
 * @var $block \Magento\Review\Block\Form
 */
?>
<div class="panel panel-default review-add">
    <div class="panel-heading"><strong><?php /* @escapeNotVerified */ echo __('Write Your Own Review') ?></strong></div>
    <div class="panel-body">
        <?php if ($block->getAllowWriteReviewFlag()): ?>
            <form action="<?php /* @escapeNotVerified */ echo $block->getAction() ?>" class="review-form" method="post" id="review-form" data-role="product-review-form" data-bind="scope: 'review-form'">
                <?php echo $block->getBlockHtml('formkey'); ?>
                <?php echo $block->getChildHtml('form_fields_before')?>
                <fieldset class="fieldset review-fieldset" data-hasrequired="<?php __('* Required Fields'); ?>">
                    <legend class="legend review-legend">
                        <span><?php /* @escapeNotVerified */ echo __("You're reviewing:"); ?></span>
                        <strong><?php echo $block->escapeHtml($block->getProductInfo()->getName()) ?></strong>
                    </legend>
                    <?php if ($block->getRatings() && $block->getRatings()->getSize()): ?>
                        <span id="input-message-box"></span>
                        <fieldset class="field required review-field-ratings">
                            <div class="control">
                                <div class="nested" id="product-review-table">
                                    <?php foreach ($block->getRatings() as $_rating): ?>
                                        <div class="form-group field choice review-field-rating">
                                            <label ><span><?php /* @escapeNotVerified */ echo __('Your Rating') ?><span></label>
                                            <div class="control review-control-vote">
                                                <?php $options = $_rating->getOptions();?>
                                                <?php $iterator = 1; foreach ($options as $_option): ?>
                                                    <label
                                                        class="radio-inline rating-<?php /* @escapeNotVerified */ echo $iterator; ?>"
                                                        for="<?php echo $block->escapeHtml($_rating->getRatingCode()) ?>_<?php /* @escapeNotVerified */ echo $_option->getValue() ?>"
                                                        title="<?php /* @escapeNotVerified */ echo __('%1 %2', $iterator, $iterator > 1 ? 'stars' : 'star') ?>"
                                                        id="<?php echo $block->escapeHtml($_rating->getRatingCode()) ?>_<?php /* @escapeNotVerified */ echo $_option->getValue() ?>_label">

                                                        <input
                                                            type="radio"
                                                            name="ratings[<?php /* @escapeNotVerified */ echo $_rating->getId() ?>]"
                                                            id="<?php echo $block->escapeHtml($_rating->getRatingCode()) ?>_<?php /* @escapeNotVerified */ echo $_option->getValue() ?>"
                                                            value="<?php /* @escapeNotVerified */ echo $_option->getId() ?>"
                                                            data-validate="{required:true, messages:{required:'Please select one of each of the ratings above.'}}"
                                                            aria-labelledby="<?php echo $block->escapeHtml($_rating->getRatingCode()) ?>_rating_label <?php echo $block->escapeHtml($_rating->getRatingCode()) ?>_<?php /* @escapeNotVerified */ echo $_option->getValue() ?>_label" />

                                                        <?php /* @escapeNotVerified */ echo __('%1 %2', $iterator, $iterator > 1 ? 'stars' : 'star') ?>
                                                    </label>
                                                    <?php $iterator++; ?>
                                                <?php endforeach; ?>
                                            </div>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                                <input type="hidden" name="validate_rating" class="validate-rating" value="" />
                            </div>
                        </fieldset>
                    <?php endif ?>
                    <div class="form-group field review-field-nickname required">
                        <label for="nickname_field"><span><?php /* @escapeNotVerified */ echo __('Nickname') ?></span></label>
                        <div class="control">
                            <input type="text" name="nickname" id="nickname_field" class="form-control input-text" data-validate="{required:true}" data-bind="value: nickname()" />
                        </div>
                    </div>
                    <div class="form-group field review-field-summary required">
                        <label for="summary_field"><span><?php /* @escapeNotVerified */ echo __('Summary') ?></span></label>
                        <div class="control">
                            <input type="text" name="title" id="summary_field" class="form-control input-text" data-validate="{required:true}" data-bind="value: review().title" />
                        </div>
                    </div>
                    <div class="form-group field review-field-text required">
                        <label for="review_field"><span><?php /* @escapeNotVerified */ echo __('Review') ?></span></label>
                        <div class="control">
                            <textarea class="form-control" name="detail" id="review_field" cols="5" rows="3" data-validate="{required:true}" data-bind="value: review().detail"></textarea>
                        </div>
                    </div>
                </fieldset>
                <div class="form-group actions-toolbar review-form-actions">
                    <div class="primary actions-primary">
                        <button type="submit" class="btn btn-primary action submit primary"><span><?php /* @escapeNotVerified */ echo __('Submit Review') ?></span></button>
                    </div>
                </div>
            </form>
            <script type="text/x-magento-init">
            {
                "[data-role=product-review-form]": {
                    "Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
                },
                "#review-form": {
                    "Magento_Review/js/error-placement": {}
                }
            }
            </script>
        <?php else: ?>
            <div class="message info notlogged" id="review-form">
                <div>
                    <?php /* @escapeNotVerified */ echo __('Only registered users can write reviews. Please <a href="%1">Sign in</a> or <a href="%2">create an account</a>', $block->getLoginLink(), $block->getRegisterUrl()) ?>
                </div>
            </div>
        <?php endif ?>
    </div>
</div>
