@extends('admin.master')

@section('title')
    Edit Achievement
@endsection

@section('content')
    <div class="card card-custom " id="kt_card_4">
        <div class="card-header">
            <h3 class="card-title">
                Edit Achievement
            </h3>
        </div>
        <form class="form" action="{{ route('achievements.update', $achievement->id) }}" method="POST" enctype="multipart/form-data">
            @csrf
            @method('PUT')
            <div class="card-body">
                <div class="form-group row">
                    <div class="col-lg-6">
                        <label>Achievement Title: <span class="text-danger">*</span></label>
                        <input type="text" name="title" class="form-control mb-2" placeholder="Enter achievement title here" value="{{ old('title', $achievement->title) }}" required />
                        @error('title')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>

                    <div class="col-lg-6">
                        <label>Achievement Category: <span class="text-danger">*</span></label>
                        <select name="category_id" class="form-control mb-2">
                            <option value="">Select Category</option>
                            @foreach ($achievementCategories as $achievementCategory)
                                <option value="{{ $achievementCategory->id }}" {{ old('category_id', $achievement->category_id) == $achievementCategory->id ? 'selected' : '' }}>
                                    {{ $achievementCategory->title }}
                                </option>
                            @endforeach
                        </select>
                        @error('category_id')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>
                </div>

                <div class="form-group row">
                    <div class="col-lg-12">
                        <label>Achievement Description: <span class="text-danger">*</span></label>
                        <textarea name="description" class="form-control" placeholder="Enter achievement description">{{ old('description', $achievement->description) }}</textarea>
                        @error('description')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>
                </div>


            </div>
            <div class="card-footer">
                <div class="row">
                    <div class="col-lg-12 text-center">
                        <button type="submit" class="btn btn-success mr-2">Update Achievement</button>
                        <a href="{{ route('achievements.index') }}" class="btn btn-secondary">Cancel</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection
