{extends "[shared]/list.tpl"}

{block css append}
   <link href="./static/fancybox2/jquery.fancybox.css" rel="stylesheet" media="screen">
{/block}

{block body}
   {$smarty.block.parent}
   <div data-wpj-modal-mount></div>
{/block}

{block "list-wrapper-class"}translations-modal{/block}

{block "js-onready" append}
   <script type="text/javascript" src="../ckeditor/ckeditor.js"></script>

   <script src="/admin/static/fineuploader/jquery.fine-uploader.min.js"></script>
   <script type="text/template" id="qq-simple-thumbnails-template">
      <div class="qq-uploader-selector qq-uploader">
         <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
            <div>
               <span></span>Přesuňte soubory sem
            </div>
         </div>
         <div class="qq-upload-button-selector">
            <p>
               <strong>Nahrát obrázek</strong>
               podporované formáty jsou .jpg, .jpeg, .png, .webp, .avif, .gif
            </p>
         </div>
         <span class="qq-drop-processing-selector qq-drop-processing">
         <span>Zpracovávám soubory...</span>
         <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
      </span>
         <ul class="qq-upload-list-selector qq-upload-list">
            <li>
               <div class="qq-progress-bar-container-selector">
                  <div class="qq-progress-bar-selector qq-progress-bar"></div>
               </div>
               <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
               <div class="qq-thumb-img">
                  <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
               </div>
               <span class="qq-edit-filename-icon-selector qq-edit-filename-icon"></span>
               <span class="qq-upload-file-selector qq-upload-file"></span>
               <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
               <span class="qq-upload-size-selector qq-upload-size"></span>
               <a class="qq-upload-cancel-selector qq-upload-cancel" href="#">Zrušit</a>
               <a class="qq-upload-retry-selector qq-upload-retry" href="#">Opakovat</a>
               <a class="qq-upload-delete-selector qq-upload-delete" href="#">Smazat</a>
               <span class="qq-upload-status-text-selector qq-upload-status-text"></span>
            </li>
         </ul>
      </div>
   </script>
   {encore_entry_script_tags entry='translate' build='admin'}
{/block}

