<?php

$collectPermissionKeys = static function (array $items) use (&$collectPermissionKeys): array {
    $keys = [];

    foreach ($items as $item) {
        $permission = $item['permission_key'] ?? null;
        if (is_string($permission) && $permission !== '') {
            $keys[] = $permission;
        }

        $children = $item['children'] ?? [];
        if (is_array($children) && $children !== []) {
            $keys = [...$keys, ...$collectPermissionKeys($children)];
        }
    }

    return $keys;
};

$allDashboardPermissions = array_values(array_unique($collectPermissionKeys(config('mtt_dashboard_menu', []))));
$allPermissions = $allDashboardPermissions;
$landingPermission = 'dashboard.index.view';

$settingsDealersPermissions = [
    'settings.dealers.view',
    'settings.dealers.manage',
];

$settingsUsersPermissions = [
    'settings.users.view',
    'settings.users.manage',
    'settings.users.security',
];

$settingsDepartmentsPermissions = [
    'settings.departments.manage',
    'settings.branches.manage',
];

$settingsBrandingPermissions = [
    'settings.branding.manage',
];

$exclude = static fn(array $items, array $excluded): array => array_values(array_filter(
    $items,
    static fn(string $permission): bool => !in_array($permission, $excluded, true)
));

$merge = static fn(array ...$parts): array => array_values(array_unique(array_merge(...$parts)));

$companyCommon = [
    'dashboard.company_documents.employees_meet_team.view',
    'dashboard.company_documents.my_documents.view',
    'dashboard.company_documents.company_documents.policies_and_procedures.view',
    'dashboard.company_documents.company_documents.templates_and_forms.view',
    'dashboard.company_documents.calendar.birthdays.view',
    'dashboard.company_documents.calendar.events.view',
    'dashboard.company_documents.calendar.tasks_due.view',
    'dashboard.company_documents.calendar.reminders.view',
    'dashboard.company_documents.quick_actions.create_task.view',
    'dashboard.company_documents.quick_actions.request_a_payment.view',
    'dashboard.company_documents.tasks.announcements.view',
    'dashboard.company_documents.tasks.task_delegation.view',
    'dashboard.company_documents.tasks.manager_messages.view',
    'dashboard.company_documents.duties.daily.view',
    'dashboard.company_documents.duties.weekly.view',
    'dashboard.company_documents.duties.monthly.view',
    'dashboard.company_documents.hr_payroll.offer_letter.view',
    'dashboard.company_documents.hr_payroll.signed_contract_duty_list_etc.view',
    'dashboard.company_documents.hr_payroll.payslips.view',
    'dashboard.company_documents.hr_payroll.leave.view',
    'dashboard.company_documents.hr_payroll.performance_reviews.view',
    'dashboard.company_documents.hr_payroll.disciplinary.view',
];

$companySalesStats = [
    'dashboard.company_documents.performance_stats.sales.units_mtd.view',
    'dashboard.company_documents.performance_stats.sales.gross_profit_mtd.view',
    'dashboard.company_documents.performance_stats.sales.forecast_vs_actual_units_and_gp.view',
    'dashboard.company_documents.performance_stats.sales.prospecting.view',
    'dashboard.company_documents.performance_stats.sales.exhibitions.view',
    'dashboard.company_documents.performance_stats.sales.calls_quotes_apps_and_sales_vs_target_tracking.view',
    'dashboard.company_documents.performance_stats.sales.appraisals.view',
    'dashboard.company_documents.performance_stats.sales.comebacks_aftersales.view',
    'dashboard.company_documents.performance_stats.sales.commission_current_month_and_historic.view',
];

$companyFiStats = [
    'dashboard.company_documents.performance_stats.fi.target_vs_actual_2nd_gross.view',
    'dashboard.company_documents.performance_stats.fi.vaps_penetration.view',
    'dashboard.company_documents.performance_stats.fi.rand_per_1000_per_bank.view',
    'dashboard.company_documents.performance_stats.fi.finance_vs_cash_vs_self_finance_deals.view',
    'dashboard.company_documents.performance_stats.fi.commission_current_month_and_historic.view',
];

