<?php
declare(strict_types=1);

use App\Core\Registries\PermissionRegistry;
use App\Core\EventBus;

// Menu registered centrally via Members/bootstrap.php under "membership" parent.

PermissionRegistry::register('documents', [
    'document.upload' => ['ar' => 'رفع مستندات', 'en' => 'Upload Documents'],
    'document.view'   => ['ar' => 'عرض مستندات', 'en' => 'View Documents'],
    'document.delete' => ['ar' => 'حذف مستندات', 'en' => 'Delete Documents'],
]);

// Enrich member profile with document count
EventBus::listen('member.profile_data', function(array &$data) {
    if (isset($data['member']) && is_object($data['member']) && isset($data['member']->id)) {
        try {
            $data['documents'] = \App\Modules\Documents\Models\Document::getForMember((int) $data['member']->id);
        } catch (\Throwable $e) {
            $data['documents'] = [];
        }
    }
});