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

<div class="page-head">
  <div>
    <p class="muted"><a href="/admin/shop/customers">{lang key="shop.customer.back_to_list"}</a></p>
    <h1>
      <span class="cust-avatar cust-avatar-lg">{customer.initials}</span>
      {customer.name}
      [if {customer.is_vip}]<span class="cust-vip-tag">VIP</span>[/if]
    </h1>
    <p class="muted">{lang key="shop.customer.since" date="{customer.created_fmt}"}</p>
  </div>
  <div class="actions">
    <a class="btn btn-primary" href="/admin/shop/orders/create?customer_email={customer.email}">{icon name="plus" size="14"} Создать заказ</a>
  </div>
</div>

<div class="cust-stats">
  <div class="cust-stat">
    <span class="cust-stat-label">{lang key="shop.customer.stats.orders"}</span>
    <span class="cust-stat-value">{customer.orders_count}</span>
  </div>
  <div class="cust-stat">
    <span class="cust-stat-label">{lang key="shop.customer.stats.spent"}</span>
    <span class="cust-stat-value">{customer.total_spent_fmt}</span>
  </div>
  <div class="cust-stat">
    <span class="cust-stat-label">{lang key="shop.analytics.kpi.aov"}</span>
    <span class="cust-stat-value">{customer.avg_order}</span>
  </div>
  <div class="cust-stat">
    <span class="cust-stat-label">{lang key="shop.customer.stats.last_order"}</span>
    <span class="cust-stat-value">{customer.last_order_fmt}</span>
  </div>
</div>

<div class="grid-2">
  <div class="card">
    <div class="card-h"><h3>{lang key="shop.customer.section_profile"}</h3></div>

    <form method="post" action="/admin/shop/customers/{customer.id}/update" class="form">
      {csrf}
      <div class="form-row">
        <div class="form-group">
          <label>{lang key="shop.customer.name"}</label>
          <input type="text" name="name" value="{customer.name}">
        </div>
        <div class="form-group">
          <label>Email</label>
          <input type="email" value="{customer.email}" disabled>
          <small class="help">{lang key="shop.customer.email_help"}</small>
        </div>
      </div>
      <div class="form-row">
        <div class="form-group">
          <label>{lang key="shop.customer.phone"}</label>
          <input type="text" name="phone" value="{customer.phone}">
        </div>
        <div class="form-group">
          <label>{lang key="shop.customer.city"}</label>
          <input type="text" name="city" value="{customer.city}">
        </div>
        <div class="form-group">
          <label>{lang key="shop.manufacturer.country"}</label>
          <input type="text" name="country" value="{customer.country}">
        </div>
        <div class="form-group">
          <label>{lang key="shop.customer.zip"}</label>
          <input type="text" name="zip" value="{customer.zip}">
        </div>
      </div>
      <div class="form-group">
        <label>{lang key="shop.customer.address"}</label>
        <textarea name="address" rows="2">{customer.address}</textarea>
      </div>
      <div class="form-group">
        <label>{lang key="shop.customer.note"}</label>
        <textarea name="note" rows="3" placeholder="{lang key="shop.customer.note_placeholder"}">{customer.note}</textarea>
      </div>
      <div class="form-row">
        <div class="form-group">
          <label class="checkbox">
            <input type="checkbox" name="is_vip" value="1" [if {customer.is_vip}]checked[/if]>
            {lang key="shop.customer.is_vip"}
          </label>
        </div>
        <div class="form-group">
          <label class="checkbox">
            <input type="checkbox" name="marketing_opt_in" value="1" [if {customer.marketing_opt_in}]checked[/if]>
            {lang key="shop.customer.marketing"}
          </label>
        </div>
      </div>
      <div class="form-actions">
        <button type="submit" class="btn btn-primary">{icon name="check" size="14"} {lang key="shop.common.save"}</button>
      </div>
    </form>

    <form method="post" action="/admin/shop/customers/{customer.id}/delete" class="cust-delete-form" data-confirm="Удалить клиента? Заказы останутся в системе, но потеряют связь." data-confirm-danger="1">
      {csrf}
      <button type="submit" class="btn btn-link btn-danger">{lang key="shop.customer.delete"}</button>
    </form>
  </div>

  <div class="card">
    <div class="card-h"><h3>{lang key="shop.customer.section_orders"}</h3>
      <span class="muted">{customer.orders_count}</span>
    </div>
    [if {orders}]
      <table class="table">
        <thead><tr><th>{lang key="shop.dashboard_widget.col_number"}</th><th>{lang key="shop.reviews_list.col.date"}</th><th>{lang key="shop.dashboard_widget.col_total"}</th><th>{lang key="shop.products_list.col.status"}</th></tr></thead>
        <tbody>
          [foreach var="orders" as="o"]
            <tr>
              <td><a href="/admin/shop/orders/{o.id}" class="row-link"><code>{o.number}</code></a></td>
              <td class="muted">{o.date_short}</td>
              <td><b>{o.total_fmt}</b></td>
              <td><span class="badge badge-{o.status}">{o.status}</span></td>
            </tr>
          [/foreach]
        </tbody>
      </table>
    [else]
      <p class="muted">{lang key="shop.dashboard_widget.no_orders_yet"}</p>
    [/if]
  </div>
</div>

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