$companyManagerStats = [
    'dashboard.company_documents.performance_stats.manager.total_1st_gross.view',
    'dashboard.company_documents.performance_stats.manager.total_2nd_gross.view',
    'dashboard.company_documents.performance_stats.manager.total_gross_profit_mtd.view',
    'dashboard.company_documents.performance_stats.manager.total_forecast_vs_actual_units_and_gp.view',
    'dashboard.company_documents.performance_stats.manager.expenses_and_nett_profit.view',
    'dashboard.company_documents.performance_stats.manager.commission_current_month_and_historic.view',
];

$companyDealFilesAndFinance = [
    'dashboard.company_documents.company_documents.finance_and_insurance.view',
    'dashboard.company_documents.company_documents.deal_files.view',
];

$companyQuickActionsExtended = [
    'dashboard.company_documents.quick_actions.new_lead.view',
    'dashboard.company_documents.quick_actions.log_a_comeback_after_sale.view',
    'dashboard.company_documents.quick_actions.request_valuation.view',
    'dashboard.company_documents.quick_actions.check_stock.view',
];

$companyTasksExtended = [
    'dashboard.company_documents.tasks.quick_links.view',
    'dashboard.company_documents.tasks.pending_docs.view',
];

$companyAll = $merge(
    $companyCommon,
    $companySalesStats,
    $companyFiStats,
    $companyManagerStats,
    $companyDealFilesAndFinance,
    $companyQuickActionsExtended,
    $companyTasksExtended
);

$buyerCompany = $merge(
    $companyCommon,
    $companySalesStats,
    $companyDealFilesAndFinance,
    $companyQuickActionsExtended,
    $companyTasksExtended
);

$fiCompany = $merge(
    $companyCommon,
    $companySalesStats,
    $companyFiStats,
    $companyDealFilesAndFinance,
    $companyQuickActionsExtended,
    $companyTasksExtended
);

$salesmanCompany = $merge(
    $companyCommon,
    $companySalesStats,
    $companyDealFilesAndFinance,
    $companyQuickActionsExtended,
    $companyTasksExtended
);

$driverCleanerCompany = $companyCommon;

$marketingCompany = $merge(
    $companyCommon,
    $companyTasksExtended
);

$stockControllerCompany = $merge(
    $companyCommon,
    [
        'dashboard.company_documents.performance_stats.sales.comebacks_aftersales.view',
        'dashboard.company_documents.performance_stats.sales.commission_current_month_and_historic.view',
        'dashboard.company_documents.quick_actions.log_a_comeback_after_sale.view',
        'dashboard.company_documents.quick_actions.check_stock.view',
    ],
    $companyTasksExtended
);

$receptionistCompany = $merge(
    $companyCommon,
    [
        'dashboard.company_documents.company_documents.deal_files.view',
        'dashboard.company_documents.quick_actions.check_stock.view',
    ],
    $companyTasksExtended
);

$stockAll = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.sales.view',
    'dashboard.stock.purchases.view',
    'dashboard.stock.recon.view',
    'dashboard.stock.admin.view',
    'dashboard.stock.driver.view',
    'dashboard.stock.cleaner.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_take.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
    'dashboard.stock.attach_vcard_to_stock.view',
];

$buyerStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.purchases.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
    'dashboard.stock.attach_vcard_to_stock.view',
];

$fiStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.sales.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
    'dashboard.stock.attach_vcard_to_stock.view',
];

$salesmanStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.sales.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
    'dashboard.stock.attach_vcard_to_stock.view',
];

$driverStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.driver.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
];

$cleanerStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.cleaner.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
];

$marketingStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
    'dashboard.stock.attach_vcard_to_stock.view',
];

$financialManagerStock = $stockAll;

$stockControllerStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.recon.view',
    'dashboard.stock.admin.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_take.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
];

$receptionistStock = [
    'dashboard.stock.zero_tolerance.view',
    'dashboard.stock.admin.view',
    'dashboard.stock.stock_list.view',
    'dashboard.stock.stock_reports.view',
    'dashboard.stock.whatsapp_share_stock_list.view',
];

