@extends('admin.layouts.main')
@section('title')
    {{ __('translations.examinations-edit') }}
@endsection
@section('sub-title')
    {{ __('translations.examinations') }}
@endsection
@section('content')
    <div class="content d-flex flex-column flex-column-fluid" id="kt_content">
        <div class="post d-flex flex-column-fluid" id="kt_post">
            <div id="kt_content_container" class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card card-docs mb-2">
                            <div class="card-header">
                                <div class="card-title m-0">
                                    <h3 class="fw-bolder m-0">{{ __('translations.examinations-edit') }}</h3>
                                </div>
                            </div>
                            <div class="card-body">
                                <form action="{{ route('admin.examinations.update', $examination->id) }}" method="post"
                                    enctype="multipart/form-data">
                                    @csrf
                                    @method('PUT') <!-- استخدم PUT لتحديث البيانات -->
                                    <div class="row">
                                        <!-- Examination Code -->
                                        <div class="col-md-6 mb-5">
                                            <label class="form-label">{{ __('translations.Examination Code') }} <span
                                                    class="text-danger">*</span></label>
                                            <input type="text" class="form-control" name="code"
                                                value="{{ $examination->code }}" readonly />
                                            @error('code')
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong>{{ $message }}</strong>
                                                </div>
                                            @enderror
                                        </div>

                                        <!-- Client Name -->
                                        <div class="col-md-6 mb-5">
                                            <label class="form-label">{{ __('translations.Client name') }} <span
                                                    class="text-danger">*</span></label>
                                            <select class="form-control" data-control="select2" name="client_id" required>
                                                <option value="" disabled>{{ __('translations.select_client') }}
                                                </option>
                                                @foreach ($clients as $client)
                                                    <option value="{{ $client->id }}"
                                                        {{ $client->id == $examination->client_id ? 'selected' : '' }}>
                                                        {{ $client->first_name . ' ' . $client->last_name }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('client_id')
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong>{{ $message }}</strong>
                                                </div>
                                            @enderror
                                        </div>

                                        <!-- Type -->
                                        <div class="col-md-6 mb-5">
                                            <label class="form-label">{{ __('translations.type') }} <span
                                                    class="text-danger">*</span></label>
                                            <select class="form-control" data-control="select2" name="type" required>
                                                <option value="" disabled>{{ __('translations.select_type') }}
                                                </option>
                                                @foreach ($types as $type)
                                                    <option value="{{ $type }}"
                                                        {{ $type == $examination->type ? 'selected' : '' }}>
                                                        {{ $type }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('type')
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong>{{ $message }}</strong>
                                                </div>
                                            @enderror
                                        </div>

                                        <!-- Examiner -->
                                        <div class="col-md-6 mb-5">
                                            <label class="form-label">{{ __('translations.examiner') }} <span
                                                    class="text-danger">*</span></label>
                                            <select class="form-control" data-control="select2" name="examiner_id" required>
                                                <option value="" disabled>{{ __('translations.select_examiner') }}
                                                </option>
                                                @foreach ($examiners as $examiner)
                                                    <option value="{{ $examiner->id }}"
                                                        {{ $examiner->id == $examination->examiner_id ? 'selected' : '' }}>
                                                        {{ $examiner->name }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('examiner_id')
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong>{{ $message }}</strong>
                                                </div>
                                            @enderror
                                        </div>

                                        <!-- Notes -->
                                        <div class="col-md-12 mb-5">
                                            <label class="form-label">{{ __('translations.Note') }} <span
                                                    class="text-danger">*</span></label>
                                            <textarea class="form-control" name="notes" rows="5">{{ $examination->notes }}</textarea>
                                            @error('notes')
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong>{{ $message }}</strong>
                                                </div>
                                            @enderror
                                        </div>

                                        <!-- Status -->
                                        <div class="col-md-6 mb-5">
                                            <input type="text" class="form-control" name="status"
                                                value="{{ $examination->status }}" hidden />
                                            @error('status')
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong>{{ $message }}</strong>
                                                </div>
                                            @enderror
                                        </div>

                                        <!-- Examination Details Table -->
                                        <div class="card-body" dir="ltr">
                                            <table
                                                class="table align-middle table-row-dashed fs-6 gy-5 custom-table d-table">
                                                <thead>
                                                    <tr class="fw-bolder fs-8 text-uppercase gs-0">
                                                        <th>Type</th>
                                                        <th>Sph</th>
                                                        <th>Cyl</th>
                                                        <th>Axis</th>
                                                        <th>A.D.D</th>
                                                        <th>I.P.D</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="text-gray-800 fw-bold">
                                                    <tr>
                                                        <td>Rt</td>
                                                        <td>{{ $examination->rt_sph ?? '--' }}</td>
                                                        <td>{{ $examination->rt_cyl ?? '--' }}</td>
                                                        <td>{{ $examination->rt_axis ?? '--' }}</td>
                                                        <td>{{ $examination->rt_lpd ?? '--' }}</td>
                                                        <td>{{ $examination->rt_add ?? '--' }}</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Lt</td>
                                                        <td>{{ $examination->lt_sph ?? '--' }}</td>
                                                        <td>{{ $examination->lt_cyl ?? '--' }}</td>
                                                        <td>{{ $examination->lt_axis ?? '--' }}</td>
                                                        <td>{{ $examination->lt_lpd ?? '--' }}</td>
                                                        <td>{{ $examination->lt_add ?? '--' }}</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>

                                        <!-- Buttons -->
                                        <div class="d-flex pt-5 justify-content-between align-items-center">
                                            <a href="{{ route('admin.examinations.index') }}" class="btn btn-secondary">
                                                {{ __('translations.back') }} <i class="fa fa-undo" aria-hidden="true"></i>
                                            </a>
                                            <button type="submit" class="btn btn-primary">
                                                {{ __('translations.update') }} <i class="fa fa-check"
                                                    aria-hidden="true"></i>
                                            </button>
                                        </div>
                                    </div>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
