{{define "content"}}
<div class="panel">
  <div class="panel-head">
    <h2><svg class="ico"><use href="/static/icons.svg#i-box"/></svg>Siparişler ({{len .Orders}}{{if ne (len .Orders) .Total}} / {{.Total}}{{end}})</h2>
  </div>

  <div class="tab-row">
    {{$d := .Durum}}{{$sc := .StatusCounts}}
    <a class="tab {{if eq $d ""}}tab-on{{end}}" href="/admin/siparisler">Tümü ({{.Total}})</a>
    <a class="tab {{if eq $d "yeni"}}tab-on{{end}}" href="/admin/siparisler?durum=yeni">Yeni ({{index $sc "yeni"}})</a>
    <a class="tab {{if eq $d "onaylandi"}}tab-on{{end}}" href="/admin/siparisler?durum=onaylandi">Onaylandı ({{index $sc "onaylandi"}})</a>
    <a class="tab {{if eq $d "kargoda"}}tab-on{{end}}" href="/admin/siparisler?durum=kargoda">Kargoda ({{index $sc "kargoda"}})</a>
    <a class="tab {{if eq $d "tamamlandi"}}tab-on{{end}}" href="/admin/siparisler?durum=tamamlandi">Tamamlandı ({{index $sc "tamamlandi"}})</a>
    <a class="tab {{if eq $d "iptal"}}tab-on{{end}}" href="/admin/siparisler?durum=iptal">İptal ({{index $sc "iptal"}})</a>
  </div>

  <form class="admin-filter" action="/admin/siparisler" method="get">
    {{if .Durum}}<input type="hidden" name="durum" value="{{.Durum}}">{{end}}
    <input type="search" name="q" placeholder="Ad, telefon, sipariş kodu veya ürün ara..." value="{{.Query}}">
    <button class="btn btn-sm btn-dark" type="submit">Ara</button>
    {{if .Query}}<a class="btn btn-sm btn-ghost-dark" href="/admin/siparisler{{if .Durum}}?durum={{.Durum}}{{end}}">Temizle</a>{{end}}
  </form>

  {{if .Orders}}
  <table class="table">
    <thead><tr><th>Kod</th><th>Müşteri</th><th>İletişim</th><th>Ürün</th><th>Adres</th><th>Durum</th><th>Tarih</th><th></th></tr></thead>
    <tbody>
      {{range .Orders}}
      <tr>
        <td><strong>{{.Code}}</strong></td>
        <td>{{.Name}}</td>
        <td><a href="{{tel .Phone}}">{{.Phone}}</a></td>
        <td>{{if .ProductName}}{{.ProductName}}{{else}}—{{end}}{{if .Note}}<br><small class="muted">Not: {{.Note}}</small>{{end}}</td>
        <td>{{.City}}{{if .Address}}<br><small class="muted">{{.Address}}</small>{{end}}</td>
        <td>
          <form method="post" action="/admin/siparis/{{.ID}}/durum">
            <select name="status" class="status-select st-{{.Status}}" onchange="this.form.submit()">
              <option value="yeni" {{if eq .Status "yeni"}}selected{{end}}>Yeni</option>
              <option value="onaylandi" {{if eq .Status "onaylandi"}}selected{{end}}>Onaylandı</option>
              <option value="kargoda" {{if eq .Status "kargoda"}}selected{{end}}>Kargoda</option>
              <option value="tamamlandi" {{if eq .Status "tamamlandi"}}selected{{end}}>Tamamlandı</option>
              <option value="iptal" {{if eq .Status "iptal"}}selected{{end}}>İptal</option>
            </select>
          </form>
        </td>
        <td>{{dt .CreatedAt}}</td>
        <td class="td-actions">
          <form method="post" action="/admin/siparis/{{.ID}}/sil" onsubmit="return confirm('{{.Code}} silinsin mi?')">
            <button class="btn btn-sm btn-danger" type="submit">Sil</button>
          </form>
        </td>
      </tr>
      {{end}}
    </tbody>
  </table>
  {{else}}
  <p class="muted">{{if or .Durum .Query}}Bu filtreye uyan sipariş yok.{{else}}Henüz sipariş yok. Müşteriler Satın Al formunu doldurduğunda burada listelenecek.{{end}}</p>
  {{end}}
</div>
{{end}}
