@php($isEdit = isset($machine))
<form action="{{ $isEdit ? route('machines.update', $machine) : route('machines.store') }}" method="POST">
    @csrf
    @if($isEdit)
        @method('PUT')
    @endif

    <div class="row g-3">
        <div class="col-md-6">
            <label for="code" class="form-label">Code <span class="text-danger">*</span></label>
            <input type="text" id="code" name="code" class="form-control @error('code') is-invalid @enderror"
                   value="{{ old('code', $isEdit ? $machine->code : '') }}" required maxlength="10" style="text-transform: uppercase;">
            @error('code')
                <div class="invalid-feedback">{{ $message }}</div>
            @enderror
            <small class="form-text text-muted">Unique machine code (max 10 characters).</small>
        </div>

        <div class="col-md-6">
            <label for="name" class="form-label">Name <span class="text-danger">*</span></label>
            <input type="text" id="name" name="name" class="form-control @error('name') is-invalid @enderror"
                   value="{{ old('name', $isEdit ? $machine->name : '') }}" required maxlength="255">
            @error('name')
                <div class="invalid-feedback">{{ $message }}</div>
            @enderror
            <small class="form-text text-muted">Machine name or description.</small>
        </div>

        {{-- <div class="col-md-6">
            <label for="capacity" class="form-label">Capacity</label>
            <input type="text" id="capacity" name="capacity" class="form-control @error('capacity') is-invalid @enderror"
                   value="{{ old('capacity', $isEdit ? $machine->capacity : '') }}" maxlength="255" placeholder="e.g., 1000 kg/hour">
            @error('capacity')
                <div class="invalid-feedback">{{ $message }}</div>
            @enderror
            <small class="form-text text-muted">Optional capacity or production rate.</small>
        </div> --}}

        <div class="col-md-6">
            <label for="status" class="form-label">Status <span class="text-danger">*</span></label>
            <select id="status" name="status" class="form-select @error('status') is-invalid @enderror" required>
                <option value="">— Select Status —</option>
                <option value="active" {{ old('status', $isEdit ? $machine->status : 'active') == 'active' ? 'selected' : '' }}>Active</option>
                <option value="maintenance" {{ old('status', $isEdit ? $machine->status : '') == 'maintenance' ? 'selected' : '' }}>Maintenance</option>
                <option value="inactive" {{ old('status', $isEdit ? $machine->status : '') == 'inactive' ? 'selected' : '' }}>Inactive</option>
            </select>
            @error('status')
                <div class="invalid-feedback">{{ $message }}</div>
            @enderror
        </div>

        <div class="col-12">
            <div class="d-flex gap-2">
                <button type="submit" class="btn btn-primary">
                    {{ $isEdit ? 'Update' : 'Create' }} Machine
                </button>
                <a href="{{ route('machines.index') }}" class="btn btn-secondary">Cancel</a>
            </div>
        </div>
    </div>
</form>
