{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-6">
  <div class="flex items-center justify-between">
    <div>
      <h2 class="text-xl font-semibold text-slate-900">{{ service.service_name }}</h2>
      <p class="text-sm text-slate-500">System default task templates for {{ service.service_code }}</p>
    </div>
    <div class="flex gap-2"><a href="/services/defaults" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Back</a><a href="/services/catalogue/{{ service.id }}" class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">Catalogue Detail</a></div>
  </div>
  <section class="rounded-2xl bg-white p-5 shadow-soft">
    <div class="space-y-3">
      {% for task in default_tasks %}
      {% if task.is_active or is_system_admin %}
      <div class="rounded-xl border border-slate-200 p-4">
  <div class="flex items-center justify-between gap-4">
    <div>
      <div class="text-sm font-semibold text-slate-900">{{ task.sequence_no }}. {{ task.task_name }}</div>
      <div class="mt-1 text-xs text-slate-500">
        Role: {{ task.default_role_name or '-' }} ·
        Mandatory: {{ 'Yes' if task.is_mandatory else 'No' }} ·
        Review: {{ 'Yes' if task.requires_review else 'No' }} · AQMM: {{ 'Yes' if task.is_aqmm_task else 'No' }}
      </div>
    </div>
    <div class="flex items-center gap-3">
      <span class="rounded-full px-2 py-1 text-xs font-medium {% if task.is_active %}bg-emerald-100 text-emerald-700{% else %}bg-slate-200 text-slate-700{% endif %}">
        {{ 'Active' if task.is_active else 'Inactive' }}
      </span>
      <a href="/services/catalogue/{{ service.id }}/defaults/{{ task.id }}/edit" class="text-xs font-medium text-brand-700 hover:underline">Edit</a>
    </div>
  </div>
  {% if task.description %}
  <p class="mt-2 text-sm text-slate-700">{{ task.description }}</p>
  {% endif %}
</div>
      {% endif %}
      {% else %}<div class="rounded-xl border border-dashed border-slate-300 p-6 text-sm text-slate-500">No default tasks configured yet.</div>{% endfor %}
    </div>
  </section>
  <section class="rounded-2xl bg-white p-5 shadow-soft">
    <h3 class="text-sm font-semibold text-slate-900">Add Default Task Template</h3>
    <form method="post" action="/services/catalogue/{{ service.id }}/defaults/new" class="mt-5 grid gap-4 rounded-2xl border border-slate-200 p-4 md:grid-cols-2">
      <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
      <div><label class="mb-2 block text-sm font-medium text-slate-700">Task Name</label><input type="text" name="task_name" required class="w-full rounded-xl border border-slate-300 px-4 py-2 text-sm"></div>
      <div><label class="mb-2 block text-sm font-medium text-slate-700">Default Role</label><input type="text" name="default_role_name" class="w-full rounded-xl border border-slate-300 px-4 py-2 text-sm"></div>
      <div><label class="mb-2 block text-sm font-medium text-slate-700">Sequence No</label><input type="number" min="1" name="sequence_no" class="w-full rounded-xl border border-slate-300 px-4 py-2 text-sm"></div>
      <div class="flex items-center gap-6 pt-7 text-sm text-slate-700"><label class="inline-flex items-center gap-2"><input type="checkbox" name="is_mandatory" checked> Mandatory</label><label class="inline-flex items-center gap-2"><input type="checkbox" name="requires_review"> Review</label><label class="inline-flex items-center gap-2"><input type="checkbox" name="is_active" checked> Active</label></div>
      <div class="md:col-span-2"><label class="mb-2 block text-sm font-medium text-slate-700">Description</label><textarea name="description" rows="4" class="w-full rounded-xl border border-slate-300 px-4 py-2 text-sm"></textarea></div>
      <div class="md:col-span-2 rounded-2xl border border-indigo-200 bg-indigo-50 p-4">
        <div class="text-sm font-semibold text-indigo-950">AQMM / Quality Control Tagging</div>
        <div class="mt-3 grid gap-2 md:grid-cols-4 text-xs text-slate-700">
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="is_aqmm_task"> Part of AQMM</label>
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="aqmm_mandatory"> Mandatory</label>
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="aqmm_evidence_required"> Evidence required</label>
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="aqmm_manager_review_required"> Manager review</label>
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="aqmm_partner_review_required"> Partner review</label>
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="aqmm_review_partner_required"> Review partner review</label>
          <label class="inline-flex items-center gap-1"><input type="checkbox" name="aqmm_blocks_final_release"> Blocks final release</label>
          <input name="aqmm_reference" placeholder="AQMM reference / clause" class="rounded-lg border border-indigo-200 px-2 py-1 text-xs">
        </div>
      </div>
      <div class="md:col-span-2 flex justify-end"><button class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">Add Default Task</button></div>
    </form>
  </section>
</div>
{% endblock %}
