@extends('frontend.layout.dash')
@section('title', $title)
@section('content')

<a href="{{ route('user.marketplace.seller.products') }}" class="mkt-back"><i class="ti ti-arrow-left"></i> Back to Products</a>

<div class="card" style="max-width:600px;">
    <h2 class="title">{{ $title }}</h2>
    <form method="POST" action="{{ $product ? route('user.marketplace.seller.products.update', $product->id) : route('user.marketplace.seller.products.store') }}">
        @csrf
        @if($product) @method('PUT') @endif
        <div class="form-group" style="margin-bottom:16px;">
            <label class="form-label">Title <span class="required">*</span></label>
            <input type="text" name="title" class="form-control" value="{{ old('title', $product->title ?? '') }}" required>
        </div>
        <div class="form-grid">
            <div class="form-group">
                <label class="form-label">Price <span class="required">*</span></label>
                <input type="number" step="0.01" min="0.01" name="price" class="form-control" value="{{ old('price', $product->price ?? '') }}" required>
            </div>
            <div class="form-group">
                <label class="form-label">Category</label>
                <select name="category" class="form-control">
                    <option value="">— Select category —</option>
                    @foreach($categories as $cat)
                    <option value="{{ $cat->name }}" {{ old('category', $product->category ?? '') === $cat->name ? 'selected' : '' }}>{{ $cat->name }}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="form-group" style="margin-bottom:16px;">
            <label class="form-label">Description</label>
            <textarea name="description" class="form-control" rows="4" style="height:auto;padding:12px 16px;">{{ old('description', $product->description ?? '') }}</textarea>
        </div>
        @if($product)
        <div class="form-group" style="margin-bottom:16px;">
            <label class="form-label">Status</label>
            <select name="status" class="form-control">
                <option value="1" {{ ($product->status ?? true) ? 'selected' : '' }}>Active</option>
                <option value="0" {{ !($product->status ?? true) ? 'selected' : '' }}>Inactive</option>
            </select>
        </div>
        @endif
        <button type="submit" class="btn btn-primary"><i class="ti ti-device-floppy"></i> {{ $product ? 'Update' : 'Create' }} Product</button>
    </form>
</div>

@endsection
@push('style')
<style>
.mkt-back{display:inline-flex;align-items:center;gap:6px;font-size:14px;color:var(--primary-color);font-weight:500;margin-bottom:20px;text-decoration:none;}
</style>
@endpush
