@extends('layouts.admin')

@section('content')
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h2>Student Results</h2>
        <a href="{{ route('admin.results.create') }}" class="btn btn-success">+ Add Result</a>
    </div>

    @if (session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    @if($results->isEmpty())
        <div class="alert alert-info">No results found.</div>
    @else
        <div class="table-responsive">
            <table class="table table-bordered table-striped align-middle">
                <thead class="table-dark">
                    <tr>
                        <th>#</th>
                        <th>Registration Number</th>
                        <th>Course Code</th>
                        <th>Coursework Mark</th>
                        <th>Exam Mark</th>
                        <th>Final Mark</th>
                        <th>Grade</th>
                        <th>Decision</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($results as $index => $result)
                        <tr>
                            <td>{{ $index + 1 }}</td>
                            <td>{{ $result->registration_number }}</td>
                            <td>{{ $result->course_code }}</td>
                            <td>{{ $result->coursework_mark }}</td>
                            <td>{{ $result->exam_mark }}</td>
                            <td>{{ $result->final_mark }}</td>
                            <td>{{ $result->grade }}</td>
                            <td>{{ $result->decision }}</td>
                            <td>
                                <a href="{{ route('admin.results.show', $result->id) }}" class="btn btn-sm btn-info">View</a>
                                <a href="{{ route('admin.results.edit', $result->id) }}" class="btn btn-sm btn-primary">Edit</a>
                                <form action="{{ route('admin.results.destroy', $result->id) }}" method="POST" style="display:inline-block;">
                                    @csrf
                                    @method('DELETE')
                                    <button onclick="return confirm('Delete this result?')" class="btn btn-sm btn-danger">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    @endif
</div>
@endsection
