<div data-reload="product_question">
   <div class="product-question" data-form="#tabs-inquiry">
      {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}
         {include "block.messages.tpl"}

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

         {$labelClass = 'col-sm-3 col-xs-12 text-right form-control-label'}
         {$inputClass = 'col-sm-9 col-xs-12'}
         <form name="help" method="post" action="{$ctrl.currUrl.Abs}" role="form">
            <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 row required">
                  <label for="name" class="{$labelClass}">{t}Jméno a příjmení{/t}</label>
                  <div class="{$inputClass}">
                     <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>
               <div class="form-group row required">
                  <label for="email" class="{$labelClass}">{t}Váš e-mail{/t}</label>
                  <div class="{$inputClass}">
                     <input type="email" name="email" id="email" class="form-control" value="{$body.data.email}"
                            data-bv-notempty="true" data-bv-emailaddress-message="{t}Zadejte platnou e-mailovou adresu{/t}">
                  </div>
               </div>
               <div class="form-group row">
                  {get_contexts currency=1 country=1 assign="questionContexts"}
                  {$activeCountry = $questionContexts.country->getActive()}
                  <label for="phone" class="{$labelClass}">{t}Telefon{/t}</label>
                  <div class="{$inputClass}">
                     <input type="text" name="phone" id="phone" class="form-control" value="{$body.data.phone}"
                            data-bv-phone="true" data-bv-phone-country="{$activeCountry.id}" data-bv-phone-message="{t}Zadejte platné telefoní číslo{/t}">
                  </div>
               </div>
            {/if}
            <div class="form-group row required">
               <label for="subject" class="{$labelClass}">{t}Název výrobku{/t}</label>
               <div class="{$inputClass}">
                  <input type="text" name="subject" id="subject" class="form-control" value="{$body.data.subject}" disabled>
               </div>
            </div>
            <div class="form-group row required">
               <label for="message" class="{$labelClass}">{t}Dotaz{/t}</label>
               <div class="{$inputClass}">
                  <textarea id="message" name="message" class="form-control" rows="4" data-bv-notempty="true">{$body.data.message}</textarea>
               </div>
            </div>

            {if $ctrl.get_news != "Y"}
               <div class="form-group row">
                  <div class="col-xs-12 col-sm-9 col-sm-push-3">
                     <label class="custom-control custom-checkbox c-input c-checkbox">
                        <input class="custom-control-input" type="checkbox" name="get_news" value="Y">
                        <span class="c-indicator 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>
               </div>
            {/if}

            {if findModule('recaptcha')}
               <div class="form-group row required">
                  <label for="message" class="{$labelClass}">{t}Ověření{/t}</label>
                  <div class="{$inputClass}">
                     {include "block.recaptcha.tpl"}
                  </div>
               </div>
            {else}
               <div class="form-group row required {if $body.email.error == 'Chybně opsaný kód'}has-error{/if}">
                  <label for="captcha" class="{$labelClass}">{t}Opište kód z obrázku{/t}</label>
                  <div class="col-md-3 col-sm-3 col-xs-6">
                     <input type="text" name="captcha" id="captcha" class="form-control" value=""
                            data-bv-notempty="true" data-bv-stringlength="true" data-bv-stringlength-min="4">
                  </div>
                  <div class="col-md-3 col-sm-3 col-xs-6">
                     <img alt="captcha" src="{url s=captcha id=$smarty.now}">
                     <input type="hidden" name="captcha_id" value="{$smarty.now}">
                  </div>
               </div>
            {/if}
            <div class="form-group row">
               {block submit}
                  <div class="col-xs-12 col-sm-9 col-sm-offset-3">
                     <input class="btn btn-gray btn-lg btn-rounded" type="submit" name="SendQuestion" value="{t}Odeslat dotaz{/t}">
                  </div>
               {/block}
            </div>
         </form>
         <script>
            $('form[name=help]').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>
</div>
