@extends('layouts.app', ['title' => 'Edit Maintenance', 'heading' => 'Edit Histori Maintenance'])

@section('content')
<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header border-bottom">
                <h5 class="mb-0">Edit Data #{{ $log->id }} - {{ $log->maintainable?->name ?? 'Objek' }}</h5>
            </div>
            <div class="card-body mt-3">
                <form action="{{ route('maintenance.update', $log->id) }}" method="POST">
                    @csrf
                    @method('PUT')
                    
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label" for="submitter_name">Nama Petugas</label>
                            <input type="text" class="form-control @error('submitter_name') is-invalid @enderror" id="submitter_name" name="submitter_name" value="{{ old('submitter_name', $log->submitter_name) }}" required>
                            @error('submitter_name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                        
                        <div class="col-md-6">
                            <label class="form-label" for="performed_at">Tanggal Maintenance</label>
                            <input type="datetime-local" class="form-control @error('performed_at') is-invalid @enderror" id="performed_at" name="performed_at" value="{{ old('performed_at', $log->performed_at && $log->performed_at->format('H:i') !== '00:00' ? $log->performed_at->format('Y-m-d\TH:i') : now()->format('Y-m-d\TH:i')) }}" required>
                            @error('performed_at')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6">
                            <label class="form-label" for="condition">Kondisi</label>
                            <select class="form-select @error('condition') is-invalid @enderror" id="condition" name="condition" required>
                                <option value="good" {{ old('condition', $log->condition) == 'good' ? 'selected' : '' }}>Baik</option>
                                <option value="minor" {{ old('condition', $log->condition) == 'minor' ? 'selected' : '' }}>Rusak Ringan</option>
                                <option value="major" {{ old('condition', $log->condition) == 'major' ? 'selected' : '' }}>Rusak Berat</option>
                                <option value="lost" {{ old('condition', $log->condition) == 'lost' ? 'selected' : '' }}>Hilang</option>
                            </select>
                            @error('condition')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6">
                            <label class="form-label" for="location_note">Catatan Lokasi</label>
                            <input type="text" class="form-control @error('location_note') is-invalid @enderror" id="location_note" name="location_note" value="{{ old('location_note', $log->location_note) }}">
                            @error('location_note')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-12">
                            <label class="form-label" for="notes">Catatan Maintenance</label>
                            <textarea class="form-control @error('notes') is-invalid @enderror" id="notes" name="notes" rows="4">{{ old('notes', $log->notes) }}</textarea>
                            @error('notes')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-12 mt-4">
                            <button type="submit" class="btn btn-primary waves-effect waves-light">Simpan Perubahan</button>
                            <a href="{{ route('maintenance.index') }}" class="btn btn-label-secondary waves-effect">Batal</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
