<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\ModuleAccess;

class ModuleAccessControl extends Component
{
    public $modules;

    public function mount()
    {
        $this->modules = ModuleAccess::all();
    }

    public function toggleVisibility($id)
    {
        $module = ModuleAccess::findOrFail($id);
        $module->is_visible = !$module->is_visible;
        $module->save();

        $this->modules = ModuleAccess::all(); // refresh
    }

    public function render()
    {
        return view('livewire.module-access-control');
    }
}

