{include file="_partials/head.tpl"}

<div class="page-head">
  <div>
    <h1>{lang key="shop.csv.title"}</h1>
    <p class="muted">{lang key="shop.csv.subtitle"}</p>
  </div>
  <div class="actions">
    <a class="btn btn-secondary" href="/admin/shop/products/export">{icon name="download" size="14"} {lang key="shop.csv.export_current"}</a>
  </div>
</div>

[if {stats}]
  <div class="card">
    <h3>{lang key="shop.csv.result_section"}</h3>
    <ul class="muted">
      <li>{lang key="shop.csv.created"}: <b>{stats.inserted}</b></li>
      <li>{lang key="shop.csv.stats.updated"}: <b>{stats.updated}</b></li>
      <li>{lang key="shop.csv.stats.skipped"}: <b>{stats.skipped}</b></li>
    </ul>
    [if {stats.errors}]
      <div class="alert alert-error">
        <b>{lang key="shop.csv.stats.errors"}:</b>
        <ul>[foreach var="stats.errors" as="e"]<li>{e}</li>[/foreach]</ul>
      </div>
    [/if]
  </div>
[/if]

<form method="post" action="/admin/shop/products/import" enctype="multipart/form-data" class="card">
  {csrf}

  <div class="form-group">
    <label>{lang key="shop.csv.file_label"} *</label>
    <input type="file" name="file" accept=".csv,text/csv" required>
    <small class="help">{lang key="shop.csv.file_help"}</small>
  </div>

  <div class="form-group">
    <label>{lang key="shop.csv.delimiter"}</label>
    <select name="delimiter">
      <option value=",">{lang key="shop.csv.delimiter_comma"}</option>
      <option value=";">{lang key="shop.csv.delimiter_semicolon"}</option>
      <option value="	">{lang key="shop.csv.delimiter_tab"}</option>
    </select>
  </div>

  <div class="form-actions">
    <button type="submit" class="btn btn-primary">{icon name="upload" size="14"} {lang key="shop.csv.run"}</button>
  </div>
</form>

<div class="card">
  <h3>{lang key="shop.csv.structure"}</h3>
  <p class="muted">Первая строка — заголовки. Доступные колонки:</p>
  <pre style="font-size:12px;line-height:1.6;background:var(--surface-2);padding:14px;border-radius:8px;overflow:auto">id,slug,title,sku,barcode,price,old_price,stock,status,is_featured,manufacturer,category,short,body,seo_title,seo_description,cover</pre>
  <ul class="muted">
    <li><code>id</code> — если указан и товар найден, обновится. Иначе ищется по <code>slug</code>.</li>
    <li><code>slug</code> — пусто = автогенерация из title.</li>
    <li><code>status</code> — <code>active</code>, <code>draft</code> или <code>archived</code>.</li>
    <li><code>is_featured</code> — <code>1</code>, <code>0</code>, <code>yes</code>, <code>no</code>, <code>true</code>, <code>false</code>.</li>
    <li><code>manufacturer</code>, <code>category</code> — slug соответствующей записи. Если не найдены — null.</li>
  </ul>
</div>

{include file="_partials/foot.tpl"}