{block "list-content"}
   {if !$iframe}
      <form method="get" data-frm-filter action="" class="paramsContainer viewParams form-horizontal" role="form" enctype="multipart/form-data">

         <input type="hidden" name="s" value="list.php">
         <input type="hidden" name="type" value="{$listType}">

         <div class="panel panel-primary first">
            <div class="panel-heading">
               <h3 class="panel-title">{translate_type type=('translate.'|cat:$listType)}</h3>
            </div>
            <div class="panel-body">
               {if !getVal('is_modal')}
                  <div class="form-group form-group-flex">
                     <div class="col-lg-12 text-right">
                        <a href="javascript:nw('exportTranslations', '{$listType}', 'sourceLanguage={$sourceLanguage}&language={$language}')">Export</a> /
                        <a href="javascript:nw('importTranslations', '{$listType}', 'sourceLanguage={$sourceLanguage}&language={$language}')">Import</a>
                     </div>
                  </div>
               {/if}
               {block translationSettings}
                  <div class="form-group form-group-flex translations-settings">
                     <label class="col-md-1 control-label" for="filterFrm_SourceLanguage" style="white-space: nowrap;">{'translate_from'|translate:'translations'}</label>
                     <div class="col-md-2">
                        {print_select name='sourceLanguage' var=$sourceLanguages selected=$sourceLanguage param='id="filterFrm_SourceLanguage"'}
                     </div>
                     <label class="col-md-1 control-label" for="filterFrm_Language" style="white-space: nowrap;">{'translate_to'|translate:'translations'}</label>
                     <div class="col-md-2">
                        {print_select name='language' var=$languages selected=$language param='id="filterFrm_Language"'}
                     </div>
                     {if !getVal('is_modal')}
                        <label class="col-md-1 control-label" for="filterFrm_ItemsPerPage" title="{'items_per_page'|translate:'translations'}">
                           {'items_per_page_short'|translate:'translations'}
                        </label>
                        <div class="col-md-1">
                              {print_select name='itemsPerPage' var=$itemsPerPageOptions selected=$filters.itemsPerPage.selected param='id="filterFrm_ItemsPerPage"'}
                        </div>
                     {/if}
                     <label class="col-md-1 control-label" for="googleTranslate" title="Google Translate">
                        {'googleTranslate'|translate:'translations'}</label>
                     </label>
                     <div class="col-md-1">
                        {print_toggle nameRaw="googleTranslate" value="{$googleTranslate}"}
                     </div>
                     {if $googleTranslate == 'Y'}
                        <div class="col-md-2">
                           <button type="button" data-google-translate="page" class="btn">
                              {'autoTranslatePage'|translate:'translations'}
                           </button>
                        </div>
                     {/if}
                     {if getVal('objectIDs')}
                         <input type="hidden" name="objectIDs" value="{getVal('objectIDs')}" />
                     {/if}
                     {if getVal('is_modal')}
                         <input type="hidden" name="is_modal" value="{getVal('is_modal')}" />
                     {/if}
                     <div class="col-md-2">
                        <button type="submit" name="action" class="btn btn-primary filter-action" value="filter">{'use'|translate:'translations'}</button>
                     </div>
                  </div>
               {/block}
            </div>
         </div>

      {if !getVal('is_modal')}
         <div class="panel panel-success">
            <div class="panel-heading">
               <h3 class="panel-title">{'objectsFilter'|translate:'translations'}</h3>
            </div>
            <div class="panel-body">
               {block objectsFilter}
                  <div class="form-group form-group-flex">
                     <label class="col-md-1 control-label">Hledat</label>
                     <div class="col-md-4">
                        <div class="row bottom-space">
                           <div class="col-md-6">
                              <input placeholder="{'filter.byObjectIDs'|translate:'translations'}" type="text" name="objectIDs" value="{$filters.objectIDs.selected}"
                                 class="form-control">
                           </div>
                           <div class="col-md-6" style="padding-left:0;">
                              {if $filters.objectName.enabled}
                                 <input placeholder="{'filter.byObjectName'|translate:'translations'}" type="text" name="objectName" value="{$filters.objectName.selected}"
                                    class="form-control">
                              {/if}
                           </div>
                        </div>

                        <div style="border-top:2px solid #AAB2BD;border-bottom:2px solid #AAB2BD;padding:10px 0">
                           <div class="row bottom-space" style="padding-top: 0">
                              <div class="col-md-6">
                                 <input placeholder="Hledat" type="text" name="search[term]" class="form-control" value="{$filters.search.term}">
                              </div>
                              <div class="col-md-6" style="padding-left:0;">
                                 <select class="selecter" data-placeholder="Ve všech polích" name="search[in]">
                                    <option value="original" {$filters.search.in|selected:'original'}>v originále</option>
                                    <option value="translation" {$filters.search.in|selected:'translation'}>v překladu</option>
                                 </select>
                              </div>
                           </div>
                           <div class="row">
                              <div class="col-md-12">
                                 <select class="selecter" data-placeholder="Ve všech polích" name="search[field]">
                                    <option value="-1">Ve všech polích</option>
                                    {foreach $translateColumns as $field => $column}
                                       <option value="{$field}" {$column.sourceName|selected:$filters.search.field}>{$column.alias}</option>
                                    {/foreach}
                                 </select>
                              </div>
                           </div>
                        </div>

                        {block objectCategory}{/block}
                     </div>

                     {block objectsFilterTranslated}
                        <div class="col-md-6">
                           <div class="row">
                              <label class="col-md-4 control-label">{'translationStatus'|translate:'translations'}</label>
                              <div class="col-md-7 condensedRadioContainer">
                                 <div class="radio pull-left">
                                    <input type="radio" name="translated" value=""
                                           id="translated_0" {$filters.translated.selected|checked:''} class="check"/>
                                    <label for="translated_0"
                                           title="{'indifferent'|translate:'translations'}">{'indifferentShort'|translate:'translations'}</label>
                                 </div>
                                 <div class="radio pull-left">
                                    <input type="radio" name="translated" value="1"
                                           id="translated_1" {$filters.translated.selected|checked:1} class="check"/>
                                    <label for="translated_1">{'filter.untranslated'|translate:'translations'}</label>
                                 </div>
                                 <div class="radio pull-left">
                                    <input type="radio" name="translated" value="2"
                                           id="translated_2" {$filters.translated.selected|checked:2} class="check"/>
                                    <label for="translated_2">{'filter.translated'|translate:'translations'}</label>
                                 </div>
                              </div>
                           </div>

                           <div class="row bottom-space">
                              <div class="col-md-4 control-label">
                                 <a class="help-tip" data-toggle="tooltip" title="{'filter.translated.tooltip'|translate:'translations'}">
                                    <i class="bi bi-question-circle"></i>
                                 </a>
                              </div>

                              <div class="col-md-7">
                                 <select class="selecter" id="filterTranslatedRange" data-placeholder="{'filter.translated.searchInFields'|translate:'translations'}"
                                         data-list-type="{$listType}" multiple name="translatedRange[]">
                                     {foreach $translateColumns as $field => $column}
                                        <option value="{$field}" {$column.sourceName|selected:$filters.search.field}
                                           {if in_array($field, $filters.translated.range)} selected{/if}
                                        >{$column.alias}</option>
                                     {/foreach}
                                 </select>
                              </div>

                           </div>
                        </div>
                     {/block}

                     {block objectsFilterSubmitBtn}
                        <div class="col-md-2">
                           <button type="submit" name="action" class="btn btn-primary filter-action" value="filter">{'filterBtn'|translate:'translations'}</button>
                        </div>
                     {/block}
                  </div>
               {/block}
            </div>
         </div>
      {/if}
      </form>
   {/if}
   <div class="translationsContainer" data-container="translations">
      {if !$iframe}
         <div class="row textRow">
            <div class="col-sm-6">
               <h5>{$sourceLanguages[$sourceLanguage]}</h5>
            </div>
            <div class="col-sm-6">
               <h5 style="padding-left: 35px;">{$languages[$language]}</h5>
            </div>
         </div>
      {/if}

      {*   <form method="POST" action="" class="viewParams" role="form">
            <input type="submit" style="display: none" name="submitSave" value="save"/>*}

      {foreach $SQL as $object}
         <div class="{block "object-class"}panel{/block}">
            {block objectRow}
               <div class="objectRow" data-type="objectRow">
                  <div class="objectTitle">
                     <div class="pull-right">
                        {block translationObjectTitleRight}
                        <span data-type="objectLastModified"
                           title="{'lastModified'|translate:'translations'}">{if $object[$language|cat:"_updated"]}{$object[$language|cat:"_updated"]|date_format:'Y-m-d'}{if $object[$language|cat:"_admin_email"]}, {/if}{/if}</span>
                        <span data-type="objectAdminEmail">{if $object[$language|cat:"_admin_email"]}{$object[$language|cat:"_admin_email"]}{/if}</span>
                        &nbsp;<span class="btn btn-sm btn-primary pull-right"
                           data-progress-title="{'saving'|translate:'translations'}" data-acn-ajax="save"
                           data-save-url="launch.php?s=list.php&type={$listType}&uniqueKey={$uniqueKey}&acn=ajaxSave&sourceLanguage={$sourceLanguage}&language={$language}"
                           disabled
                        >Uložit</span>
                           {block translationObjectDeleteButton}
                           <span class="btn btn-sm btn-danger pull-right" title="{'deleteObjectTranslation'|translate:'translations'}"
                                 data-object-id="{$object.id}" data-acn-ajax="delete"
                                 data-delete-url="launch.php?s=list.php&type={$listType}&uniqueKey={$uniqueKey}&acn=ajaxDelete&id_object={$object.id}&sourceLanguage={$sourceLanguage}&language={$language}"
                           ><span class="glyphicon glyphicon-remove"></span></span>
                           {/block}
                        {/block}
                     </div>
                     <span>
                        {block translationObjectTitle}{$object.id}{/block}
                        {if $googleTranslate == 'Y'}
                           <button data-google-translate="object" style="margin-left:15px" class="btn btn-sm" title="{if $dbcfg.use_deepl=='Y'}{'autoTranslateObjectTitleDeepL'|translate:'translations'}{else}{'autoTranslateObjectTitle'|translate:'translations'}{/if}">
                              {'autoTranslateObject'|translate:'translations'}
                           </button>
                        {/if}
                     </span>
                  </div>
                  {foreach $translateColumns as $columnDefaultName => $column}
                     {if $columnDefaultName == 'data' || ($column.superuser && !isSuperuser())}{continue}{/if}
                     {if $listType == 'translateBlocks' && $columnDefaultName == 'content'}{continue}{/if}
                     {block translateColumnIf}
                         {$skip = false}
                     {/block}
                     {if $skip == false}
                     {block translateColumn}
                     <div class="row columnRow" data-type="columnRow">
                        {block translateColumnDefaulInput}
                           <div class="col-sm-5">
                              <label class="columnTitle">{$column.alias}</label>

                              {$inputValue = $object[$column.sourceName]}
                              {if $column.custom_data}
                                 {$inputValue = $inputValue[$columnDefaultName]}
                              {/if}

                              {* Nech tohle na jednom radku, aby se spravne kopiroval text *}
                              {if $column.richtext}
                                 <textarea class="sourceText" data-init="ckeditor" name="{$uniqueKey}-{$columnDefaultName}-{$object.id}"
                                           data-text-type="source" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                           disabled>{$inputValue nofilter}</textarea>
                              {elseif $column.image}
                                 <div class="sourceText" data-text-type="source" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                      data-image-value="{$object[$column.sourceName]}">
                                    <img src="{$view->getObjectImage($object, $column.sourceName, $sourceLanguage)}" class="img-rounded img-responsive">
                                 </div>
                              {else}
                                 <div class="sourceText form-control input-sm {if $column.multiline}textarea{/if}"
                                      data-text-type="source" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                 >{if $column.select}{if array_key_exists($inputValue, $column.select)}{$column.select[$inputValue]}{/if}{else}{if $column.multiline}{$inputValue|nl2br nofilter}{else}{$inputValue nofilter}{/if}{/if}</div>
                              {/if}
                           </div>
                        {/block}

                        <div class="col-sm-2">
                           {if $column.select or $column.image or $googleTranslate != 'Y'}
                           <button type="button" data-acn="copyText" class="btn btn-sm copyTextBtn" title="{'transferText'|translate:'translations'}"><i
                                 class="glyphicon glyphicon-arrow-right"></i></button>
                           {else}
                           <span class="btn btn-sm btn-primary pull-right" title="Google Translate"
                                 data-progress-title="{'saving'|translate:'translations'}" data-acn-ajax="translate"
                                 data-save-url="launch.php?s=list.php&type={$listType}&uniqueKey={$uniqueKey}&acn=ajaxTranslate&sourceLanguage={$sourceLanguage}&language={$language}">
                                <i class="glyphicon glyphicon-arrow-right"></i>
                           </span>
                           {/if}
                        </div>
                        <div class="col-sm-5">
                           {$inputName = "translation-{$uniqueKey}[{$object.id}][{$language}][{$columnDefaultName}]"}
                           <label class="columnTitle d-flex justify-content-between">
                              {$column.alias}

                              {if (!$column.select && !$column.image) || $column.llmDisabled}
                              {insert_llm_button type='translation_translated_text' target=$inputName}
                              {/if}
                           </label>

                           {$inputValue = $object[$column.name]}
                           {if $column.custom_data}
                              {$inputName = "translation-{$uniqueKey}[{$object.id}][{$language}][custom_data][{$columnDefaultName}]"}
                              {$inputValue = $inputValue[$columnDefaultName]}
                           {/if}

                           {if $column.maxlength}<span class="help-block" style="float: right; margin-bottom: 0; display: none;">Maximálně {$column.maxlength} znaků.
                              <span class="charCounter" rel="{$inputName}"></span></span>{/if}
                           {if $column.richtext}
                              <textarea class="targetText" data-init="ckeditor"
                                 {if $column.maxlength}maxlength="{$column.maxlength}"{/if}
                                 data-text-type="target" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                 name="{$inputName}"
                                 disabled>{$inputValue}</textarea>
                           {elseif $column.multiline}
                              <textarea class="targetText form-control input-sm"
                                 {if $column.maxlength}maxlength="{$column.maxlength}"{/if}
                                 data-text-type="target" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                 name="{$inputName}"
                                 disabled>{$inputValue}</textarea>
                           {elseif $column.select}
                               <select name="{$inputName}"
                                       class=" selecter targetText form-control input-sm"
                                       data-text-type="target" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                       disabled>
                                 {foreach $column.select as $value => $title}
                                    <option {if $inputValue == $value}selected{/if} value="{$value}">{$title}</option>
                                 {/foreach}
                               </select>
                           {elseif $column.image}
                               <div class="translations-file-uploader" data-translations-file-upload data-source-column="{$column.sourceName}" data-unique-key="{$uniqueKey}"
                                    data-list-type="{$listType}" data-object-id="{$object.id}" data-source-language="{$sourceLanguage}"
                                    data-language="{$language}">
                                   {if empty($object[$column.name])}
                                       <div id="translations-uploader-{$uniqueKey}-{$object.id}"></div>
                                   {else}
                                       <ul class="qq-upload-list">
                                           <li data-file-uid="{$object.id}-{$column.sourceName}-{$language}">
                                               <img src="{$view->getObjectImage($object, $column.sourceName, $language)}" class="img-rounded img-responsive">
                                               <span class="qq-upload-delete" data-uploader-file-delete="{$object.id}-{$column.sourceName}-{$language}">Smazat</span></li>
                                       </ul>
                                   {/if}
                               </div>
                           {else}
                              <input class="targetText form-control input-sm"
                                 {if $column.maxlength}maxlength="{$column.maxlength}"{/if}
                                 data-text-type="target" data-object="{$object.id}" data-column="{$columnDefaultName}"
                                 name="{$inputName}"
                                 disabled value="{$inputValue}"/>
                           {/if}
                        </div>
                     </div>
                     {/block}
                      {/if}
                  {/foreach}
               </div>
            {/block}
         </div>
         {$objectsExists = true}
      {/foreach}

      {if !$objectsExists}<p class="emptyMessage">{'noObjectsFound'|translate:'translations'}.</p>{/if}

      {if !$iframe}
         <div style="width: 20px; height: 70px;">
         </div>
         <div class="window-btns">
            <div class="translationsContainer">
               <div class="row">
                  <div class="col-md-10 paginationContainer">
                     {paginationList pager=$pager}
                  </div>

                  <div class="col-md-2 text-right">
                     <span data-acn-ajax="save-all" class="btn btn-success">Uložit změny</span>
                  </div>

                  {*<div class="col-lg-3 col-md-2">
                     <input type="submit" name="submitSave" class="btn btn-success btn-block" value="Uložit vše">
                  </div>

                  <div class="col-lg-3 col-md-2">
                     <input type="submit" name="submitSaveAndNext" class="btn btn-success btn-block" value="Uložit vše a přejít na další stranu"{if $pager.count <= 1 || $pager.number == $pager.count} disabled="disabled"{/if}>
                  </div>*}
               </div>
            </div>
         </div>
      {/if}
      {*</form>*}
   </div>
{/block}

{block bottomPagination}
{/block}


