@extends('training.inc.master')

@section('title','Dashboard')

@section('content')

<main class="content">
				<div class="container-fluid p-0">

				<h1 class="h3 mb-3"><strong>Update Training </strong> Enrolment details</h1>
				@include('training.alerts.alert')


                <div class="row">
                   <div class="col-12">
                    <div class="card shadow-sm">
                        <div class="card-header bg-primary text-white">
                            <h4 class="mb-0">Update Enrolment Details</h4>
                        </div>
                        <div class="card-body">
                            <form action="{{ route('students.update', $student->id) }}" method="POST">
                                @csrf
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label for="name" class="form-label">Full Names</label>
                                        <input type="text" class="form-control" id="name" name="name" value="{{ old('name', $student->name) }}" required>
                                    </div>
                                    <div class="col-md-6">
                                        <label for="idno" class="form-label">National ID</label>
                                        <input type="text" class="form-control" id="idno" name="idno" value="{{ old('idno', $student->idno) }}" required>
                                    </div>
                                </div>

                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label for="phone" class="form-label">Phone</label>
                                        <input type="text" class="form-control" id="phone" name="phone" value="{{ old('phone', $student->phone) }}" required>
                                    </div>
                                    <div class="col-md-6">
                                        <label for="email" class="form-label">Email</label>
                                        <input type="email" class="form-control" id="email" name="email" value="{{ old('email', $student->email) }}">
                                    </div>
                                </div>

                                <div class="row mb-3">
                                     <div class="col-md-6">
                                        <label for="station" class="form-label">Station</label>
                                        <select name="station" id="station" class="form-select" required>
                                            {{-- First, show the student's current station as selected --}}
                                            <option value="{{ $student->station }}" selected>
                                                {{ $student->station }}
                                            </option>

                                            {{-- Then, show the rest of the stations --}}
                                            @foreach($stations as $st)
                                                <option value="{{ $st->station_name }}">{{ $st->station_name }}</option>
                                            @endforeach
                                        </select>
                                    </div>

                                    <div class="col-md-6">
                                        <label for="paymentmode" class="form-label">Payment Mode</label>
                                        <select name="paymentmode" id="paymentmode" class="form-select">
                                            <option value="">Select Mode</option>
                                            <option value="mpesa" {{ $student->paymentmode == 'mpesa' ? 'selected' : '' }}>M-PESA</option>
                                            <option value="kcb" {{ $student->paymentmode == 'kcb' ? 'selected' : '' }}>Bank</option>
                                            <option value="Cheque" {{ $student->paymentmode == 'Cheque' ? 'selected' : '' }}>Cheque</option>
                                            <option value="LPO" {{ $student->paymentmode == 'LPO' ? 'selected' : '' }}>LPO</option>
                                        </select>
                                    </div>
                                    
                                </div>

                                <div class="mb-3">
                                    <label for="coursecode" class="form-label">Course</label>
                                    <select name="coursecode" id="coursecode" class="form-select" required>
                                        <option value="">-- Select Course --</option>
                                        @foreach($courses as $course)
                                            <option value="{{ $course->id }}" 
                                                {{ $student->course == $course->id ? 'selected' : '' }}>
                                                {{ $course->course_name }}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="text-end">
                                    <a href="{{ route('weeklyStudentenrolments') }}" class="btn btn-secondary">Cancel</a>
                                    <button type="submit" class="btn btn-primary">Update Student</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
				
			</main>
@endsection