@extends('layouts.app')

@section('content')

    <!--begin::App Content Header-->
    <div class="app-content-header"> <!--begin::Container-->
        <div class="container-fluid">
            <!--begin::Row-->
            <div class="row">
                <div class="col-sm-6">
                    <h3 class="mb-0">Form Status Timeline</h3>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-end">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('form.index') }}">Form List</a></li>
                        <li class="breadcrumb-item active">Form Status Timeline</li>
                    </ol>
                </div>
            </div>
            <!--end::Row-->
        </div> <!--end::Container-->
    </div>
    <!--end::App Content Header-->

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="row justify-content-center">
                        <div class="col-md-8">
                            <div class="timeline">
                                <!-- First Time Label for Form Submission -->
                                <div class="time-label">
                                    <span class="text-bg-danger"><i class="fas fa-clock"></i>
                                        {{ $submittedForm->created_at->format('d M Y') }}</span>
                                </div>
                                <div>
                                    <i class="timeline-icon bi bi-envelope text-bg-primary"></i>
                                    <div class="timeline-item">
                                        <span class="time">
                                            <i class="bi bi-clock-fill"></i>
                                            {{ $submittedForm->created_at->format('h:i A') }}
                                        </span>
                                        <h3 class="timeline-header"> <a href="#">Form Submitted</a> sent you an email
                                        </h3>
                                        <div class="timeline-body">
                                            Submitted by: {{ $submittedForm->created_by ?? 'Unknown User' }}
                                        </div>
                                    </div>
                                </div>


                                @php
                                    // Track the date of the previous status log
                                    $previousDate = null;
                                @endphp

                                <!-- Show latest status after verification or rejection -->
                                @if ($submittedForm->form_status->title === 'Verified' || $submittedForm->form_status->title === 'Rejected')
                                    @if ($previousDate !== now()->format('d M Y'))
                                        <!-- New Time Label for current date if different -->
                                        <div class="time-label">
                                            <span class="text-bg-primary"><i class="fas fa-clock"></i>
                                                {{ now()->format('d M Y') }}</span>
                                        </div>
                                    @endif

                                    <div>
                                        <i class="timeline-icon bi bi-envelope text-bg-primary"></i>
                                        <div class="timeline-item">
                                            <span class="time">
                                                <i class="bi bi-clock-fill"></i>
                                                {{ now()->format('h:i A') }}
                                            </span>
                                            <h3 class="timeline-header"> <a
                                                    href="#">{{ $submittedForm->form_status->title }}</a> sent you an
                                                email
                                            </h3>
                                            <div class="timeline-body">
                                                Status updated by: {{ auth()->user()->username }}
                                            </div>
                                        </div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