$crmVehicleSaleCore = [
    'dashboard.crm_leads.vehicle_sale_leads.my_leads.view',
    'dashboard.crm_leads.vehicle_sale_leads.new_leads.view',
    'dashboard.crm_leads.vehicle_sale_leads.affiliate_leads.view',
    'dashboard.crm_leads.vehicle_sale_leads.reminders.view',
    'dashboard.crm_leads.vehicle_sale_leads.hot_list.view',
    'dashboard.crm_leads.vehicle_sale_leads.lead_source_report.view',
    'dashboard.crm_leads.vehicle_sale_leads.marketing_tools_prospecting.view',
    'dashboard.crm_leads.vehicle_sale_leads.prospecting.view',
    'dashboard.crm_leads.vehicle_sale_leads.communication_history.view',
    'dashboard.crm_leads.vehicle_sale_leads.calendar.view',
    'dashboard.crm_leads.vehicle_sale_leads.customer_follow_ups.view',
    'dashboard.crm_leads.vehicle_sale_leads.parked_customers.view',
];

$crmFinanceCalculator = [
    'dashboard.crm_leads.vehicle_sale_leads.finance_calculator.view',
];

$crmDealBuilder = [
    'dashboard.crm_leads.vehicle_sale_leads.deal_builder.view',
];

$crmSellMyCarLeads = [
    'dashboard.crm_leads.vehicle_purchase_leads.sell_my_car_leads.view',
];

$crmFull = $merge($crmVehicleSaleCore, $crmFinanceCalculator, $crmDealBuilder, $crmSellMyCarLeads);
$crmBuyer = $merge($crmFinanceCalculator, $crmSellMyCarLeads);
$crmStockController = $merge($crmFinanceCalculator, $crmDealBuilder, $crmSellMyCarLeads);

$valuationsCommon = [
    'dashboard.valuations.new_evaluation.view',
    'dashboard.valuations.new_vehicle_pre_inspection.view',
    'dashboard.valuations.valuations_subject_to_view_prices.view',
    'dashboard.valuations.transunion_values.view',
    'dashboard.valuations.pricing_on_vehicles.view',
    'dashboard.valuations.validate_vehicle.view',
    'dashboard.valuations.accident_history_report.view',
];

$valuationsStockController = [
    'dashboard.valuations.pricing_on_vehicles.view',
];

$performanceSalesRows = [
    'dashboard.performance_stats.targets.sales.view',
    'dashboard.performance_stats.actuals.sales.view',
    'dashboard.performance_stats.targets_vs_actuals.sales.view',
];

$performanceFiRows = [
    'dashboard.performance_stats.targets.fi.view',
    'dashboard.performance_stats.actuals.fi.view',
    'dashboard.performance_stats.targets_vs_actuals.fi.view',
];

$performanceManagerRows = [
    'dashboard.performance_stats.targets.manager.view',
    'dashboard.performance_stats.actuals.manager.view',
    'dashboard.performance_stats.targets_vs_actuals.manager.view',
];

$performanceConsolidatedRows = [
    'dashboard.performance_stats.targets.consolidated.view',
    'dashboard.performance_stats.actuals.consolidated.view',
    'dashboard.performance_stats.targets_vs_actuals.consolidated.view',
];

$performanceCommissionRows = [
    'dashboard.performance_stats.commission.current_month.view',
    'dashboard.performance_stats.commission.historic.view',
];

$performanceFinancialManager = $merge(
    $performanceSalesRows,
    $performanceFiRows,
    $performanceManagerRows,
    $performanceConsolidatedRows,
    $performanceCommissionRows
);

$performanceSalesman = $merge(
    $performanceSalesRows,
    $performanceCommissionRows
);

$performanceFi = $merge(
    $performanceFiRows,
    $performanceCommissionRows
);

$performanceBuyer = $performanceCommissionRows;
$performanceMarketing = $performanceCommissionRows;
$performanceStockController = $performanceCommissionRows;

$leaderBoardRows = [
    'dashboard.leader_board.individual.view',
    'dashboard.leader_board.combined.view',
];

$reportsSalesRows = [
    'dashboard.reports.sales.stock.view',
    'dashboard.reports.sales.gp.view',
    'dashboard.reports.sales.licence_registration.view',
    'dashboard.reports.sales.comebacks_aftersales.view',
];

