<?php

namespace App\Http\Controllers\Dashboard;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class SidebarController extends Controller
{
    public function index(Request $request)
    {
        $user = Auth::user();
        if (!$user) {
            return redirect()->route('login');
        }

        $collapsed = session()->get('collapsed', false);
        $navigation = [
            ['key' => 0, 'label' => 'User Management', 'path' => '/user-management', 'icon' => 'team', 'access' => $user && $user->role == 1],
            ['key' => 9, 'label' => 'Notifications', 'path' => '/notifications', 'icon' => 'notification', 'access' => true],
            ['key' => 4, 'label' => 'Member Management', 'path' => '/member-management', 'icon' => 'credit-card', 'access' => $user && $user->role == 1, 'child' => [
                ['key' => 0.0, 'label' => 'Card Member', 'path' => '/member-management/card-member', 'access' => true],
                ['key' => 0.1, 'label' => 'Locked Accounts', 'path' => '/member-management/lock-account', 'access' => true],
            ]],
            ['key' => 8, 'label' => 'Home Page ( Mobile )', 'path' => '/home-page', 'icon' => 'home', 'access' => true, 'child' => [
                ['key' => 0.0, 'label' => 'Photo Slider', 'path' => '/home-page/photo-slider', 'access' => true],
            ]],
            ['key' => 3, 'label' => 'Promotions', 'path' => '/promotions', 'icon' => 'tags', 'access' => true],
            ['key' => 2, 'label' => 'Top-Up', 'path' => '/top-up', 'icon' => 'plus-circle', 'access' => $user && $user->role == 1],
            ['key' => 6, 'label' => 'About Us', 'path' => '/about-us', 'icon' => 'info-circle', 'access' => $user && $user->role == 1, 'child' => [
                ['key' => 0.6, 'label' => 'Card Types', 'path' => '/about-us/card-types', 'access' => true],
                ['key' => 0.5, 'label' => 'Terms & Privacy', 'path' => '/about-us/term-privacy', 'access' => true],
            ]],
            ['key' => 7, 'label' => 'Reports', 'path' => '/reports', 'icon' => 'file-text', 'access' => true, 'child' => [
                ['key' => 0.7, 'label' => 'Registration Report', 'path' => '/reports/registration-report', 'access' => true],
                ['key' => 0.8, 'label' => 'Top-Up Usage Report', 'path' => '/reports/top-up', 'access' => true],
                ['key' => 0.9, 'label' => 'Mobile Usage Report', 'path' => '/reports/mobile-report', 'access' => true],
                ['key' => 0.1, 'label' => 'Station Rating Report', 'path' => '/reports/station-rating', 'access' => true],
            ]],
            ['key' => 8, 'label' => 'System Parameters', 'path' => '/system-parameters', 'icon' => 'setting', 'access' => $user && $user->role == 1],
            ['key' => 12, 'label' => 'Station Locator', 'path' => '', 'icon' => 'environment', 'access' => true, 'child' => [
                ['key' => 0.11, 'label' => 'Branches', 'path' => '/branches', 'access' => true],
                ['key' => 0.12, 'label' => 'Stations', 'path' => '/stations', 'access' => true],
                ['key' => 0.13, 'label' => 'Fuels', 'path' => '/fuels', 'access' => true],
            ]],
        ];

        return view('dashboard.sidebar', compact('collapsed', 'navigation', 'user'));
    }
}