@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title">Edit Product Attribute</h4>
                </div>
                <div class="card-body">
                    <form action="{{ route('admin.product-attributes.update', $productAttribute->id) }}" method="POST">
                        @csrf
                        @method('PUT')
                        <div class="mb-3">
                            <label for="product_id" class="form-label">Product</label>
                            <select class="form-control @error('product_id') is-invalid @enderror" id="product_id" name="product_id" required>
                                <option value="">Select Product</option>
                                @foreach($products as $product)
                                    <option value="{{ $product->id }}" {{ old('product_id', $productAttribute->product_id) == $product->id ? 'selected' : '' }}>{{ $product->name }}</option>
                                @endforeach
                            </select>
                            @error('product_id')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label for="unit" class="form-label">Unit</label>
                            <select class="form-control @error('unit') is-invalid @enderror" id="unit" name="unit" required>
                                <option value="">Select Unit</option>
                                <option value="kg" {{ old('unit', $productAttribute->unit) == 'kg' ? 'selected' : '' }}>Kg</option>
                                <option value="g" {{ old('unit', $productAttribute->unit) == 'g' ? 'selected' : '' }}>G</option>
                                <option value="l" {{ old('unit', $productAttribute->unit) == 'l' ? 'selected' : '' }}>L</option>
                                <option value="ml" {{ old('unit', $productAttribute->unit) == 'ml' ? 'selected' : '' }}>Ml</option>
                                <option value="piece" {{ old('unit', $productAttribute->unit) == 'piece' ? 'selected' : '' }}>Piece</option>
                            </select>
                            @error('unit')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="row">
                            <div class="col-md-4 mb-3">
                                <label for="unit_value" class="form-label">Unit Value</label>
                                <input type="number" step="0.01" class="form-control @error('unit_value') is-invalid @enderror" id="unit_value" name="unit_value" value="{{ old('unit_value', $productAttribute->unit_value) }}" required>
                                @error('unit_value')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-4 mb-3">
                                <label for="unit_price" class="form-label">Unit Price</label>
                                <input type="number" step="0.01" class="form-control @error('unit_price') is-invalid @enderror" id="unit_price" name="unit_price" value="{{ old('unit_price', $productAttribute->unit_price) }}" required>
                                @error('unit_price')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-2 mb-3">
                                <label for="min_quantity" class="form-label">Min Quantity</label>
                                <input type="number" class="form-control @error('min_quantity') is-invalid @enderror" id="min_quantity" name="min_quantity" value="{{ old('min_quantity', $productAttribute->min_quantity) }}" required>
                                @error('min_quantity')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-2 mb-3">
                                <label for="max_quantity" class="form-label">Max Quantity</label>
                                <input type="number" class="form-control @error('max_quantity') is-invalid @enderror" id="max_quantity" name="max_quantity" value="{{ old('max_quantity', $productAttribute->max_quantity) }}">
                                @error('max_quantity')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <button type="submit" class="btn btn-primary">Update Attribute</button>
                        <a href="{{ route('admin.product-attributes.index') }}" class="btn btn-secondary">Cancel</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
