<?php
$value = is_array($this->value ?? null) ? $this->value : [];
$languages = is_array($this->languages ?? null) ? $this->languages : [];
$rowKey = (string)($this->rowKey ?? '');
$defaultLanguageId = (string)($this->defaultLanguageId ?? '');
$valueId = (int)($value['id'] ?? 0);
$isDefault = !empty($value['is_default']);
$impact = (string)($value['impact_on_the_price'] ?? '');
?>
<tr class="attribute-value-row" data-row-key="<?= htmlspecialchars($rowKey, ENT_QUOTES, 'UTF-8'); ?>">
  <td class="text-center" style="width: 90px;">
    <input
      type="radio"
      class="js-default-row"
      name="default_row_key"
      value="<?= htmlspecialchars($rowKey, ENT_QUOTES, 'UTF-8'); ?>"
      <?= $isDefault ? 'checked="checked"' : ''; ?>
    />
  </td>
  <td style="width: 180px;">
    <input type="hidden" class="js-value-id" value="<?= $valueId; ?>" />
    <input
      type="text"
      class="form-control input-sm js-impact-on-price"
      value="<?= htmlspecialchars($impact, ENT_QUOTES, 'UTF-8'); ?>"
      placeholder="+10.00 / -5.50"
    />
  </td>
  <td>
    <?php foreach ($languages as $language): ?>
      <?php
      if ((int)($language['status'] ?? 0) !== 1) {
          continue;
      }

      $langId = (string)($language['id'] ?? '');
      if ($langId === '') {
          continue;
      }

      $langName = (string)($language['name'] ?? $langId);
      $langValue = '';
      if (is_array($value['languages'] ?? null) && isset($value['languages'][$langId]['name'])) {
          $langValue = (string)$value['languages'][$langId]['name'];
      }
      ?>
      <div class="form-group mb10">
        <label class="control-label" style="display:block;">
          <?= htmlspecialchars($langName, ENT_QUOTES, 'UTF-8'); ?>
          <?= $langId === $defaultLanguageId ? '<span style="color:#e74c3c;">*</span>' : ''; ?>
        </label>
        <input
          type="text"
          class="form-control input-sm js-value-name"
          data-lang-id="<?= htmlspecialchars($langId, ENT_QUOTES, 'UTF-8'); ?>"
          value="<?= htmlspecialchars($langValue, ENT_QUOTES, 'UTF-8'); ?>"
          placeholder="Nazwa wartosci"
        />
      </div>
    <?php endforeach; ?>
  </td>
  <td class="text-center" style="width: 100px;">
    <button type="button" class="btn btn-xs btn-danger js-value-remove">
      <i class="fa fa-trash"></i> Usun
    </button>
  </td>
</tr>

