<?php
/**
 * Property Management System Menu Configuration
 * Define different menu structures for different user roles
 */

/**
 * Get menu configuration based on user role
 */
function getMenuConfig($userRole = 'guest')
{

    // Common menu items for all logged-in users
    $commonMenus = [
        [
            'title' => 'Main Menu',
            'type' => 'header'
        ]
    ];
    
    // Role-specific dashboard URLs
    $dashboardUrls = [
        'Super Admin' => 'index.php',
        'Landlord' => 'landlord_dashboard.php',
        'Property Agent' => 'agent_dashboard.php',
        'Tenant' => 'tenant_dashboard.php',
        'Buyer' => 'buyer_dashboard.php',
        'Vendor' => 'vendor_dashboard.php',
        'Accountant' => 'accountant_dashboard.php'
    ];
    
    // Add dashboard link based on role
    $dashboardUrl = $dashboardUrls[$userRole] ?? 'index.php';
    $commonMenus[] = [
        'title' => 'Dashboard',
        'icon' => 'ph-chart-line',
        'url' => $dashboardUrl,
        'type' => 'link'
    ];

    // Role-specific menu configurations
    $roleMenus = [
        'Super Admin' => [
            // Property Management
            [
                'title' => 'Property Management',
                'type' => 'header'
            ],
            [
                'title' => 'Properties',
                'icon' => 'ph-buildings',
                'type' => 'dropdown',
                'id' => 'propertiesMenu',
                'items' => [
                    ['title' => 'All Properties', 'url' => 'list_properties.php'],
                    ['title' => 'Add Property', 'url' => 'add_property.php'],
                    ['title' => 'Units', 'url' => 'list_units.php'],
                    ['title' => 'Add Unit', 'url' => 'add_unit.php']
                ]
            ],
            [
                'title' => 'Tenants & Leases',
                'icon' => 'ph-users',
                'type' => 'dropdown',
                'id' => 'tenantsMenu',
                'items' => [
                    ['title' => 'All Tenants', 'url' => 'list_tenants.php'],
                    ['title' => 'Add Tenant', 'url' => 'add_tenant.php'],
                    ['title' => 'Lease Agreements', 'url' => 'list_leases.php'],
                    ['title' => 'Create Lease', 'url' => 'create_lease.php'],
                    ['title' => 'Tenant Screening', 'url' => 'tenant_screening.php']
                ]
            ],

            // Sales Module
            [
                'title' => 'Sales Management',
                'type' => 'header'
            ],
            [
                'title' => 'Unit Sales',
                'icon' => 'ph-tag',
                'type' => 'dropdown',
                'id' => 'salesMenu',
                'items' => [
                    ['title' => 'Units for Sale', 'url' => 'list_units_sale.php'],
                    ['title' => 'Reservations', 'url' => 'list_reservations.php'],
                    ['title' => 'Sales Agreements', 'url' => 'list_sales.php'],
                    ['title' => 'Installments', 'url' => 'sales_installments.php']
                ]
            ],
            [
                'title' => 'CRM',
                'icon' => 'ph-address-book',
                'type' => 'dropdown',
                'id' => 'crmMenu',
                'items' => [
                    ['title' => 'Leads / Buyers', 'url' => 'list_leads.php'],
                    ['title' => 'Add Lead', 'url' => 'add_lead.php'],
                    ['title' => 'CRM Dashboard', 'url' => 'crm_dashboard.php']
                ]
            ],

            // Financials
            [
                'title' => 'Financials',
                'type' => 'header'
            ],
            [
                'title' => 'Billing & Rent',
                'icon' => 'ph-money',
                'type' => 'dropdown',
                'id' => 'billingMenu',
                'items' => [
                    ['title' => 'Invoices', 'url' => 'list_invoices.php'],
                    ['title' => 'Payments Received', 'url' => 'list_payments.php'],
                    ['title' => 'Rent Roll', 'url' => 'rent_roll.php'],
                    ['title' => 'M-Pesa Transactions', 'url' => 'mpesa_transactions.php']
                ]
            ],
            [
                'title' => 'Accounting',
                'icon' => 'ph-calculator',
                'type' => 'dropdown',
                'id' => 'accountingMenu',
                'items' => [
                    ['title' => 'Expenses', 'url' => 'list_expenses.php'],
                    ['title' => 'Landlord Wallets', 'url' => 'landlord_wallets.php'],
                    ['title' => 'Bank Reconciliation', 'url' => 'bank_reconciliation.php'],
                    ['title' => 'Profit & Loss', 'url' => 'report_pnl.php']
                ]
            ],

            // Maintenance
            [
                'title' => 'Maintenance',
                'type' => 'header'
            ],
            [
                'title' => 'Work Orders',
                'icon' => 'ph-wrench',
                'type' => 'dropdown',
                'id' => 'maintenanceMenu',
                'items' => [
                    ['title' => 'All Requests', 'url' => 'list_maintenance.php'],
                    ['title' => 'Work Orders', 'url' => 'list_work_orders.php'],
                    ['title' => 'Vendors', 'url' => 'list_vendors.php']
                ]
            ],

            // Admin
            [
                'title' => 'System',
                'type' => 'header'
            ],
            [
                'title' => 'Settings',
                'icon' => 'ph-gear',
                'type' => 'dropdown',
                'id' => 'settingsMenu',
                'items' => [
                    ['title' => 'Users & Roles', 'url' => 'list_users.php'],
                    ['title' => 'General Settings', 'url' => 'system_settings.php'],
                    ['title' => 'Audit Logs', 'url' => 'audit_logs.php']
                ]
            ]
        ],

        'Landlord' => [
            [
                'title' => 'My Investment',
                'type' => 'header'
            ],
            [
                'title' => 'Properties',
                'icon' => 'ph-buildings',
                'url' => 'my_properties.php',
                'type' => 'link'
            ],
            [
                'title' => 'Financials',
                'icon' => 'ph-coins',
                'type' => 'dropdown',
                'id' => 'landlordFinanceMenu',
                'items' => [
                    ['title' => 'Rental Income', 'url' => 'my_rental_income.php'],
                    ['title' => 'Expenses', 'url' => 'my_property_expenses.php'],
                    ['title' => 'Wallet / Withdrawals', 'url' => 'my_wallet.php'],
                    ['title' => 'Statements', 'url' => 'my_statements.php']
                ]
            ],
            [
                'title' => 'Reports',
                'icon' => 'ph-chart-pie',
                'type' => 'dropdown',
                'id' => 'landlordReportsMenu',
                'items' => [
                    ['title' => 'Occupancy Report', 'url' => 'report_occupancy.php'],
                    ['title' => 'Maintenance Report', 'url' => 'report_maintenance.php']
                ]
            ]
        ],

        'Property Agent' => [
            [
                'title' => 'Management',
                'type' => 'header'
            ],
            [
                'title' => 'Properties',
                'icon' => 'ph-buildings',
                'url' => 'list_properties.php',
                'type' => 'link'
            ],
            [
                'title' => 'Tenants',
                'icon' => 'ph-users',
                'type' => 'dropdown',
                'id' => 'agentTenantsMenu',
                'items' => [
                    ['title' => 'Active Tenants', 'url' => 'list_tenants.php'],
                    ['title' => 'Lease Renewals', 'url' => 'lease_renewals.php'],
                    ['title' => 'Vacant Units', 'url' => 'vacant_units.php']
                ]
            ],
            [
                'title' => 'Maintenance',
                'icon' => 'ph-wrench',
                'url' => 'list_maintenance.php',
                'type' => 'link'
            ],
            [
                'title' => 'Sales',
                'icon' => 'ph-tag',
                'type' => 'dropdown',
                'id' => 'agentSalesMenu',
                'items' => [
                    ['title' => 'Leads', 'url' => 'list_leads.php'],
                    ['title' => 'Sales Reservations', 'url' => 'list_reservations.php']
                ]
            ]
        ],

        'Tenant' => [
            [
                'title' => 'My Home',
                'type' => 'header'
            ],
            [
                'title' => 'Lease Info',
                'icon' => 'ph-file-text',
                'url' => 'my_lease.php',
                'type' => 'link'
            ],
            [
                'title' => 'Payments',
                'icon' => 'ph-credit-card',
                'type' => 'dropdown',
                'id' => 'tenantPaymentMenu',
                'items' => [
                    ['title' => 'Pay Rent', 'url' => 'pay_rent.php'],
                    ['title' => 'Payment History', 'url' => 'my_payments.php'],
                    ['title' => 'Invoices', 'url' => 'my_invoices.php']
                ]
            ],
            [
                'title' => 'Maintenance',
                'icon' => 'ph-wrench',
                'type' => 'dropdown',
                'id' => 'tenantMaintenanceMenu',
                'items' => [
                    ['title' => 'Report Issue', 'url' => 'report_issue.php'],
                    ['title' => 'My Requests', 'url' => 'my_maintenance_requests.php']
                ]
            ]
        ],

        'Buyer' => [
            [
                'title' => 'My Investment',
                'type' => 'header'
            ],
            [
                'title' => 'My Units',
                'icon' => 'ph-house',
                'url' => 'my_purchased_units.php',
                'type' => 'link'
            ],
            [
                'title' => 'Payments',
                'icon' => 'ph-receipt',
                'type' => 'dropdown',
                'id' => 'buyerPaymentMenu',
                'items' => [
                    ['title' => 'Installments', 'url' => 'my_installments.php'],
                    ['title' => 'Payment History', 'url' => 'my_payment_history.php']
                ]
            ],
            [
                'title' => 'Documents',
                'icon' => 'ph-file',
                'url' => 'my_documents.php',
                'type' => 'link'
            ]
        ],

        'Vendor' => [
            [
                'title' => 'Work',
                'type' => 'header'
            ],
            [
                'title' => 'Jobs',
                'icon' => 'ph-briefcase',
                'type' => 'dropdown',
                'id' => 'vendorJobsMenu',
                'items' => [
                    ['title' => 'New Work Orders', 'url' => 'new_work_orders.php'],
                    ['title' => 'My Jobs', 'url' => 'my_jobs.php']
                ]
            ],
            [
                'title' => 'Invoicing',
                'icon' => 'ph-receipt',
                'url' => 'vendor_invoices.php',
                'type' => 'link'
            ]
        ],

        'Accountant' => [
            [
                'title' => 'Finance',
                'type' => 'header'
            ],
            [
                'title' => 'Accounts',
                'icon' => 'ph-calculator',
                'type' => 'dropdown',
                'id' => 'acctMenu',
                'items' => [
                    ['title' => 'Invoices', 'url' => 'list_invoices.php'],
                    ['title' => 'Payments', 'url' => 'list_payments.php'],
                    ['title' => 'Expenses', 'url' => 'list_expenses.php'],
                    ['title' => 'Ledger', 'url' => 'general_ledger.php']
                ]
            ],
            [
                'title' => 'Reports',
                'icon' => 'ph-chart-bar',
                'url' => 'financial_reports.php',
                'type' => 'link'
            ]
        ]
    ];

    // Combine common menu with role-specific menu
    if (isset($roleMenus[$userRole])) {
        return array_merge($commonMenus, $roleMenus[$userRole]);
    }

    // Default menu (dashboard only)
    return $commonMenus;
}
?>