@extends('layouts.app')

@section('title', 'Teacher Dashboard - Edunetra')

@section('content')
<!-- Page Header -->
<section class="bg-edunetra-dark text-white py-5">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-8">
                <h1 class="display-4 fw-bold mb-3">Teacher Dashboard</h1>
                <p class="fs-5 text-light opacity-90">Manage your courses, sessions, and track student progress</p>
            </div>
            <div class="col-lg-4 text-lg-end">
                <a href="{{ route('teacher.courses.create') }}" class="btn btn-edunetra btn-lg">
                    <i class="bi bi-plus-circle me-2"></i>Create New Course
                </a>
            </div>
        </div>
    </div>
</section>

<!-- Stats Section -->
<section class="py-4 bg-light">
    <div class="container">
        <div class="row g-3">
            <div class="col-lg-3 col-md-6">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <i class="bi bi-book text-edunetra-yellow fs-1 mb-2"></i>
                        <h3 class="fw-bold text-edunetra-dark">{{ $stats['total_courses'] }}</h3>
                        <p class="text-muted mb-0">Total Courses</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <i class="bi bi-people text-success fs-1 mb-2"></i>
                        <h3 class="fw-bold text-edunetra-dark">{{ $stats['total_students'] }}</h3>
                        <p class="text-muted mb-0">Total Students</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <i class="bi bi-check-circle text-success fs-1 mb-2"></i>
                        <h3 class="fw-bold text-edunetra-dark">{{ $stats['published_courses'] }}</h3>
                        <p class="text-muted mb-0">Published</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <i class="bi bi-pencil text-warning fs-1 mb-2"></i>
                        <h3 class="fw-bold text-edunetra-dark">{{ $stats['draft_courses'] }}</h3>
                        <p class="text-muted mb-0">Drafts</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Courses Section -->
<section class="py-5">
    <div class="container">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="h3 fw-bold text-edunetra-dark">Your Courses</h2>
            <a href="{{ route('teacher.courses.index') }}" class="btn btn-outline-edunetra">
                <i class="bi bi-grid me-1"></i>View All Courses
            </a>
        </div>

        @if($courses->count() > 0)
            <div class="row g-4">
                @foreach($courses->take(6) as $course)
                    <div class="col-lg-4 col-md-6">
                        <div class="card h-100 border-0 shadow-sm">
                            <div class="card-img-top bg-light d-flex align-items-center justify-content-center" style="height: 180px;">
                                @if($course->image)
                                    <img src="{{ $course->image }}" alt="{{ $course->title }}" class="img-fluid rounded-top" style="object-fit: cover; height: 100%; width: 100%;">
                                @else
                                    <div class="text-center text-muted">
                                        <i class="bi bi-book fs-1 mb-2"></i>
                                        <p class="mb-0 small">{{ Str::limit($course->title, 20) }}</p>
                                    </div>
                                @endif
                            </div>
                            <div class="card-body d-flex flex-column">
                                <div class="d-flex justify-content-between align-items-start mb-2">
                                    <span class="badge bg-{{ $course->status === 'published' ? 'success' : 'warning' }} mb-2">
                                        {{ ucfirst($course->status) }}
                                    </span>
                                    <span class="badge bg-edunetra-yellow text-dark">
                                        {{ ucfirst($course->level) }}
                                    </span>
                                </div>

                                <h5 class="card-title fw-bold mb-2">{{ $course->title }}</h5>
                                <p class="card-text text-muted small flex-grow-1">{{ Str::limit($course->description, 80) }}</p>

                                <!-- Course Stats -->
                                <div class="row text-center mb-3">
                                    <div class="col-4">
                                        <small class="text-muted d-block">Sessions</small>
                                        <strong>{{ $course->sessions->count() }}</strong>
                                    </div>
                                    <div class="col-4">
                                        <small class="text-muted d-block">Students</small>
                                        <strong>{{ $course->enrollments->where('status', 'enrolled')->count() }}</strong>
                                    </div>
                                    <div class="col-4">
                                        <small class="text-muted d-block">Duration</small>
                                        <strong>{{ $course->duration_weeks }}w</strong>
                                    </div>
                                </div>

                                <!-- Action Buttons -->
                                <div class="d-grid gap-2">
                                    <a href="{{ route('teacher.courses.sessions', $course) }}" class="btn btn-edunetra btn-sm">
                                        <i class="bi bi-gear me-1"></i>Manage Course
                                    </a>
                                    <div class="btn-group" role="group">
                                        <a href="{{ route('teacher.courses.edit', $course) }}" class="btn btn-outline-edunetra btn-sm">
                                            <i class="bi bi-pencil me-1"></i>Edit
                                        </a>
                                        <a href="{{ route('courses.show', $course->slug) }}" class="btn btn-outline-edunetra btn-sm" target="_blank">
                                            <i class="bi bi-eye me-1"></i>Preview
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
        @else
            <div class="text-center py-5">
                <i class="bi bi-book display-1 text-muted mb-3"></i>
                <h3 class="fw-bold mb-2">No Courses Yet</h3>
                <p class="text-muted mb-4">Start creating your first course to begin teaching!</p>
                <a href="{{ route('teacher.courses.create') }}" class="btn btn-edunetra btn-lg">
                    <i class="bi bi-plus-circle me-2"></i>Create Your First Course
                </a>
            </div>
        @endif
    </div>
</section>
@endsection