$reportsFiRows = [
    'dashboard.reports.fi.second_gp.view',
    'dashboard.reports.fi.vaps_penetration.view',
    'dashboard.reports.fi.rand_per_1000_per_bank.view',
    'dashboard.reports.fi.applications_per_day.view',
    'dashboard.reports.fi.approved_vs_declined_ratio.view',
    'dashboard.reports.fi.approved_non_taken_up_follow_up.view',
];

$reportsMarketingRows = [
    'dashboard.reports.marketing.actual_vs_budget_spend.view',
    'dashboard.reports.marketing.lead_source_report_from_all_platforms.view',
];

$reportsFmRows = [
    'dashboard.reports.fm.financial.view',
    'dashboard.reports.fm.expenses.view',
    'dashboard.reports.fm.hr_payroll.view',
    'dashboard.reports.fm.contracts.view',
];

$reportsBuyerRows = [
    'dashboard.reports.buyer.forecast_vs_actual.view',
    'dashboard.reports.buyer.units_mtd.view',
    'dashboard.reports.buyer.average_valuation_variance.view',
    'dashboard.reports.buyer.appoints_due_screen.view',
    'dashboard.reports.buyer.tasks_inspections.view',
];

$reportsReconRows = [
    'dashboard.reports.recon.recon_workflow.view',
    'dashboard.reports.recon.supplier_orders.view',
    'dashboard.reports.recon.parts_requested.view',
    'dashboard.reports.recon.stock_takes.view',
    'dashboard.reports.recon.job_cards.view',
    'dashboard.reports.recon.vehicle_overdue_in_recon_process_auto_reminder.view',
    'dashboard.reports.recon.status_new_in_progress_done.view',
];

$reportsFull = $merge(
    $reportsSalesRows,
    $reportsFiRows,
    $reportsMarketingRows,
    $reportsFmRows,
    $reportsBuyerRows,
    $reportsReconRows
);

$reportsBuyer = $reportsBuyerRows;
$reportsFi = $merge($reportsSalesRows, $reportsFiRows, ['dashboard.reports.buyer.appoints_due_screen.view']);
$reportsSalesman = $merge($reportsSalesRows, ['dashboard.reports.fi.approved_non_taken_up_follow_up.view', 'dashboard.reports.buyer.appoints_due_screen.view', 'dashboard.reports.recon.vehicle_overdue_in_recon_process_auto_reminder.view']);
$reportsDriver = [
    'dashboard.reports.recon.recon_workflow.view',
    'dashboard.reports.recon.vehicle_overdue_in_recon_process_auto_reminder.view',
    'dashboard.reports.recon.status_new_in_progress_done.view',
];
$reportsCleaner = [];
$reportsMarketing = $merge($reportsMarketingRows, ['dashboard.reports.recon.vehicle_overdue_in_recon_process_auto_reminder.view']);
$reportsFinancialManager = $reportsFull;
$reportsStockController = $merge($reportsBuyerRows, $reportsReconRows);
$reportsReceptionist = [
    'dashboard.reports.recon.recon_workflow.view',
    'dashboard.reports.recon.supplier_orders.view',
    'dashboard.reports.recon.parts_requested.view',
    'dashboard.reports.recon.job_cards.view',
    'dashboard.reports.recon.status_new_in_progress_done.view',
];

$suppliersCompanyOrders = [
    'dashboard.suppliers.company_suppliers.vehicle_order.view',
    'dashboard.suppliers.company_suppliers.expense_order.view',
];

$suppliersContactLists = [
    'dashboard.suppliers.new_vehicle_suppliers.list_with_contact_info.view',
    'dashboard.suppliers.used_trade_cover_suppliers.list_with_contact_info.view',
];

$licRegVehicleSold = [
    'dashboard.lic_reg.vehicle_sold.request_registration_licence.view',
    'dashboard.lic_reg.vehicle_sold.third_party_supplier_to_be_used.view',
    'dashboard.lic_reg.vehicle_sold.number_plates_required.view',
    'dashboard.lic_reg.vehicle_sold.upload_copy_when_complete.view',
    'dashboard.lic_reg.vehicle_sold.create_task_assign.view',
];

$licRegVehiclePurchaseCommon = [
    'dashboard.lic_reg.vehicle_purchase.original_natis.view',
];

