<?php
// app/Providers/PermissionServiceProvider.php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use App\Services\PermissionService;

class PermissionServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        // @permission('view_rooms')
        Blade::if('permission', function (string $permission) {
            return auth()->check() && PermissionService::hasPermission(auth()->user(), $permission);
        });

        // @role('director')
        Blade::if('role', function (string $role) {
            return auth()->check() && auth()->user()->role === $role;
        });

        // @anyrole(['director', 'manager'])
        Blade::if('anyrole', function (array $roles) {
            return auth()->check() && in_array(auth()->user()->role, $roles);
        });
    }
}