{# Table rows fragment — no Alpine, column visibility via data-dz-col #}
{% if table and table.rows %}
{% for item in table.rows %}
<tr id="row-{{ item.id }}" class="hover cursor-pointer" data-dazzle-row="{{ table.entity_name }}" data-dz-row-id="{{ item.id }}"
    {% if table.detail_url_template %}
    hx-get="{{ table.detail_url_template.replace('{id}', item.id | string) }}"
    hx-push-url="true"
    hx-target="body"
    hx-swap="innerHTML"
    {% endif %}>
  {% if table.bulk_actions %}
  <td>
    <input type="checkbox" class="checkbox checkbox-sm" data-dz-row-select />
  </td>
  {% endif %}
  {% for col in table.columns %}
  <td data-dz-col="{{ col.key }}">
    {% if col.type == "badge" %}
      <span class="badge {{ item[col.key] | badge_class }}">{{ item[col.key] | default("") }}</span>
    {% elif col.type == "bool" %}
      {{ item[col.key] | bool_icon }}
    {% elif col.type == "date" %}
      {{ item[col.key] | dateformat }}
    {% elif col.type == "currency" %}
      {{ item[col.key] | currency(col.currency_code or "GBP") }}
    {% elif col.type == "percentage" %}
      {{ item[col.key] | default("") }}%
    {% else %}
      {{ item[col.key] | default("") | truncate_text }}
    {% endif %}
  </td>
  {% endfor %}
  <td>
    {# Row action dropdown — uses DaisyUI details-based dropdown, no JS #}
    <details class="dropdown dropdown-end" onclick="event.stopPropagation()">
      <summary class="btn btn-ghost btn-xs list-none">
        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v.01M12 12v.01M12 19v.01"/></svg>
      </summary>
      <ul class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-32 z-50">
        {% if table.detail_url_template %}
        <li><a href="{{ table.detail_url_template.replace('{id}', item.id | string) }}">View</a></li>
        {% endif %}
        <li><a href="{{ table.detail_url_template.replace('{id}', item.id | string) }}/edit" class="text-warning" data-dazzle-action="{{ table.entity_name }}.edit">Edit</a></li>
        <li>
          <button class="text-error"
                  data-dazzle-action="{{ table.entity_name }}.delete"
                  hx-delete="{{ table.api_endpoint }}/{{ item.id }}"
                  hx-confirm="Delete this {{ table.entity_name | lower }}?"
                  hx-target="closest tr"
                  hx-swap="outerHTML swap:300ms">
            Delete
          </button>
        </li>
      </ul>
    </details>
  </td>
</tr>
{% endfor %}
{% else %}
<tr>
  <td colspan="{{ (table.columns | length) + 1 if table else 1 }}" class="text-center py-8 text-base-content/50">
    {{ table.empty_message | default("No items found.") if table else "No items found." }}
  </td>
</tr>
{% endif %}
