<?php

namespace Modules\ClinicStaffPortal\Http\Controllers;

use Illuminate\Routing\Controller;

/**
 * Core ERP integration hooks for ClinicStaffPortal. Contributes a "Open Staff App"
 * link into the ClinicCore sidebar via clinicCoreMenuItems() (the Extensions
 * group). The app itself is permission-gated by clinic.access_module.
 */
class DataController extends Controller
{
    public function superadmin_package()
    {
        return [
            [
                'name'    => 'clinic_staff_portal',
                'label'   => __('clinicStaffPortal::lang.clinic_staff_portal_module'),
                'default' => false,
            ],
        ];
    }

    public function user_permissions()
    {
        // No new permissions — the staff app reuses the existing clinic.*
        // and vet_admission.* permission set.
        return [];
    }

    /** Sidebar contribution rendered INSIDE the ClinicCore "Extensions" dropdown. */
    public function clinicCoreMenuItems()
    {
        return function ($sub) {
            if (!module_entitled('ClinicStaffPortal')) return;
            $user = auth()->user();
            if (! $user || ! $user->can('clinic.access_module')) {
                return;
            }

            // Opens the installable staff PWA shell in a new tab.
            $sub->url(
                url('staff-app'),
                __('clinicStaffPortal::lang.open_staff_app'),
                ['active' => false]
            );
        };
    }
}
