<?php

namespace App\Http\Controllers\Parent;

use App\Http\Controllers\Controller;
use App\Models\Announcement;
use App\Models\Message;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index()
    {
        $user = auth()->user();
        
        // Get announcements for parents or everyone
        $announcements = Announcement::where('school_id', $user->school_id)
            ->whereIn('target_role', ['parents', 'all'])
            ->latest()
            ->take(3)
            ->get();

        // Get unread messages count
        $unreadMessages = Message::where('receiver_id', $user->id)
            ->whereNull('read_at')
            ->count();

        // Get children (assuming User has children relationship)
        $children = $user->children()->with(['schoolClass', 'school'])->get();

        return view('parent.dashboard', compact('announcements', 'unreadMessages', 'children'));
    }
}
