<?php

$id = Str::random(5);

$moduleHtml = '
    <form id="{id}" class="contact-form has-captcha" action="/reviews/store" method="POST">
        <div class="validation"></div>

        <div class="form-group">
            <input class="form-control"
                   name="title"
                   type="text"
                   maxlength="100"
                   value=""
                   data-msg-required="Please enter your opinion."
                   placeholder="Your opinion in one sentence..."
                   required
            >
        </div>

        <div class="form-group">
            <textarea class="form-control"
                      name="content"
                      maxlength="5000"
                      data-msg-required="Please enter your review."
                      placeholder="Your full review..."
                      required
            ></textarea>
        </div>

        <div class="form-group">
            <select class="form-control" name="rating" required>
                <option value="1">1 Star</option>
                <option value="2">2 Star</option>
                <option value="3">3 Star</option>
                <option value="4">4 Star</option>
                <option value="5" selected="selected">5 Star</option>
            </select>
        </div>

        <div class="form-group">
            <input class="form-control"
                   name="name"
                   type="text"
                   maxlength="100"
                   value=""
                   data-msg-required="Please enter your full name."
                   placeholder="Your Name..."
                   required
            >
        </div>

        <div class="form-group">
            <input class="form-control"
                   name="email"
                   type="email"
                   maxlength="100"
                   data-msg-required="Please enter your email address."
                   data-msg-email="Please enter a valid email address."
                   placeholder="Your Email Address..."
                   required
            >
        </div>

        <div class="form-group">
            <button class="form-submit btn btn-primary font-weight-bold text-uppercase"
                    type="submit"
            >
                Submit
            </button>
        </div>
    </form>
';

$moduleHtml .= '
    <script>
        var docReady{id} = function (fn) {
            var stateCheck = setInterval(function () {
                if (document.readyState !== "complete") return;
                clearInterval(stateCheck);
                try {fn()} catch (e) {}
            }, 1000);
        };
        docReady{id}(function () {
            let validationRequest{id} = new ValidationRequest("{id}", "review");
            validationRequest{id}.init();
        });
    </script>
';

$moduleHtml = str_replace('{id}', $id, $moduleHtml);

$moduleSettings = '
    {
        "style": "form-block"
    }
';
?>

<div class="row clearfix">
    <div class="column full"
         data-module="review-form"
         data-dialog-width="500px"
         data-module-desc="Review Form"
         data-html="{{ encode_uri_component($moduleHtml) }}"
         data-settings="{{ encode_uri_component($moduleSettings) }}"
    >
    </div>
</div>
