<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@yield('title', 'AI Vision Attendance')</title>
    <link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
<body>
@auth
    <div class="app-shell">
        <aside class="sidebar">
            <div class="brand">AI Vision <span>Attendance</span></div>
            <nav>
                <a href="{{ route('dashboard') }}" class="{{ request()->routeIs('dashboard') ? 'active' : '' }}">Dashboard</a>
                @if(in_array(auth()->user()->role, ['admin', 'hr']))
                    <a href="{{ route('employees.index') }}" class="{{ request()->routeIs('employees.*') ? 'active' : '' }}">Employees</a>
                    <a href="{{ route('attendance.index') }}" class="{{ request()->routeIs('attendance.index') || request()->routeIs('attendance.correct*') ? 'active' : '' }}">Attendance Register</a>
                    <a href="{{ route('reports.daily') }}" class="{{ request()->routeIs('reports.*') ? 'active' : '' }}">Reports</a>
                @endif
                <a href="{{ route('attendance.manual-entry') }}" class="{{ request()->routeIs('attendance.manual-entry*') ? 'active' : '' }}">Manual Entry</a>
                @if(auth()->user()->role === 'admin')
                    <a href="{{ route('devices.index') }}" class="{{ request()->routeIs('devices.*') ? 'active' : '' }}">Devices</a>
                    <a href="{{ route('users.index') }}" class="{{ request()->routeIs('users.*') ? 'active' : '' }}">Users</a>
                    <a href="{{ route('maintenance.index') }}" class="{{ request()->routeIs('maintenance.*') ? 'active' : '' }}">Maintenance</a>
                @endif
            </nav>
            <form method="POST" action="{{ route('logout') }}" class="logout-form">
                @csrf
                <div class="user-chip">{{ auth()->user()->name }} <span class="role-badge">{{ auth()->user()->role }}</span></div>
                <button type="submit" class="btn-link">Log out</button>
            </form>
        </aside>
        <main class="content">
            @if(session('status'))
                <div class="alert alert-success">{{ session('status') }}</div>
            @endif
            @if($errors->any())
                <div class="alert alert-error">
                    <ul>
                        @foreach($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
            @yield('content')
        </main>
    </div>
@else
    @yield('content')
@endauth
</body>
</html>
