{*
* 2007-2024 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    PrestaShop SA <contact@prestashop.com>
*  @copyright 2007-2024 PrestaShop SA
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}
{if isset($product->id)}
  <div id="product-features" class="panel product-tab">
    <input type="hidden" name="submitted_tabs[]" value="Features" />
    <h3>{l s='Assign features to this product:' d='Modules.Agilemultisellerpro.Product'}</h3>

    <div class="alert alert-info">
      {l s='You can specify a value for each relevant feature regarding this product. Empty fields will not be displayed.' d='Modules.Agilemultisellerpro.Product'}<br />
      {l s='You can either create a specific value, or select among the existing pre-defined values you\'ve previously added.' d='Modules.Agilemultisellerpro.Product'}
    </div>

    <div>
      <table class="table">
        <thead>
          <tr>
            <th>
              <span class="title_box">{l s='Feature' d='Modules.Agilemultisellerpro.Product'}</span>
            </th>
            <th>
              <span class="title_box">{l s='Pre-defined value' d='Modules.Agilemultisellerpro.Product'}</span>
            </th>
            <th>
              <span class="title_box">
                {l s='Customized value' d='Modules.Agilemultisellerpro.Product'}
              </span>
            </th>
          </tr>
        </thead>

        <tbody>
          {foreach from=$field.availableValues.features item=available_feature name=myLoop}
            {assign var="middle" value=($field.availableValues.features|count)/2}
            <tr>
              <td>{$available_feature.name|escape:'htmlall':'UTF-8'}</td>
              <td>
                {if sizeof($available_feature.featureValues)}
                  <select id="feature_{$available_feature.id_feature|intval}_value"
                    name="feature_{$available_feature.id_feature|intval}_value"
                    class="form-control"
                    onchange="$('.custom_{$available_feature.id_feature|intval}_').val('');">
                    <option value="0">---</option>
                    {foreach from=$available_feature.featureValues item=value}
                      <option value="{$value.id_feature_value|intval}"
                        {if $available_feature.current_item == $value.id_feature_value}selected="selected" {/if}>
                        {$value.value|truncate:40|escape:'htmlall':'UTF-8'}
                      </option>
                    {/foreach}
                  </select>
                {else}
                  <input type="hidden" name="feature_{$available_feature.id_feature|intval}_value" value="0" />
                  <span>
                    {l s='N/A'  d='Modules.Agilemultisellerpro.Product'}
                  </span>
                {/if}
              </td>
              <td>
                {if $languages|count > 1}
                  {foreach from=$languages item=language}
                    <div class="row translatable-field lang-{$language.id_lang|intval}">
                      <div class="col-xl-9">
                        <textarea
                          name="custom_{$available_feature.id_feature|intval}_{$language.id_lang|intval}"
                          cols="40"
                          rows="1"
                          class="form-control"
                          onkeyup="if (isArrowKey(event)) return ;$('#feature_{$available_feature.id_feature|intval}_value').val(0);">{if isset($available_feature.val[$language.id_lang])}{$available_feature.val[$language.id_lang].value|escape:'html':'UTF-8'|default:""}{/if}</textarea>
                      </div>
                      <div class="col-xl-3">
                        <button type="button" class="btn btn-primary dropdown-toggle pl-1 pr-1" data-toggle="dropdown"
                          tabindex="-1">
                          {$language.iso_code|escape:'htmlall':'UTF-8'}
                        </button>
                        <ul class="dropdown-menu" role="menu">
                          {foreach from=$languages item=language}
                            <li>
                              <a
                                href="javascript:hideOtherLanguage({$language.id_lang|intval});">{$language.name|escape:'htmlall':'UTF-8'}</a>
                            </li>
                          {/foreach}
                        </ul>
                      </div>
                    </div>
                  {/foreach}
                {/if}
              </td>
            </tr>
          {foreachelse}
            <tr>
              <td colspan="3" style="text-align:center;">
                <i
                  class="icon-warning-sign"></i>&nbsp;{l s='No features have been defined' d='Modules.Agilemultisellerpro.Product'}
              </td>
            </tr>
          {/foreach}
        </tbody>
      </table>
    </div>
    <!-- table-responsive -->
  </div> <!-- product-features -->
{/if}
