{{define "policy_row"}}
<tr id="policy-row-{{.ID}}">
  <td class="text-small text-muted">{{.ID}}</td>
  <td class="text-small">{{.Priority}}</td>
  <td>
    <strong>{{.Description}}</strong>
    {{if .IsExpired}}<span class="badge" style="background:#dc2626;color:#fff;margin-left:.4rem">expired</span>{{end}}
    {{if .IsPending}}<span class="badge" style="background:#d97706;color:#fff;margin-left:.4rem">scheduled</span>{{end}}
    {{if or .NotBefore .ExpiresAt}}
    <div class="text-small text-muted" style="margin-top:.2rem">
      {{if .NotBefore}}Not before: {{.NotBefore}}{{end}}
      {{if and .NotBefore .ExpiresAt}} · {{end}}
      {{if .ExpiresAt}}Expires: {{.ExpiresAt}}{{end}}
    </div>
    {{end}}
    <details style="margin-top:.25rem">
      <summary class="text-small text-muted" style="cursor:pointer">Show rule JSON</summary>
      <pre style="font-size:.75rem;background:#f8fafc;padding:.5rem;border-radius:4px;overflow:auto;margin-top:.25rem">{{.RuleJSON}}</pre>
    </details>
  </td>
  <td class="text-small">
    {{/* Extract effect from RuleJSON via prettyJSON — displayed separately */}}
    <span class="badge {{if .Enabled}}badge-active{{else}}badge-inactive{{end}}">
      {{if .Enabled}}enabled{{else}}disabled{{end}}
    </span>
  </td>
  <td>
    {{if .Enabled}}
    <button class="btn btn-sm btn-secondary"
            hx-patch="/policies/{{.ID}}/enabled"
            hx-vals='{"enabled":"0"}'
            hx-target="#policy-row-{{.ID}}"
            hx-swap="outerHTML">Disable</button>
    {{else}}
    <button class="btn btn-sm btn-secondary"
            hx-patch="/policies/{{.ID}}/enabled"
            hx-vals='{"enabled":"1"}'
            hx-target="#policy-row-{{.ID}}"
            hx-swap="outerHTML">Enable</button>
    {{end}}
  </td>
  <td class="text-small text-muted">{{.UpdatedAt}}</td>
  <td>
    <button class="btn btn-sm btn-danger"
            hx-delete="/policies/{{.ID}}"
            hx-target="#policy-row-{{.ID}}"
            hx-swap="outerHTML"
            hx-confirm="Delete policy rule {{.ID}}? This cannot be undone.">Delete</button>
  </td>
</tr>
{{end}}
