@extends('layouts.app')
@section('title', $product->exists ? __('Edit Product') : __('Add Product'))
@section('content')
<form method="POST" action="{{ $product->exists ? route('products.update',$product) : route('products.store') }}">@csrf @if($product->exists)@method('PUT')@endif<div class="card"><div class="card-body p-4"><div class="row g-3"><div class="col-md-6"><label class="form-label">{{ __('Product Name') }} *</label><input name="name" class="form-control" value="{{ old('name',$product->name) }}" required></div><div class="col-md-3"><label class="form-label">SKU</label><input name="sku" class="form-control" value="{{ old('sku',$product->sku) }}" placeholder="Auto"></div><div class="col-md-3"><label class="form-label">{{ __('Category') }}</label><select name="category_id" class="form-select"><option value="">—</option>@foreach($categories as $category)<option value="{{ $category->id }}" @selected(old('category_id',$product->category_id)==$category->id)>{{ $category->name }}</option>@endforeach</select></div><div class="col-md-4"><label class="form-label">{{ __('Unit') }}</label><select name="unit" class="form-select">@foreach($units as $unit)<option value="{{ $unit->short_name }}" @selected(old('unit',$product->unit ?: 'pc')===$unit->short_name)>{{ $unit->name }} ({{ $unit->short_name }})</option>@endforeach</select></div><div class="col-md-4"><label class="form-label">{{ __('Opening / Current Stock') }}</label><input name="stock_quantity" type="number" step="0.01" class="form-control" value="{{ old('stock_quantity',$product->stock_quantity ?? 0) }}" required></div><div class="col-md-4"><label class="form-label">{{ __('Low Stock Alert At') }}</label><input name="low_stock_at" type="number" step="0.01" class="form-control" value="{{ old('low_stock_at',$product->low_stock_at ?? 0) }}" required></div><div class="col-md-4"><label class="form-label">{{ __('Cost Price') }}</label><input name="cost_price" type="number" step="0.01" min="0" class="form-control" value="{{ old('cost_price',$product->cost_price ?? 0) }}" required></div><div class="col-md-4"><label class="form-label">{{ __('Retail Price') }}</label><input name="retail_price" type="number" step="0.01" min="0" class="form-control" value="{{ old('retail_price',$product->retail_price ?? 0) }}" required></div><div class="col-md-4"><label class="form-label">{{ __('Wholesale Price') }}</label><input name="wholesale_price" type="number" step="0.01" min="0" class="form-control" value="{{ old('wholesale_price',$product->wholesale_price ?? 0) }}" required></div><div class="col-12"><label class="form-label">{{ __('Description') }}</label><textarea name="description" class="form-control" rows="2">{{ old('description',$product->description) }}</textarea></div><div class="col-12"><div class="form-check"><input name="is_active" value="1" class="form-check-input" type="checkbox" id="active" @checked(old('is_active',$product->exists ? $product->is_active : true))><label class="form-check-label" for="active">{{ __('Available for sale') }}</label></div></div></div></div><div class="card-footer bg-white text-end"><a href="{{ route('products.index') }}" class="btn btn-light">{{ __('Cancel') }}</a><button class="btn btn-success">{{ __('Save Product') }}</button></div></div></form>
@endsection
