@extends('merchant_admin.layouts.app')

@section('title', '商家商品分类')
@section('page_title', '商家商品分类')

@section('content')
<div class="card mb-20">
    <p class="muted muted-tight">这里是当前商家的商品分类管理入口，分类数据天然受商家作用域限制。</p>
    <p class="muted">当前分类列表已接入缓存：{{ $cacheMeta['store'] }} / TTL {{ $cacheMeta['ttl'] }}。</p>
    <h3>新增分类</h3>
    <form method="post" action="/merchant-admin/product-categories">
        @csrf
        <div class="grid-3">
            <input name="name" placeholder="分类名称" value="{{ old('name') }}">
            <input name="slug" placeholder="slug" value="{{ old('slug') }}">
            <select name="status">
                <option value="active" @selected(old('status', 'active') === 'active')>active</option>
                <option value="inactive" @selected(old('status') === 'inactive')>inactive</option>
            </select>
            <input name="sort" placeholder="排序" value="{{ old('sort', 0) }}">
            <input name="description" placeholder="分类说明" class="span-2" value="{{ old('description') }}">
        </div>
        <div class="mt-12"><button type="submit">创建分类</button></div>
    </form>
</div>

<div class="card">
    <h3>分类列表</h3>
    <table>
        <thead><tr><th>ID</th><th>名称</th><th>Slug</th><th>状态</th><th>排序</th><th>说明</th><th>操作</th></tr></thead>
        <tbody>
        @foreach($categories as $category)
            <tr>
                <td>{{ $category->id }}</td>
                <td><form method="post" action="/merchant-admin/product-categories/{{ $category->id }}" class="actions">@csrf <input name="name" value="{{ $category->name }}"></td>
                <td><input name="slug" value="{{ $category->slug }}"></td>
                <td><select name="status"><option value="active" @selected($category->status==='active')>active</option><option value="inactive" @selected($category->status==='inactive')>inactive</option></select></td>
                <td><input name="sort" value="{{ $category->sort }}" class="w-90"></td>
                <td><input name="description" value="{{ $category->description }}"></td>
                <td><button type="submit">更新</button></form><form method="post" action="/merchant-admin/product-categories/{{ $category->id }}/delete" class="inline" onsubmit="return confirm('确定删除这个分类？');">@csrf <button type="submit">删除</button></form></td>
            </tr>
        @endforeach
        </tbody>
    </table>
</div>

<div class="pagination-wrap">{{ $categories->links() }}</div>
@endsection
