<div data-reload="product_question">
   {if $body.sent}
      <div class="alert alert-success">
         {t}Dotaz byl úspěšně odeslán. Odpovíme Vám co nejdříve.{/t}
      </div>
   {else}
      <form method="post" action="{$ctrl.currUrl.Abs}" data-form="product-question">
         {include "block.messages.tpl"}

         {if $body.error}
            <div class="alert alert-danger">
               {$body.error}
            </div>
         {/if}

         <input type="hidden" name="url" value="{$body.data.url}">
         <input type="hidden" name="gtm_type" value="Dotaz na produkt">

         {if $ctrl.logged}
            <input type="hidden" name="name" value="{$ctrl.name} {$ctrl.surname}">
            <input type="hidden" name="email" value="{$ctrl.email}">
            <input type="hidden" name="phone" value="{$ctrl.phone}">
         {else}
            <div class="form-group required">
               <label for="name">{t}Jméno a příjmení{/t}</label>
               <input type="text" name="name" id="name" class="form-control" value="{$body.data.name}"
                      data-bv-notempty="true" data-bv-stringlength="true" data-bv-stringlength-min="3">
            </div>
            <div class="form-group required">
               <label for="email">{t}Váš e-mail{/t}</label>
               <input type="email" name="email" id="email" class="form-control" value="{$body.data.email}"
                      data-bv-notempty="true">
            </div>
            <div class="form-group">
               <label for="phone">{t}Telefon{/t}</label>
               <input type="text" name="phone" id="phone" class="form-control" value="{$body.data.phone}"
                      data-bv-phone="true" data-bv-phone-country="{$ctrl.active_country}">
            </div>
         {/if}
         <div class="form-group required">
            <label for="subject">{t}Název výrobku{/t}</label>
            <input type="text" name="subject" id="subject" class="form-control" value="{$body.data.subject}" disabled>
         </div>
         <div class="form-group required">
            <label for="message">{t}Dotaz{/t}</label>
            <textarea id="message" name="message" class="form-control" rows="4"
                      data-bv-notempty="true">{$body.data.message}</textarea>
         </div>

         {if $ctrl.get_news != "Y"}
            <div class="form-group">
               <label class="custom-control custom-checkbox">
                  <input class="custom-control-input" type="checkbox" name="get_news" value="Y">
                  <span class="custom-control-indicator"></span>
                  {t}Dostávat novinky{/t}
                  {if $dbcfg.gdpr.enable == 'Y'}
                     <small>(<a href="{url s=page label='consent'}"
                                target="_blank">{t}Souhlasím se zpracováním osobních údajů{/t}</a>)
                     </small>
                  {/if}
               </label>
            </div>
         {/if}

         {if findModule('recaptcha')}
            <div class="form-group required">
               <label for="message">{t}Ověření{/t}</label>
               {include "block.recaptcha.tpl"}
            </div>
         {/if}

         <div class="form-group">
            <button class="btn btn-primary btn-block" type="submit" name="SendQuestion" value="{t}Odeslat{/t}">{t}Odeslat{/t}</button>
         </div>
      </form>
      <script src="/common/static/bootstrapvalidator/js/bootstrapValidator.js"></script>
      <script src="/common/static/bootstrapvalidator/js/language/{$ctrl.active_language_code|default:'cs_CZ'}.js"></script>

      <script>
         var $form = $('form[data-form="product-question"]');
         $form.each(function() {
            if (!$(this).hasClass('bv-form')) {
               $(this).bootstrapValidator({
                  feedbackIcons: {
                     valid: 'fc fc-check',
                     invalid: 'fc fc-remove',
                     validating: 'fc fc-refresh',
                  },
               }).on('success.form.bv', function(e) {
                  // Prevent submit form
                  e.preventDefault();

                  var $this = $(e.target),
                          data = $this.serialize(),
                          url = $this.attr('action');

                  {include "block.gtm.tpl" gtm_type="form_conversion"}

                  wpj.domUtils.reloadPartsFromUrl(url, $this.closest('[data-reload]'), data);
               });
            }
         });
      </script>
   {/if}
</div>