$licRegVehiclePurchaseStockControllerOnly = [
    'dashboard.lic_reg.vehicle_purchase.settlement_bank_to_send_natis.view',
    'dashboard.lic_reg.vehicle_purchase.create_task_assign.view',
    'dashboard.lic_reg.vehicle_purchase.upload_copy_when_complete.view',
];

$licRegBuyerFiSalesmanFinancialManager = $merge(
    $licRegVehiclePurchaseCommon,
    $licRegVehiclePurchaseStockControllerOnly
);

$licRegReceptionist = $merge(
    $licRegVehicleSold,
    $licRegVehiclePurchaseCommon
);

$affiliateRows = [
    'dashboard.affiliate_program.external.unique_link_per_spotter.view',
    'dashboard.affiliate_program.external.earnings_dashboard.view',
    'dashboard.affiliate_program.external.mega_theron_marketing.view',
    'dashboard.affiliate_program.internal.list_of_affiliates.view',
    'dashboard.affiliate_program.internal.load_new_affiliate.view',
    'dashboard.affiliate_program.internal.tracker.view',
];

$marketingToolsRows = [
    'dashboard.marketing.tools.create_campaigns.view',
    'dashboard.marketing.tools.whatsapp_broadcasts.view',
    'dashboard.marketing.tools.bulk_email.view',
    'dashboard.marketing.tools.templates.view',
];

$marketingBotsCommon = [
    'dashboard.marketing.whatsapp_bots.auto_reply.view',
    'dashboard.marketing.whatsapp_bots.lead_ingestion.view',
    'dashboard.marketing.whatsapp_bots.stock_search_via_whatsapp.view',
];

$marketingCollectDocs = [
    'dashboard.marketing.whatsapp_bots.collect_store_customer_documents.view',
];

$marketingPhysicalChecklist = [
    'dashboard.marketing.physical_marketing_equipment.checklist_and_inspection.view',
];

$marketingFinancialManagerRows = $merge(
    $marketingToolsRows,
    $marketingBotsCommon,
    $marketingCollectDocs,
    $marketingPhysicalChecklist
);

$marketingRoleRows = $marketingFinancialManagerRows;
$salesmanMarketingRows = $merge($marketingCollectDocs, $marketingPhysicalChecklist);
$fiMarketingRows = $marketingCollectDocs;
$driverMarketingRows = $marketingPhysicalChecklist;
$cleanerMarketingRows = $marketingPhysicalChecklist;
$receptionistMarketingRows = $marketingPhysicalChecklist;

$reconNewVehiclesAddedToQue = 'dashboard.recon.dashboard.new_vehicles_added_to_que.view';
$reconProgressOfVehicles = 'dashboard.recon.dashboard.progress_of_vehicles_in_recon.view';
$reconReportPerLocation = 'dashboard.recon.dashboard.report_for_per_location.view';
$reconReadyForFloor = 'dashboard.recon.dashboard.ready_for_floor.view';
$reconTrackingUnitFitted = 'dashboard.recon.dashboard.tracking_unit_fitted.view';
$reconVehicleCheckIn = 'dashboard.recon.dashboard.vehicle_check_in.view';
$reconOpenOrders = 'dashboard.recon.dashboard.open_orders_linked_from_approved_supplier_list.view';
$reconDashboardSummary = 'dashboard.recon.dashboard.view';

$buyerReconDashboardRows = [
    $reconDashboardSummary,
    $reconNewVehiclesAddedToQue,
    $reconProgressOfVehicles,
    $reconReportPerLocation,
    $reconReadyForFloor,
    $reconTrackingUnitFitted,
    $reconVehicleCheckIn,
];

$salesmanReconDashboardRows = [
    $reconDashboardSummary,
    $reconReadyForFloor,
];

$driverReconDashboardRows = [
    $reconDashboardSummary,
    $reconNewVehiclesAddedToQue,
    $reconReadyForFloor,
];

$marketingReconDashboardRows = [
    $reconDashboardSummary,
    $reconReadyForFloor,
];

$financialManagerReconDashboardRows = [
    $reconDashboardSummary,
    $reconNewVehiclesAddedToQue,
    $reconProgressOfVehicles,
    $reconReportPerLocation,
    $reconReadyForFloor,
    $reconTrackingUnitFitted,
    $reconVehicleCheckIn,
    $reconOpenOrders,
];

