@extends('layouts.app')
@section('title', 'Create Bill of Materials')

@section('content')
<div class="card">
    <div class="card-body">
        <h6 class="card-title mb-3">Create Bill of Materials</h6>

        @if($errors->any())
            <div class="alert alert-danger">
                <ul class="mb-0">
                    @foreach($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <form action="{{ route('boms.store') }}" method="POST">
            @csrf

            <div class="row g-3">
                <div class="col-md-6">
                    <label for="item_id" class="form-label">Product *</label>
                    @include('common.item-select', [
                        'name' => 'item_id',
                        'id' => 'item_id',
                        'label' => 'Product',
                        'class' => 'form-select @error("item_id") is-invalid @enderror',
                        'selectedItem' => old('item_id'),
                        'required' => true
                    ])
                    @error('item_id')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="col-md-6">
                    <label for="version" class="form-label">Version *</label>
                    <input type="number" id="version" name="version" class="form-control @error('version') is-invalid @enderror"
                           value="{{ old('version', 1) }}" min="1" required>
                    @error('version')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="col-12">
                    <label for="description" class="form-label">Description</label>
                    <textarea id="description" name="description" class="form-control @error('description') is-invalid @enderror"
                              rows="3" placeholder="Enter BOM description...">{{ old('description') }}</textarea>
                    @error('description')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="col-12">
                    <div class="form-check">
                        <input type="hidden" name="is_active" value="0">
                        <input type="checkbox" id="is_active" name="is_active" class="form-check-input @error('is_active') is-invalid @enderror"
                               value="1" {{ old('is_active', 1) ? 'checked' : '' }}>
                        <label for="is_active" class="form-check-label">Active</label>
                        @error('is_active')
                            <div class="invalid-feedback d-block">{{ $message }}</div>
                        @enderror
                    </div>
                </div>
            </div>

            <div class="d-flex gap-2 mt-3">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-save"></i> Create BOM
                </button>
                <a href="{{ route('boms.index') }}" class="btn btn-secondary">
                    <i class="fas fa-arrow-left"></i> Cancel
                </a>
            </div>
        </form>
    </div>
</div>
@endsection
