{# Single task row markup. Used both inside the tbody for-loop in
   _task_list.twig AND once more inside the hidden <template
   data-task-row-template> at the bottom of the same file — keeping a
   single source of truth so JS-built rows can never drift from
   server-rendered ones (R02-N02).

   Required overrides via {% include … with %}:
     - t      : Task object, or null when rendering the template shell
     - assign : map sw_id → days (numeric); pass {} for the template
     - links  : array of link descriptors; pass [] for the template
     - tot    : numeric total of `assign`; pass 0 for the template

   Inherited from the surrounding sprint show/present view:
     - sprintWorkers, ownerChoices, taskStatusEnabled, statusGrid,
       currentUser, STATUS_ZUGEWIESEN.
#}
{% set isTemplate = (t is null) %}
{% set tId        = isTemplate ? '' : t.id %}
{% set tTitle     = isTemplate ? '' : t.title %}
{% set tPrio      = isTemplate ? 1  : t.priority %}
{% set tOwnerId   = isTemplate ? null : t.ownerWorkerId %}
{% set tDesc      = isTemplate ? '' : t.description %}
{% set tUrl       = isTemplate ? '' : t.url %}
{% set tSort      = isTemplate ? '' : t.sortOrder %}
<tr data-task-row
    class="hover:bg-slate-50 dark:hover:bg-slate-700"
    data-task-id="{{ tId }}"
    data-prio="{{ tPrio }}"
    data-owner="{{ tOwnerId is not null ? tOwnerId : '' }}"
    data-sort-order="{{ tSort }}"
    data-description="{{ tDesc }}"
    data-url="{{ tUrl }}"
    data-task-title="{{ tTitle }}"
    data-links="{{ links|json_encode|e('html_attr') }}">
    <td class="px-2 py-1">
        <button type="button" data-task-menu-trigger
                class="task-menu-trigger inline-flex items-center justify-center w-6 h-6 rounded text-slate-500 hover:bg-slate-100 dark:text-slate-400 dark:hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-400"
                aria-haspopup="true" aria-expanded="false"
                aria-label="Task actions">
            <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true">
                <line x1="2" y1="4"  x2="14" y2="4"  stroke="currentColor" stroke-width="2"/>
                <line x1="2" y1="8"  x2="14" y2="8"  stroke="currentColor" stroke-width="2"/>
                <line x1="2" y1="12" x2="14" y2="12" stroke="currentColor" stroke-width="2"/>
            </svg>
        </button>
    </td>
    <td class="px-2 py-1 min-w-[14rem]">
        <div class="flex items-center gap-1.5">
            {% if currentUser.isAdmin %}
                <input type="text" data-title value="{{ tTitle }}"
                       class="flex-1 rounded border border-slate-200 px-2 py-1 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:bg-slate-800 dark:border-slate-600 dark:text-slate-100 dark:focus:ring-slate-500">
            {% else %}
                <span class="flex-1">{{ tTitle }}</span>
            {% endif %}

            <a data-task-url-link href="{{ tUrl }}"
               target="_blank" rel="noopener noreferrer"
               class="task-url-link inline-flex items-center justify-center w-5 h-5 rounded text-blue-600 hover:bg-slate-100 dark:text-blue-400 dark:hover:bg-slate-700{% if tUrl == '' %} hidden{% endif %}"
               title="Open task link"
               aria-label="Open task link">
                <svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true">
                    <path d="M9 2h5v5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
                    <path d="M14 2L7 9" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
                    <path d="M12 9v4a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
            </a>
        </div>
    </td>
    <td class="px-2 py-1" data-col="owner">
        {% if currentUser.isAdmin %}
            <select data-owner-select
                    class="w-full rounded border border-slate-200 px-2 py-1 bg-white focus:outline-none focus:ring-2 focus:ring-slate-400 dark:bg-slate-800 dark:border-slate-600 dark:text-slate-100 dark:focus:ring-slate-500">
                <option value="">—</option>
                {% for ow in ownerChoices %}
                    <option value="{{ ow.id }}" {{ tOwnerId == ow.id ? 'selected' : '' }}>
                        {{ ow.name }}
                    </option>
                {% endfor %}
            </select>
        {% else %}
            {% set ownerName = '—' %}
            {% for ow in ownerChoices %}
                {% if ow.id == tOwnerId %}{% set ownerName = ow.name %}{% endif %}
            {% endfor %}
            {{ ownerName }}
        {% endif %}
    </td>
    <td class="px-2 py-1 text-center" data-col="prio">
        {% if currentUser.isAdmin %}
            <select data-prio-select
                    class="rounded border border-slate-200 px-2 py-1 bg-white font-mono focus:outline-none focus:ring-2 focus:ring-slate-400 dark:bg-slate-800 dark:border-slate-600 dark:text-slate-100 dark:focus:ring-slate-500">
                <option value="1" {{ tPrio == 1 ? 'selected' : '' }}>1</option>
                <option value="2" {{ tPrio == 2 ? 'selected' : '' }}>2</option>
            </select>
        {% else %}
            <span class="font-mono">{{ tPrio }}</span>
        {% endif %}
    </td>
    <td class="px-2 py-1 text-center font-mono font-semibold"
        data-col="tot" data-task-tot>
        {{ fmt_days(tot) }}
    </td>
    {% for sw in sprintWorkers %}
        {% set d = assign[sw.id]|default(0.0) %}
        {% set st = isTemplate ? STATUS_ZUGEWIESEN : (statusGrid[t.id][sw.id]|default(STATUS_ZUGEWIESEN)) %}
        {% set tdExtraClass = taskStatusEnabled ? ' assign-status-' ~ st : '' %}
        <td class="px-1 py-1 text-center whitespace-nowrap{{ tdExtraClass }}"
            data-col="sw-{{ sw.id }}"
            {% if taskStatusEnabled %}data-assign-cell data-status="{{ st }}" data-sw-id="{{ sw.id }}"{% endif %}
            data-sort-value-sw-{{ sw.id }}="{{ d|number_format(2, '.', '') }}">
            {% if currentUser.isAdmin %}
                <input type="number" min="0" step="0.5"
                       value="{{ fmt_days(d) }}"
                       data-assign
                       data-sw-id="{{ sw.id }}"
                       class="w-14 rounded border border-slate-200 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400 dark:bg-slate-800 dark:border-slate-600 dark:text-slate-100 dark:focus:ring-slate-500">
            {% else %}
                <span class="font-mono inline-block min-w-[2rem]{% if taskStatusEnabled %} cursor-pointer{% endif %}"
                      data-assign-readonly
                      data-sw-id="{{ sw.id }}">{{ fmt_days(d) }}</span>
            {% endif %}
        </td>
    {% endfor %}
</tr>
