{{define "content"}}
<div class="panel">
  <div class="panel-head">
    <h2><svg class="ico"><use href="/static/icons.svg#i-car"/></svg>Ürünler ({{len .Products}}{{if ne (len .Products) .Total}} / {{.Total}}{{end}})</h2>
    <a class="btn btn-sm btn-gold" href="/admin/urun/yeni"><svg class="ico ico-sm"><use href="/static/icons.svg#i-plus"/></svg>Yeni Ürün</a>
  </div>

  <form class="admin-filter" action="/admin/urunler" method="get">
    <input type="search" name="q" placeholder="Ürün adı ara..." value="{{.Query}}">
    <select name="kategori" onchange="this.form.submit()">
      <option value="">Tüm Kategoriler</option>
      {{$ac := .ActiveCat}}
      {{range .Categories}}<option value="{{.Slug}}" {{if eq .Slug $ac}}selected{{end}}>{{.Name}}</option>{{end}}
    </select>
    <select name="filtre" onchange="this.form.submit()">
      {{$f := .Filtre}}
      <option value="">Tüm Durumlar</option>
      <option value="stokta" {{if eq $f "stokta"}}selected{{end}}>Stokta olanlar</option>
      <option value="tukenen" {{if eq $f "tukenen"}}selected{{end}}>Tükenenler</option>
      <option value="gorselsiz" {{if eq $f "gorselsiz"}}selected{{end}}>Görseli eksik ({{.NumNoImage}})</option>
      <option value="onecikan" {{if eq $f "onecikan"}}selected{{end}}>Öne çıkanlar</option>
    </select>
    <button class="btn btn-sm btn-dark" type="submit">Ara</button>
    {{if or .Query .ActiveCat .Filtre}}<a class="btn btn-sm btn-ghost-dark" href="/admin/urunler">Temizle</a>{{end}}
  </form>

  {{if .Products}}
  <table class="table">
    <thead><tr><th></th><th>Ürün</th><th>Marka</th><th>Fiyat</th><th>Stok</th><th>Öne Çıkan</th><th></th></tr></thead>
    <tbody>
      {{range .Products}}
      <tr>
        <td class="td-img">
          <img src="{{.Image}}" alt="">
        </td>
        <td>
          <strong>{{.Name}}</strong>
          <div class="row-tags">
            <span class="muted">{{cat .Category}}</span>
            {{if .Voltage}}<span class="badge tag-mini">{{.Voltage}}</span>{{end}}
            {{if not .Image}}<span class="badge st-iptal">Görsel yok</span>{{else if eq .Image "/static/img/placeholder.svg"}}<span class="badge st-yeni">Görsel eksik</span>{{end}}
          </div>
        </td>
        <td>{{if .Brand}}{{.Brand}}{{else}}—{{end}}</td>
        <td><strong>{{money .Price}} ₺</strong>{{if .OldPrice}}<br><s class="muted">{{money .OldPrice}} ₺</s> <span class="badge st-featured">-%{{discount .OldPrice .Price}}</span>{{end}}</td>
        <td>
          <form method="post" action="/admin/urun/{{.ID}}/stok">
            <button class="toggle {{if .InStock}}toggle-on{{end}}" type="submit" title="Stok durumunu değiştir">{{if .InStock}}Stokta{{else}}Tükendi{{end}}</button>
          </form>
        </td>
        <td>
          <form method="post" action="/admin/urun/{{.ID}}/onecikan">
            <button class="toggle {{if .Featured}}toggle-on{{end}}" type="submit" title="Öne çıkan durumunu değiştir">{{if .Featured}}Evet{{else}}Hayır{{end}}</button>
          </form>
        </td>
        <td class="td-actions">
          <a class="btn btn-sm btn-dark" href="/admin/urun/{{.ID}}">Düzenle</a>
          <form method="post" action="/admin/urun/{{.ID}}/sil" onsubmit="return confirm('{{.Name}} silinsin mi?')">
            <button class="btn btn-sm btn-danger" type="submit">Sil</button>
          </form>
        </td>
      </tr>
      {{end}}
    </tbody>
  </table>
  {{else}}
  <p class="muted">Bu filtreye uyan ürün yok. <a href="/admin/urunler">Filtreleri temizleyin</a> veya <a href="/admin/urun/yeni">yeni ürün ekleyin</a>.</p>
  {{end}}
</div>
{{end}}