$stockControllerReconDashboardRows = $financialManagerReconDashboardRows;

$receptionistReconDashboardRows = [
    $reconDashboardSummary,
    $reconNewVehiclesAddedToQue,
    $reconOpenOrders,
];

$biFunnelReporting = 'dashboard.business_intelligence.funnel_reporting.view';
$biDealerComparisons = 'dashboard.business_intelligence.dealer_comparisons.view';
$biReconAnalytics = 'dashboard.business_intelligence.recon_analytics.view';
$biSalesOverview = 'dashboard.business_intelligence.sales_overview.view';
$biFinancialOverview = 'dashboard.business_intelligence.financial_overview.view';
$biFiOverview = 'dashboard.business_intelligence.fi_overview.view';
$biReconOverview = 'dashboard.business_intelligence.recon_overview.view';
$biMonthEndPacks = 'dashboard.business_intelligence.month_end_packs.view';

$biFinancialManagerRows = [
    $biFunnelReporting,
    $biDealerComparisons,
    $biReconAnalytics,
    $biSalesOverview,
    $biFinancialOverview,
    $biFiOverview,
    $biReconOverview,
    $biMonthEndPacks,
];

$biStockControllerRows = [
    $biDealerComparisons,
    $biReconOverview,
];

$biFiRows = [
    $biFiOverview,
    $biMonthEndPacks,
];

$biBuyerRows = [
    $biMonthEndPacks,
];

$biMarketingRows = [
    $biMonthEndPacks,
];

$externalCustomersSetup = 'dashboard.external_customers.system_to_be_used_by_other_dealership.set_up_per_module_department.view';

$managingDirectorPermissions = $merge(
    [$landingPermission],
    $allPermissions,
    $companyAll,
    $settingsDealersPermissions,
    $settingsUsersPermissions,
    $settingsDepartmentsPermissions,
    $settingsBrandingPermissions
);

