@extends('layouts.app')

@section('title', 'Edit Cycle')
@section('heading', 'Edit Performance Cycle')

@section('content')
@include('performance.top-submenu')

<x-card class="max-w-3xl">
    <form action="{{ route('performance-cycles.update', $cycle) }}" method="POST" class="space-y-6" novalidate data-performance-cycle-form="edit">
        @csrf
        @method('PUT')
        <div class="grid gap-4 sm:grid-cols-2">
            <div class="sm:col-span-2">
                <label class="block text-sm font-medium text-slate-700">Cycle name <span class="text-red-500">*</span></label>
                <input type="text" name="name" value="{{ old('name', $cycle->name) }}" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2">
                @error('name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                <p data-js-error="name" class="mt-1 text-sm text-red-600 hidden"></p>
            </div>
            <div>
                <label class="block text-sm font-medium text-slate-700">Start date</label>
                <input type="date" name="start_date" value="{{ old('start_date', $cycle->start_date?->format('Y-m-d')) }}" required class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2">
            </div>
            <div>
                <label class="block text-sm font-medium text-slate-700">End date</label>
                <input type="date" name="end_date" value="{{ old('end_date', $cycle->end_date?->format('Y-m-d')) }}" required class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2">
            </div>
            <div class="sm:col-span-2">
                <label class="block text-sm font-medium text-slate-700">Description</label>
                <textarea name="description" rows="3" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2">{{ old('description', $cycle->description) }}</textarea>
                @error('description')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                <p data-js-error="description" class="mt-1 text-sm text-red-600 hidden"></p>
            </div>
        </div>
        <div class="flex gap-2">
            <button type="submit" class="rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white">Save changes</button>
            <a href="{{ route('performance-cycles.index') }}" class="rounded-lg bg-slate-100 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200">Cancel</a>
        </div>
    </form>
</x-card>
@endsection

@push('scripts')
<script src="{{ asset('js/form-validation.js') }}"></script>
<script src="{{ asset('js/form-text-rules.js') }}"></script>
<script src="{{ asset('js/performance-cycle-form-validation.js') }}"></script>
@endpush