return [
    'System Admin' => array_values(array_unique(array_merge(
        [$landingPermission],
        $allPermissions,
        $settingsDealersPermissions,
        $settingsUsersPermissions,
        $settingsDepartmentsPermissions,
        $settingsBrandingPermissions
    ))),
    'Managing Director' => $managingDirectorPermissions,
    'Dealer Administration' => $managingDirectorPermissions,
    'Branch Manager' => array_values(array_unique(array_merge(
        [$landingPermission],
        $exclude($allDashboardPermissions, ['dashboard.settings.view', $externalCustomersSetup, 'settings.dealers.view']),
        $companyAll
    ))),
    'Buyer' => $merge([
        'dashboard.index.view',
        'dashboard.crm_leads.view',
        'dashboard.stock.view',
        'dashboard.performance_stats.view',
        'dashboard.valuations.view',
        'dashboard.leader_board.view',
        'dashboard.lic_reg.view',
        'dashboard.suppliers.view',
        'dashboard.reports.view',
        'dashboard.recon.view',
        'dashboard.business_intelligence.view',
    ], $buyerCompany, $buyerStock, $crmBuyer, $valuationsCommon, $performanceBuyer, $leaderBoardRows, $reportsBuyer, $suppliersCompanyOrders, $suppliersContactLists, $licRegBuyerFiSalesmanFinancialManager, $buyerReconDashboardRows, $biBuyerRows),
    'F&I' => $merge([
        'dashboard.index.view',
        'dashboard.performance_stats.view',
        'dashboard.valuations.view',
        'dashboard.crm_leads.view',
        'dashboard.leader_board.view',
        'dashboard.marketing.view',
        'dashboard.suppliers.view',
        'dashboard.lic_reg.view',
        'dashboard.reports.view',
        'dashboard.business_intelligence.view',
        // Department dashboard
        'dashboard.fi_department.view',
    ], $fiCompany, $fiStock, $crmFull, $valuationsCommon, $performanceFi, $leaderBoardRows, $reportsFi, $suppliersCompanyOrders, $licRegVehicleSold, $licRegBuyerFiSalesmanFinancialManager, $fiMarketingRows, $biFiRows),
    'Salesman' => $merge([
        'dashboard.index.view',
        'dashboard.valuations.view',
        'dashboard.crm_leads.view',
        'dashboard.duties_tasks.view',
        'dashboard.stock.view',
        'dashboard.leader_board.view',
        'dashboard.performance_stats.view',
        'dashboard.marketing.view',
        'dashboard.lic_reg.view',
        'dashboard.suppliers.view',
        'dashboard.reports.view',
        'dashboard.recon.view',
    ], $salesmanCompany, $salesmanStock, $crmFull, $valuationsCommon, $performanceSalesman, $leaderBoardRows, $reportsSalesman, $suppliersCompanyOrders, $suppliersContactLists, $licRegVehicleSold, $licRegBuyerFiSalesmanFinancialManager, $salesmanMarketingRows, $salesmanReconDashboardRows),
    'Marketing' => $merge([
        'dashboard.index.view',
        'dashboard.leader_board.view',
        'dashboard.marketing.view',
        'dashboard.business_intelligence.view',
        'dashboard.performance_stats.view',
        'dashboard.suppliers.view',
        'dashboard.reports.view',
        'dashboard.recon.view',
    ], $marketingCompany, $marketingStock, $performanceMarketing, $leaderBoardRows, $reportsMarketing, $suppliersCompanyOrders, $marketingRoleRows, $marketingReconDashboardRows, $biMarketingRows),
    'Financial Manager' => $merge([
        'dashboard.index.view',
        'dashboard.valuations.view',
        'dashboard.crm_leads.view',
        'dashboard.leader_board.view',
        'dashboard.performance_stats.view',
        'dashboard.lic_reg.view',
        'dashboard.affiliate_program.view',
        'dashboard.suppliers.view',
        'dashboard.reports.view',
        'dashboard.recon.view',
        'dashboard.business_intelligence.view',
        'dashboard.backend_access.view',
        // Department dashboard
        'dashboard.financial.view',
    ], $companyAll, $financialManagerStock, $crmFull, $valuationsCommon, $performanceFinancialManager, $leaderBoardRows, $reportsFinancialManager, $suppliersCompanyOrders, $suppliersContactLists, $licRegVehicleSold, $licRegBuyerFiSalesmanFinancialManager, $affiliateRows, $marketingFinancialManagerRows, $financialManagerReconDashboardRows, $biFinancialManagerRows),
    'Stock Controller' => $merge([
        'dashboard.index.view',
        'dashboard.crm_leads.view',
        'dashboard.stock.view',
        'dashboard.valuations.view',
        'dashboard.leader_board.view',
        'dashboard.performance_stats.view',
        'dashboard.recon.view',
        'dashboard.suppliers.view',
        'dashboard.lic_reg.view',
        'dashboard.reports.view',
        'dashboard.business_intelligence.view',
    ], $stockControllerCompany, $stockControllerStock, $crmStockController, $valuationsStockController, $performanceStockController, $leaderBoardRows, $reportsStockController, $suppliersCompanyOrders, $suppliersContactLists, $licRegVehiclePurchaseStockControllerOnly, $stockControllerReconDashboardRows, $biStockControllerRows),
    'Receptionist' => $merge([
        'dashboard.index.view',
        'dashboard.lic_reg.view',
        'dashboard.marketing.view',
        'dashboard.duties_tasks.view',
        'dashboard.suppliers.view',
        'dashboard.reports.view',
        'dashboard.recon.view',
    ], $receptionistCompany, $receptionistStock, $reportsReceptionist, $suppliersCompanyOrders, $licRegReceptionist, $receptionistMarketingRows, $receptionistReconDashboardRows),
    'Driver' => $merge([
        'dashboard.index.view',
        'dashboard.duties_tasks.view',
        'dashboard.stock.view',
        'dashboard.marketing.view',
        'dashboard.suppliers.view',
        'dashboard.reports.view',
        'dashboard.recon.view',
    ], $driverCleanerCompany, $driverStock, $reportsDriver, $suppliersCompanyOrders, $driverMarketingRows, $driverReconDashboardRows),
    'Cleaner' => $merge([
        'dashboard.index.view',
        'dashboard.marketing.view',
        'dashboard.duties_tasks.view',
        'dashboard.suppliers.view',
    ], $driverCleanerCompany, $cleanerStock, $reportsCleaner, $suppliersCompanyOrders, $cleanerMarketingRows),
];
