Watch
1
0
Fork
You've already forked arc
0
forked from hesabix/arc
arc/hesabixUI/hesabix_ui/lib/pages/business/business_shell.dart
Babak Alizadeh 1c582e9fd7 fix(office-automation): expand sidebar group so OA submenus open
Track expandable menus by item key instead of a hardcoded label list so Office Automation and other groups toggle correctly.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-02 16:51:35 +03:30

4141 lines
154 KiB
Dart
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import '../../core/auth_store.dart';
import '../../core/business_nav.dart';
import '../../core/business_route_paths.dart';
import '../../core/business_panel_ui_store.dart';
import '../../core/locale_controller.dart';
import '../../core/calendar_controller.dart';
import '../../core/mobile_launcher_nav.dart';
import '../../theme/theme_controller.dart';
import '../../widgets/combined_user_menu_button.dart';
import '../../widgets/fx/daily_fx_rates_toolbar_chip.dart';
import '../../models/person_model.dart';
import '../../widgets/person/person_form_dialog.dart';
import '../../widgets/banking/bank_account_form_dialog.dart';
import '../../widgets/banking/cash_register_form_dialog.dart';
import '../../widgets/banking/petty_cash_form_dialog.dart';
import '../../widgets/product/product_form_dialog.dart';
import '../../widgets/category/category_tree_dialog.dart';
import '../../services/business_dashboard_service.dart';
import '../../services/marketplace_service.dart';
import '../../widgets/marketplace/plugin_marketplace_utils.dart';
import '../../core/api_client.dart';
import '../../core/fiscal_year_controller.dart';
import 'package:hesabix_ui/config/brand_config.dart';
import 'package:hesabix_ui/l10n/app_localizations.dart';
import '../../theme/brand_logo.dart';
import 'receipts_payments_list_page.dart' show BulkSettlementDialog;
import '../../widgets/document/document_form_dialog.dart';
import '../../widgets/wallet/wallet_top_up_dialog.dart';
import '../../widgets/notification_bell_button.dart';
import '../../widgets/transfer/transfer_form_dialog.dart';
import '../../widgets/expense_income/expense_income_form_dialog.dart';
import '../../widgets/warehouse/warehouse_form_dialog.dart';
import '../../widgets/warehouse/warehouse_doc_wizard_dialog.dart';
import '../../widgets/warehouse/warehouse_document_form_dialog.dart';
import '../../services/invoice_service.dart';
import '../../services/warehouse_service.dart';
import '../../utils/warehouse_invoice_lines.dart';
import '../../services/business_menu_preferences_service.dart';
import '../../widgets/ai/ai_chat_dialog.dart';
import '../../widgets/ai/ai_quick_start.dart';
import '../../widgets/calculator/calculator_dialog.dart';
import '../../widgets/business/business_shell_glyphs.dart';
import '../../widgets/telephony/telephony_phone_bar.dart';
import '../../widgets/telephony/telephony_incoming_call_overlay.dart';
import '../../core/date_utils.dart';
import '../../utils/error_extractor.dart';
import '../../utils/responsive_helper.dart';
import '../../theme/tokens/extensions.dart';
import '../../utils/snackbar_helper.dart';
import 'check_form_page.dart';
import 'bank_accounts_page.dart';
import 'persons_page.dart';
import 'cash_registers_page.dart';
import 'petty_cash_page.dart';
import 'checks_page.dart';
import 'invoices_list_page.dart';
import 'receipts_payments_list_page.dart';
import 'expense_income_list_page.dart';
import 'transfers_page.dart';
import 'documents_page.dart';
import 'loan_facilities_page.dart';
import 'business_shell_side_nav_scope.dart';
class BusinessShell extends StatefulWidget {
final int businessId;
final Widget child;
final AuthStore authStore;
final LocaleController? localeController;
final CalendarController? calendarController;
final ThemeController? themeController;
const BusinessShell({
super.key,
required this.businessId,
required this.child,
required this.authStore,
this.localeController,
this.calendarController,
this.themeController,
});
@override
State<BusinessShell> createState() => _BusinessShellState();
}
class _BusinessShellState extends State<BusinessShell> {
/// ارتفاع نوار ابزار آبی (لوگو، اکشن‌ها) — فشرده‌تر از [kToolbarHeight] پیش‌فرض.
static const double _kBizAppBarToolbarHeight = 44;
/// نوار دوم: تب‌ها / نام کسب‌وکار و زمان — کمی فشرده‌تر از قبل.
static const double _kUnifiedBizTabBarHeight = 44;
static const double _kBizTabStripVerticalPadding = 6;
/// ارتفاع ثابت بدنهٔ هر تب داخل نوار (نوار − پدینگ عمودی).
static const double _kBizTabChipInnerHeight =
_kUnifiedBizTabBarHeight - (_kBizTabStripVerticalPadding * 2);
static const double _kBizTabMinWidth = 100;
static const double _kBizTabMaxWidth = 188;
int _hoverIndex = -1;
final Map<String, bool> _expandedMenuByKey = {};
final BusinessDashboardService _businessService = BusinessDashboardService(ApiClient());
final MarketplaceService _marketplaceService = MarketplaceService();
List<Map<String, dynamic>> _businessPlugins = [];
bool _pluginsLoaded = false;
int? _pluginsLoadedForBusinessId;
String? _lastRouteLocation;
int _lastPluginsRefreshNonce = 0;
bool _isBusinessLoading = false;
String? _businessLoadError;
Timer? _dateTimeUpdateTimer;
final BusinessMenuPreferencesService _menuPreferencesService =
BusinessMenuPreferencesService(ApiClient());
BusinessMenuPreferencesDto _menuPreferences = BusinessMenuPreferencesDto.empty();
/// فقط زمانی که `NavigationRail`/ریل کناری برای دسکتاپ نشان داده می‌شود؛ موبایل از drawer استفاده می‌کند.
bool _desktopRailVisible = true;
void _onBusinessPanelUiChanged() {
if (!mounted) return;
final nonce = BusinessPanelUiStore.instance.pluginsRefreshNonce;
if (nonce != _lastPluginsRefreshNonce) {
_lastPluginsRefreshNonce = nonce;
_loadBusinessPlugins(force: true);
}
setState(() {});
}
String _bu(String rel) => context.businessPanelUrl(widget.businessId, rel);
/// در دسکتاپ + حالت «تب»: بر اساس [reuseAcrossTabs]؛ در موبایل/تک‌صفحه همان مسیر [_bu].
Future<void> _navigateMenuPath(
BuildContext ctx,
String menuUrl, {
required bool desktopRail,
required bool reuseAcrossTabs,
}) async {
await BusinessPanelUiStore.instance.hydrateIfNeeded();
if (!ctx.mounted) return;
BusinessPanelUiStore.instance.navigateSidebarFromMenuUrl(
businessId: widget.businessId,
menuUrl: menuUrl,
go: (loc) => ctx.go(loc),
fallbackOnly: !desktopRail,
reuseAcrossTabs: reuseAcrossTabs,
);
}
bool _reuseAcrossTabsForSidebarGesture({required bool longPress}) {
final store = BusinessPanelUiStore.instance;
if (store.mode != BusinessPanelNavigationMode.tabs) return true;
if (store.sidebarTabBehavior != BusinessPanelSidebarTabBehavior.newTabViaLongPress) {
return true;
}
return longPress;
}
/// عنوان نمایشی تب؛ برای مسیرهای خارج از درخت منو از [t] و [_fallbackTabTitleForRouteTail] استفاده می‌شود.
String _tabTitleForBusinessPath(
String path,
int businessId,
List<_MenuItem> menuRoot,
AppLocalizations t,
) {
final pathNorm = path.split('?').first;
final pathTail = BusinessRoutePaths.stripBusinessPrefixAndTab(pathNorm, businessId);
final pathTailBase = pathTail.split('?').first;
var best = '';
var bestLen = 0;
void walk(List<_MenuItem> items) {
for (final item in items) {
final p = item.path;
if (p == null) continue;
final menuNorm = p.split('?').first;
final menuTail = BusinessRoutePaths.stripBusinessPrefixAndTab(menuNorm, businessId);
final menuTailBase = menuTail.split('?').first;
if (menuTailBase.isEmpty) continue;
final nested = pathTailBase.startsWith('$menuTailBase/');
if (pathTailBase != menuTailBase && !nested) continue;
if (menuTailBase.length >= bestLen) {
bestLen = menuTailBase.length;
best = item.label;
}
final ch = item.children;
if (ch != null) walk(ch);
}
}
walk(menuRoot);
if (best.isNotEmpty) return best;
final localizedTail = _fallbackTabTitleForRouteTail(pathTailBase, t);
if (localizedTail != null) return localizedTail;
try {
if (pathTailBase.isNotEmpty) return pathTailBase.replaceAll('/', ' / ');
} catch (_) {}
return path;
}
/// مسیرهایی که در [allMenuItems] نیستند یا پیشوند «repair-shop» ندارند (تیره به‌جای /).
String? _fallbackTabTitleForRouteTail(String pathTailBase, AppLocalizations t) {
switch (pathTailBase) {
case 'users-permissions':
return t.usersAndPermissions;
case 'price-lists':
return t.priceLists;
case 'projects':
return t.businessPanelTabRouteProjects;
case 'installments-report':
return t.installmentsReportTitle;
case 'document-monetization':
return t.documentMonetizationTitle;
case 'repair-shop-technicians':
return t.businessPanelTabRouteRepairTechnicians;
case 'repair-shop-settings':
return t.businessPanelTabRouteRepairShopSettings;
case 'payroll':
return t.payrollMenu;
case 'office-automation':
return t.oaCartable;
case 'office-automation/org':
return t.oaOrg;
case 'office-automation/external-orgs':
return t.oaExternalOrgs;
case 'office-automation/archive':
return t.oaArchiveTree;
case 'office-automation/reports':
return t.oaReports;
case 'settings/office-automation':
return t.oaSettings;
case 'fixed-assets':
return t.fixedAssetsMenu;
case 'settings/fixed-assets':
return t.fixedAssetsSettingsPageTitle;
case 'telephony':
return t.telephonyMenu;
case 'telephony/calls':
return t.telephonyCallHistoryShort;
case 'telephony/live':
return t.telephonyLiveDashboardTitle;
case 'telephony/reports':
return t.telephonyReportsTitle;
case 'telephony/softphone':
return t.telephonySoftphoneTitle;
case 'settings/telephony':
return t.telephonySettingsTitle;
case 'digipay':
return t.digipayMenuTitle;
case 'settings/digipay':
return t.settingsDigipayTitle;
case 'distribution':
return t.distributionMenu;
case 'hscript':
return 'گزارش‌ساز اسکریپتی';
default:
break;
}
if (pathTailBase.startsWith('telephony/')) {
return t.telephonyMenu;
}
if (pathTailBase.startsWith('payroll/')) {
return t.payrollMenu;
}
if (pathTailBase.startsWith('office-automation')) {
return t.oaMenu;
}
if (pathTailBase.startsWith('hscript')) {
return 'گزارش‌ساز اسکریپتی';
}
if (RegExp(r'^price-lists/\d+/items$').hasMatch(pathTailBase)) {
return t.businessPanelTabRoutePriceListItems;
}
return null;
}
/// تطبیق مسیر منو با [location] بر اساس بخش منطقی مسیر (بدون توجه به شمارهٔ تب).
bool _businessMenuPathMatchesLocation(String location, String menuPath, int businessId) {
final locTail =
BusinessRoutePaths.stripBusinessPrefixAndTab(location.split('?').first, businessId).split('?').first;
final menuTail =
BusinessRoutePaths.stripBusinessPrefixAndTab(menuPath.split('?').first, businessId).split('?').first;
if (menuTail.isEmpty) return false;
return locTail == menuTail || locTail.startsWith('$menuTail/');
}
Future<bool> _confirmClosePinnedTab(BuildContext context) async {
final t = AppLocalizations.of(context)!;
final result = await showDialog<bool>(
context: context,
builder: (ctx) {
final cs = Theme.of(ctx).colorScheme;
return AlertDialog(
icon: Icon(Icons.push_pin_rounded, color: cs.primary),
title: Text(t.businessPanelTabPinnedCloseTitle),
content: Text(t.businessPanelTabPinnedCloseMessage),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: Text(t.cancel),
),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: cs.error,
foregroundColor: cs.onError,
),
onPressed: () => Navigator.pop(ctx, true),
child: Text(t.businessPanelTabPinnedCloseConfirm),
),
],
);
},
);
return result == true;
}
void _showPinnedKeptSnackBar(BuildContext context, int count) {
if (count <= 0 || !context.mounted) return;
final t = AppLocalizations.of(context)!;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(t.businessPanelTabPinnedKeptSnackbar(count))),
);
}
Future<void> _requestCloseTab(
BuildContext context,
String path,
void Function(String location) go,
) async {
final store = BusinessPanelUiStore.instance;
final bid = widget.businessId;
if (store.isTabPinned(bid, path)) {
final ok = await _confirmClosePinnedTab(context);
if (!ok || !context.mounted) return;
store.closeTab(bid, path, go, force: true);
return;
}
store.closeTab(bid, path, go);
}
Future<void> _showDesktopTabActionDialog(
BuildContext context,
List<_MenuItem> menuRoot,
BusinessPanelTabSession session,
String path,
) async {
final store = BusinessPanelUiStore.instance;
final bid = widget.businessId;
void go(String loc) => context.go(loc);
final pinned = session.isPathPinned(path);
await showDialog<void>(
context: context,
builder: (ctx) {
final t = AppLocalizations.of(ctx)!;
return AlertDialog(
title: Text(
_tabTitleForBusinessPath(path, bid, menuRoot, t),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ListTile(
leading: Icon(pinned ? Icons.push_pin_rounded : Icons.push_pin_outlined),
title: Text(pinned ? t.businessPanelTabUnpin : t.businessPanelTabPin),
onTap: () {
Navigator.pop(ctx);
store.toggleTabPinned(bid, path);
},
),
ListTile(
leading: const Icon(Icons.close),
title: Text(t.businessPanelTabCloseThisTab),
onTap: () async {
Navigator.pop(ctx);
if (!context.mounted) return;
await _requestCloseTab(context, path, go);
},
),
ListTile(
leading: const Icon(Icons.arrow_forward),
title: Text(t.businessPanelTabCloseTabsToTheRight),
onTap: () {
Navigator.pop(ctx);
final kept = store.closeTabsToTheRightOf(bid, path, go);
if (context.mounted) _showPinnedKeptSnackBar(context, kept);
},
),
ListTile(
leading: const Icon(Icons.arrow_back),
title: Text(t.businessPanelTabCloseTabsToTheLeft),
onTap: () {
Navigator.pop(ctx);
final kept = store.closeTabsToTheLeftOf(bid, path, go);
if (context.mounted) _showPinnedKeptSnackBar(context, kept);
},
),
],
),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx), child: Text(t.cancel)),
],
);
},
);
}
Future<void> _showAllTabsManagementDialog(BuildContext context, List<_MenuItem> menuRoot) async {
final store = BusinessPanelUiStore.instance;
final bid = widget.businessId;
void go(String loc) => context.go(loc);
if (store.tabsForBusiness(bid) == null) return;
await showDialog<void>(
context: context,
builder: (ctx) {
return ListenableBuilder(
listenable: store,
builder: (ctx, _) {
final t = AppLocalizations.of(ctx)!;
final session = store.tabsForBusiness(bid);
if (session == null || session.paths.isEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (Navigator.of(ctx).canPop()) Navigator.pop(ctx);
});
return const SizedBox.shrink();
}
return AlertDialog(
title: Text(t.businessPanelTabAllTabsTitle),
content: SizedBox(
width: double.maxFinite,
child: ListView.builder(
shrinkWrap: true,
itemCount: session.paths.length,
itemBuilder: (_, i) {
final p = session.paths[i];
final title = _tabTitleForBusinessPath(p, bid, menuRoot, t);
final sel = p == session.activePath;
final isPinned = session.isPinnedAt(i);
return ListTile(
dense: true,
selected: sel,
leading: Icon(
isPinned ? Icons.push_pin_rounded : Icons.push_pin_outlined,
size: 18,
color: isPinned
? Theme.of(ctx).colorScheme.primary
: Theme.of(ctx).colorScheme.onSurfaceVariant,
),
title: Text(title, maxLines: 2, overflow: TextOverflow.ellipsis),
onTap: () {
Navigator.pop(ctx);
store.selectTab(bid, p, go);
},
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
tooltip: isPinned ? t.businessPanelTabUnpin : t.businessPanelTabPin,
icon: Icon(
isPinned ? Icons.push_pin_rounded : Icons.push_pin_outlined,
size: 20,
),
onPressed: () => store.toggleTabPinned(bid, p),
),
IconButton(
tooltip: isPinned
? t.businessPanelTabClosePinnedTooltip
: MaterialLocalizations.of(ctx).closeButtonTooltip,
icon: const Icon(Icons.close, size: 20),
onPressed: () async {
if (isPinned) {
final ok = await _confirmClosePinnedTab(ctx);
if (!ok || !ctx.mounted) return;
store.closeTab(bid, p, go, force: true);
} else {
store.closeTab(bid, p, go);
}
},
),
],
),
);
},
),
),
actions: [
TextButton(
onPressed: () {
final kept = store.closeAllTabs(bid, go);
Navigator.pop(ctx);
if (context.mounted) _showPinnedKeptSnackBar(context, kept);
},
child: Text(t.businessPanelTabCloseAllTabs),
),
TextButton(onPressed: () => Navigator.pop(ctx), child: Text(t.close)),
],
);
},
);
},
);
}
Widget _buildDesktopTabChip(
BuildContext context,
List<_MenuItem> menuRoot,
BusinessPanelTabSession session,
String path,
) {
final store = BusinessPanelUiStore.instance;
final bid = widget.businessId;
final active = path == session.activePath;
final pinned = session.isPathPinned(path);
final t = AppLocalizations.of(context)!;
final label = _tabTitleForBusinessPath(path, bid, menuRoot, t);
void goLoc(String loc) => context.go(loc);
final cs = Theme.of(context).colorScheme;
final bool isDarkStrip = Theme.of(context).brightness == Brightness.dark;
final chipFg = active ? cs.onSurface : cs.onSurfaceVariant.withValues(alpha: 0.92);
final chipFgStrong = active ? cs.onSurface : cs.onSurfaceVariant;
final chipClose = chipFg.withValues(alpha: active ? 0.72 : 0.62);
final chipPin = pinned
? cs.primary.withValues(alpha: active ? 0.95 : 0.82)
: cs.outline.withValues(alpha: 0.55);
final BorderRadius chipRadius = BorderRadius.circular(11);
final Color chipBg = active
? Color.alphaBlend(
cs.primary.withValues(alpha: isDarkStrip ? 0.26 : 0.13),
cs.surface,
)
: cs.surfaceContainerHighest.withValues(alpha: isDarkStrip ? 0.52 : 0.72);
final Color chipBorder = active
? cs.primary.withValues(alpha: isDarkStrip ? 0.72 : 0.52)
: pinned
? cs.primary.withValues(alpha: isDarkStrip ? 0.42 : 0.28)
: cs.outline.withValues(alpha: isDarkStrip ? 0.38 : 0.22);
return Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: _kBizTabMinWidth, maxWidth: _kBizTabMaxWidth),
child: Material(
elevation: active ? (isDarkStrip ? 5 : 4) : (pinned ? 1 : 0),
shadowColor: cs.shadow.withValues(alpha: active ? (isDarkStrip ? 0.45 : 0.28) : 0.12),
color: chipBg,
shape: RoundedRectangleBorder(
borderRadius: chipRadius,
side: BorderSide(color: chipBorder, width: active ? 1.5 : 1),
),
clipBehavior: Clip.antiAlias,
child: InkWell(
borderRadius: chipRadius,
hoverColor: cs.primary.withValues(alpha: isDarkStrip ? 0.09 : 0.06),
splashColor: cs.primary.withValues(alpha: 0.10),
onTap: () => store.selectTab(bid, path, goLoc),
onLongPress: () => _showDesktopTabActionDialog(context, menuRoot, session, path),
child: SizedBox(
height: _kBizTabChipInnerHeight,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 12, end: 4),
child: Row(
children: [
if (pinned)
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Transform.rotate(
angle: -0.6,
child: Icon(Icons.push_pin_rounded, size: 13, color: chipPin),
),
)
else
Container(
width: 5,
height: 5,
margin: const EdgeInsetsDirectional.only(end: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: active ? cs.primary : cs.outline.withValues(alpha: 0.55),
),
),
Expanded(
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
fontSize: 12.5,
height: 1.15,
letterSpacing: active ? 0.15 : 0.02,
fontWeight: active ? FontWeight.w700 : FontWeight.w500,
color: active ? chipFgStrong : chipFg,
),
),
),
SizedBox(
width: 28,
height: 28,
child: IconButton(
visualDensity: VisualDensity.compact,
padding: EdgeInsets.zero,
tooltip: pinned
? t.businessPanelTabClosePinnedTooltip
: MaterialLocalizations.of(context).closeButtonTooltip,
icon: Icon(
Icons.close_rounded,
size: 16.5,
color: pinned ? cs.primary.withValues(alpha: 0.75) : chipClose,
),
onPressed: () => _requestCloseTab(context, path, goLoc),
),
),
],
),
),
),
),
),
),
);
}
/// یک خط: نام کسب‌وکار + آیکون • تب‌ها (کنار نام، با اسکرول) • زمان • منوی تب‌ها
///
/// [menuRoot] باید **منوی کامل** ([allMenuItems]) باشد نه [menuItems] فیلترشده،
/// تا عنوان تب‌ها از همان برچسب‌های محلی منو به‌دست آید (و به `products` خام نیفتد).
Widget _buildUnifiedDesktopTabStrip({
required BuildContext context,
required List<_MenuItem> menuRoot,
required Color barBg,
required Color stripBottomBorder,
required String businessName,
required String dateTimeStr,
required bool isMobile,
}) {
final store = BusinessPanelUiStore.instance;
final bid = widget.businessId;
final session = store.tabsForBusiness(bid);
if (session == null || session.paths.isEmpty) {
return const SizedBox.shrink();
}
final theme = Theme.of(context);
final cs = theme.colorScheme;
final bool isDark = theme.brightness == Brightness.dark;
final Color stripFg = cs.onSurfaceVariant;
final Color stripFgTitle = cs.onSurface;
final isRtl = Directionality.of(context) == TextDirection.rtl;
final BorderRadius pillRadius = BorderRadius.circular(12);
Widget metaCapsule({
required Widget child,
double maxW = 260,
EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
}) {
return ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxW),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: pillRadius,
color: cs.surface.withValues(alpha: isDark ? 0.52 : 0.94),
border: Border.all(color: cs.outline.withValues(alpha: isDark ? 0.42 : 0.26)),
boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: isDark ? 0.35 : 0.07),
blurRadius: isDark ? 14 : 10,
spreadRadius: -2,
offset: const Offset(0, 3),
),
],
),
child: Padding(padding: padding, child: child),
),
);
}
final Widget businessTitle = metaCapsule(
maxW: 248,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
DecoratedBox(
decoration: BoxDecoration(
color: cs.primary.withValues(alpha: isDark ? 0.35 : 0.18),
borderRadius: BorderRadius.circular(9),
),
child: Padding(
padding: const EdgeInsets.all(7),
child: BusinessShellStorefrontGlyph(size: 18, color: cs.primary),
),
),
const SizedBox(width: 10),
Flexible(
child: Text(
businessName,
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w700,
letterSpacing: 0.12,
color: stripFgTitle,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: isRtl ? TextAlign.right : TextAlign.left,
),
),
],
),
);
final Widget dateWidget = !isMobile
? metaCapsule(
maxW: 268,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.schedule_rounded, size: 17, color: stripFg.withValues(alpha: 0.95)),
const SizedBox(width: 9),
Flexible(
child: Text(
dateTimeStr,
style: theme.textTheme.bodySmall?.copyWith(
color: stripFg,
fontWeight: FontWeight.w600,
fontSize: 12,
letterSpacing: 0.02,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
)
: const SizedBox.shrink();
final t = AppLocalizations.of(context)!;
final Widget overflowBtn = Tooltip(
message: t.businessPanelTabListTooltip,
child: Material(
color: cs.surfaceContainerHighest.withValues(alpha: isDark ? 0.55 : 0.82),
shape: const CircleBorder(),
elevation: isDark ? 2 : 1,
shadowColor: cs.shadow.withValues(alpha: 0.18),
child: InkWell(
customBorder: const CircleBorder(),
onTap: () => _showAllTabsManagementDialog(context, menuRoot),
child: SizedBox(
width: 34,
height: 34,
child: Icon(Icons.more_horiz_rounded, color: stripFgTitle.withValues(alpha: 0.85), size: 22),
),
),
),
);
final Widget tabRegion = Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: ClipRect(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
reverse: isRtl,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsetsDirectional.only(start: 10, end: 12),
child: Row(
textDirection: isRtl ? TextDirection.rtl : TextDirection.ltr,
mainAxisSize: MainAxisSize.min,
children: [
for (final p in session.paths)
_buildDesktopTabChip(context, menuRoot, session, p),
],
),
),
),
),
);
return DecoratedBox(
decoration: BoxDecoration(
color: barBg,
border: Border(bottom: BorderSide(color: stripBottomBorder, width: 1)),
boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: isDark ? 0.25 : 0.06),
blurRadius: isDark ? 8 : 6,
offset: const Offset(0, 2),
),
],
),
child: SizedBox(
height: _kUnifiedBizTabBarHeight,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 14,
end: 14,
top: _kBizTabStripVerticalPadding,
bottom: _kBizTabStripVerticalPadding,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
businessTitle,
const SizedBox(width: 12),
tabRegion,
if (!isMobile) ...[
const SizedBox(width: 10),
dateWidget,
],
const SizedBox(width: 8),
overflowBtn,
],
),
),
),
);
}
@override
void initState() {
super.initState();
BusinessPanelUiStore.instance.addListener(_onBusinessPanelUiChanged);
// اطمینان از bind بودن AuthStore برای ApiClient (جهت هدرها و تنظیمات)
try {
ApiClient.bindAuthStore(widget.authStore);
} catch (_) {}
// سال مالی انتخاب‌شده در داشبورد را برای گزارش‌ها/هدر از همان ابتدا bind کن
unawaited(FiscalYearController.load(widget.businessId));
// اضافه کردن listener برای AuthStore
widget.authStore.addListener(() {
if (mounted) {
setState(() {});
}
});
// بارگذاری اطلاعات کسب و کار و دسترسی‌ها
_loadBusinessInfo();
_loadBusinessPlugins();
_loadMenuPreferences();
// به‌روزرسانی خودکار ساعت در نوار بالا هر دقیقه
_dateTimeUpdateTimer = Timer.periodic(const Duration(minutes: 1), (_) {
if (mounted) setState(() {});
});
}
@override
void dispose() {
BusinessPanelUiStore.instance.removeListener(_onBusinessPanelUiChanged);
_dateTimeUpdateTimer?.cancel();
super.dispose();
}
@override
void didUpdateWidget(covariant BusinessShell oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.businessId != widget.businessId) {
_pluginsLoaded = false;
_pluginsLoadedForBusinessId = null;
unawaited(FiscalYearController.load(widget.businessId));
_loadBusinessPlugins(force: true);
_loadMenuPreferences();
}
}
Future<void> _loadMenuPreferences() async {
try {
final data = await _menuPreferencesService.getPreferences(widget.businessId);
if (!mounted) return;
setState(() => _menuPreferences = data);
} catch (_) {}
}
Future<void> showAddReceiptPaymentDialog() async {
if (!context.mounted) return;
final ctx = context;
final calendarController = widget.calendarController ?? await CalendarController.load();
if (!ctx.mounted) return;
final result = await showDialog<bool>(
context: ctx,
builder: (context) => BulkSettlementDialog(
businessId: widget.businessId,
calendarController: calendarController,
isReceipt: true, // پیش‌فرض دریافت
businessInfo: widget.authStore.currentBusiness,
apiClient: ApiClient(),
authStore: widget.authStore,
),
);
if (result == true) {
// Refresh the receipts payments page if it's currently open
_refreshReceiptsPaymentsPageIfOpen();
}
}
Future<void> showAddTransferDialog() async {
if (!context.mounted) return;
final ctx = context;
final calendarController = widget.calendarController ?? await CalendarController.load();
if (!ctx.mounted) return;
final result = await showDialog<bool>(
context: ctx,
builder: (context) => TransferFormDialog(
businessId: widget.businessId,
calendarController: calendarController,
authStore: widget.authStore,
apiClient: ApiClient(),
),
);
if (result == true) {
_refreshTransfersPageIfOpen();
}
}
Future<void> showAddExpenseIncomeDialog() async {
if (!context.mounted) return;
final ctx = context;
final calendarController = widget.calendarController ?? await CalendarController.load();
if (!ctx.mounted) return;
final result = await showDialog<bool>(
context: ctx,
builder: (context) => ExpenseIncomeFormDialog(
businessId: widget.businessId,
calendarController: calendarController,
isIncome: false, // پیش‌فرض هزینه؛ قابل تغییر داخل دیالوگ
businessInfo: widget.authStore.currentBusiness,
apiClient: ApiClient(),
),
);
if (result == true) {
_refreshExpenseIncomePageIfOpen();
}
}
Future<void> showAddCheckDialog() async {
if (!context.mounted) return;
final ctx = context;
final calendarController = widget.calendarController ?? await CalendarController.load();
if (!ctx.mounted) return;
final result = await showDialog<bool>(
context: ctx,
builder: (context) => CheckFormDialog(
businessId: widget.businessId,
authStore: widget.authStore,
calendarController: calendarController,
onSuccess: () {
_refreshChecksPageIfOpen();
},
),
);
if (result == true) {
_refreshChecksPageIfOpen();
}
}
void _refreshCurrentPage() {
// Force a rebuild of the current page
setState(() {
// This will cause the current page to rebuild
// and if it's PettyCashPage, it will refresh its data
});
}
/// Refresh the bank accounts page if it's currently open
void _refreshBankAccountsPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final accountsPath = _bu('accounts');
if (currentPath == accountsPath) {
// Try to get the page state and refresh the page
final pageState = BankAccountsPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
// If we can't determine the current path or refresh, just refresh current page
_refreshCurrentPage();
}
}
/// Refresh the persons page if it's currently open
void _refreshPersonsPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final personsPath = _bu('persons');
if (currentPath == personsPath) {
final pageState = PersonsPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the cash registers page if it's currently open
void _refreshCashRegistersPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final cashBoxPath = _bu('cash-box');
if (currentPath == cashBoxPath) {
final pageState = CashRegistersPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the petty cash page if it's currently open
void _refreshPettyCashPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final pettyCashPath = _bu('petty-cash');
if (currentPath == pettyCashPath) {
final pageState = PettyCashPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the checks page if it's currently open
void _refreshChecksPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final checksPath = _bu('checks');
if (currentPath == checksPath) {
final pageState = ChecksPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the invoices page if it's currently open
void _refreshInvoicesPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final invoicesPath = _bu('invoice');
if (currentPath == invoicesPath) {
final pageState = InvoicesListPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the receipts payments page if it's currently open
void _refreshReceiptsPaymentsPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final receiptsPaymentsPath = _bu('receipts-payments');
if (currentPath == receiptsPaymentsPath) {
final pageState = ReceiptsPaymentsListPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the expense income page if it's currently open
void _refreshExpenseIncomePageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final expenseIncomePath = _bu('expense-income');
if (currentPath == expenseIncomePath) {
final pageState = ExpenseIncomeListPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the transfers page if it's currently open
void _refreshTransfersPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final transfersPath = _bu('transfers');
if (currentPath == transfersPath) {
final pageState = TransfersPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
/// Refresh the documents page if it's currently open
void _refreshDocumentsPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final documentsPath = _bu('documents');
if (currentPath == documentsPath) {
final pageState = DocumentsPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
Future<void> showWalletTopUpDialog() async {
if (!context.mounted) return;
await WalletTopUpDialog.show(
context: context,
businessId: widget.businessId,
onSuccess: () {
// در صورت نیاز می‌توانید callback اضافه کنید
},
onError: (error) {
// خطا در ویجت مدیریت می‌شود
},
);
}
Future<void> _loadBusinessInfo() async {
if (widget.authStore.currentBusiness?.id == widget.businessId) {
return; // اطلاعات قبلاً بارگذاری شده
}
if (mounted) {
setState(() {
_isBusinessLoading = true;
_businessLoadError = null;
});
}
try {
final businessData = await _businessService.getBusinessWithPermissions(widget.businessId);
await widget.authStore.setCurrentBusiness(businessData);
} catch (e) {
if (mounted) {
final t = AppLocalizations.of(context);
final msg = ErrorExtractor.extractErrorMessage(e, t);
setState(() {
_businessLoadError = msg;
});
SnackBarHelper.showError(
context,
message: msg,
);
}
} finally {
if (mounted) {
setState(() {
_isBusinessLoading = false;
});
}
}
}
Future<void> _loadBusinessPlugins({bool force = false}) async {
if (!force &&
_pluginsLoaded &&
_pluginsLoadedForBusinessId == widget.businessId) {
return;
}
try {
final plugins = await _marketplaceService.listBusinessPlugins(businessId: widget.businessId);
if (mounted) {
setState(() {
_businessPlugins = plugins.map((e) => Map<String, dynamic>.from(e as Map)).toList();
_pluginsLoaded = true;
_pluginsLoadedForBusinessId = widget.businessId;
});
}
} catch (e) {
// خطا را نادیده می‌گیریم تا منو کار کند
if (mounted) {
setState(() {
_pluginsLoaded = true;
_pluginsLoadedForBusinessId = widget.businessId;
});
}
}
}
bool _isBusinessOwner() {
final current = widget.authStore.currentBusiness;
return current != null && current.id == widget.businessId && current.isOwner;
}
bool _isPluginCodeLicensed(String code) {
for (final plug in _businessPlugins) {
if (plug['plugin_code'] != code) continue;
if (marketplacePluginLicenseActive(plug)) return true;
}
return false;
}
bool _showPluginGatedMenu(bool isPluginActive) => isPluginActive;
void _maybeRefreshPluginsAfterMarketplace(String location) {
final prev = _lastRouteLocation;
_lastRouteLocation = location;
if (prev != null &&
prev.contains('/plugin-marketplace') &&
!location.contains('/plugin-marketplace')) {
_loadBusinessPlugins(force: true);
}
}
bool _isWarrantyPluginActive() {
// پیدا کردن پلاگین گارانتی
try {
final warrantyPlugin = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'product_warranty',
orElse: () => <String, dynamic>{},
);
return warrantyPlugin['is_active'] == true;
} catch (e) {
return false;
}
}
bool _isRepairShopPluginActive() {
// پیدا کردن پلاگین تعمیرگاه
try {
final repairShopPlugin = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'repair_shop_management',
orElse: () => <String, dynamic>{},
);
return repairShopPlugin['is_active'] == true;
} catch (e) {
return false;
}
}
bool _isCustomerClubPluginActive() {
try {
final plug = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'customer_club',
orElse: () => <String, dynamic>{},
);
return plug['is_active'] == true;
} catch (e) {
return false;
}
}
bool _isDistributionPluginActive() {
try {
final plug = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'distribution',
orElse: () => <String, dynamic>{},
);
return plug['is_active'] == true;
} catch (e) {
return false;
}
}
bool _isPayrollPluginActive() => _isPluginCodeLicensed('payroll');
bool _isOfficeAutomationPluginActive() => _isPluginCodeLicensed('office_automation');
bool _isFixedAssetsPluginActive() => _isPluginCodeLicensed('fixed_assets');
bool _isTelephonyPluginActive() => _isPluginCodeLicensed('asterisk_issabel_connector');
bool _isWooCommerceHesabixPluginActive() {
try {
final plug = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'woocommerce_hesabix',
orElse: () => <String, dynamic>{},
);
return plug['is_active'] == true;
} catch (e) {
return false;
}
}
bool _isDigipayPluginActive() => _isPluginCodeLicensed('digipay_credit');
bool _isBasalamPluginActive() {
try {
final plug = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'basalam_connector',
orElse: () => <String, dynamic>{},
);
return plug['is_active'] == true;
} catch (e) {
return false;
}
}
bool _isMoadianPluginActive() {
try {
final plug = _businessPlugins.firstWhere(
(plugin) => plugin['plugin_code'] == 'moadian_tax_integration',
orElse: () => <String, dynamic>{},
);
return plug['is_active'] == true;
} catch (e) {
return false;
}
}
void _openQuickAiChat(BuildContext context) {
AIChatDialog.show(
context,
authStore: widget.authStore,
businessId: widget.businessId,
calendarController: widget.calendarController,
);
}
Future<void> _openAiQuickStart(BuildContext context) async {
await AiQuickStart.open(context);
}
void _openCalculator(BuildContext context) {
CalculatorDialog.show(context);
}
static ButtonStyle get _bizToolbarIconStyle => IconButton.styleFrom(
minimumSize: const Size(38, 38),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
Widget _bizToolbarIconButton({
required String tooltip,
required Widget icon,
required VoidCallback onPressed,
VoidCallback? onLongPress,
}) {
return IconButton(
tooltip: tooltip,
visualDensity: VisualDensity.compact,
style: _bizToolbarIconStyle,
onPressed: onPressed,
onLongPress: onLongPress,
icon: icon,
);
}
@override
Widget build(BuildContext context) {
final t = AppLocalizations.of(context);
final currentBusiness = widget.authStore.currentBusiness;
final bool isCorrectBusiness = currentBusiness != null && currentBusiness.id == widget.businessId;
final bool hasPermissions = widget.authStore.businessPermissions != null;
// اگر در بارگذاری اطلاعات کسب‌وکار خطا داشتیم و هنوز کسب‌وکار فعلی با این صفحه هم‌خوان نیست،
// به‌جای نمایش پیام «دسترسی ندارید»، یک صفحه خطای شفاف نمایش می‌دهیم.
if (_businessLoadError != null && !isCorrectBusiness) {
return Scaffold(
appBar: AppBar(
title: Text(t.businessDashboard),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.error_outline,
size: 64,
color: Colors.redAccent,
),
const SizedBox(height: 24),
Text(
'خطا در بارگذاری اطلاعات کسب و کار یا دسترسی‌ها.',
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
_businessLoadError ?? '',
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: Colors.grey),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: () {
_loadBusinessInfo();
},
icon: const Icon(Icons.refresh),
label: const Text('تلاش مجدد برای بارگذاری'),
),
],
),
),
),
);
}
// تا زمانی که اطلاعات کسب‌وکار و دسترسی‌ها به‌طور کامل بارگذاری نشده‌اند،
// صفحه اصلی را با یک لودر ساده نمایش می‌دهیم تا پیام «عدم دسترسی» به‌صورت موقت دیده نشود.
if (_isBusinessLoading || !isCorrectBusiness || !hasPermissions) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
const CircularProgressIndicator(),
const SizedBox(height: 16),
Text(
'در حال بارگذاری اطلاعات کسب و کار و دسترسی‌ها...',
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
],
),
),
);
}
final bool useRail = ResponsiveHelper.useShellPersistentNavigation(context);
final bool railExtended = ResponsiveHelper.shellNavigationRailExtended(context);
final ColorScheme scheme = Theme.of(context).colorScheme;
String location = _bu('dashboard'); // default location
try {
location = GoRouterState.of(context).uri.toString();
} catch (e) {
// اگر GoRouterState در دسترس نیست، از default استفاده کن
}
_maybeRefreshPluginsAfterMarketplace(location);
final bool isDark = Theme.of(context).brightness == Brightness.dark;
final workflowLabel = _workflowMenuLabel(t);
// ساختار متمرکز منو
final allMenuItems = <_MenuItem>[
_MenuItem(
key: 'dashboard',
label: t.businessDashboard,
icon: Icons.dashboard_outlined,
selectedIcon: Icons.dashboard,
path: _bu('dashboard'),
type: _MenuItemType.simple,
),
_MenuItem(
key: 'sep_practical_tools',
label: t.practicalTools,
icon: Icons.category,
selectedIcon: Icons.category,
path: null, // آیتم جداکننده
type: _MenuItemType.separator,
),
_MenuItem(
key: 'persons',
label: t.people,
icon: Icons.people,
selectedIcon: Icons.people,
path: _bu('persons'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'group:products',
label: t.productsAndServices,
icon: Icons.inventory_2,
selectedIcon: Icons.inventory_2,
path: null, // برای منوی بازشونده
type: _MenuItemType.expandable,
children: [
_MenuItem(
key: 'products',
label: t.products,
icon: Icons.shopping_cart,
selectedIcon: Icons.shopping_cart,
path: _bu('products'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'product-bundles',
label: 'باندل‌های کالا',
icon: Icons.inventory_2_outlined,
selectedIcon: Icons.inventory_2,
path: _bu('product-bundles'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'categories',
label: t.categories,
icon: Icons.category,
selectedIcon: Icons.category,
path: _bu('categories'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'product-attributes',
label: t.productAttributes,
icon: Icons.tune,
selectedIcon: Icons.tune,
path: _bu('product-attributes'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'catalog-spec-fields',
label: 'قالب مشخصات تأمین',
icon: Icons.view_list_outlined,
selectedIcon: Icons.view_list,
path: _bu('catalog-spec-fields'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'barcode-labels',
label: t.barcodeLabelsMenu,
icon: Icons.qr_code_2_outlined,
selectedIcon: Icons.qr_code_2,
path: _bu('barcode-labels'),
type: _MenuItemType.simple,
hasAddButton: false,
),
],
),
_MenuItem(
key: 'group:accounts',
label: t.banking,
icon: Icons.account_balance,
selectedIcon: Icons.account_balance,
path: null, // برای منوی بازشونده
type: _MenuItemType.expandable,
children: [
_MenuItem(
key: 'accounts',
label: t.accounts,
icon: Icons.account_balance_wallet,
selectedIcon: Icons.account_balance_wallet,
path: _bu('accounts'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'petty-cash',
label: t.pettyCash,
icon: Icons.money,
selectedIcon: Icons.money,
path: _bu('petty-cash'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'cash-box',
label: t.cashBox,
icon: Icons.savings,
selectedIcon: Icons.savings,
path: _bu('cash-box'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'wallet',
label: t.wallet,
icon: Icons.wallet,
selectedIcon: Icons.wallet,
path: _bu('wallet'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'loan-facilities',
label: t.loanFacilities,
icon: Icons.real_estate_agent_outlined,
selectedIcon: Icons.real_estate_agent,
path: _bu('loan-facilities'),
type: _MenuItemType.simple,
hasAddButton: true,
),
],
),
_MenuItem(
key: 'sep_accounting',
label: t.accounting,
icon: Icons.calculate,
selectedIcon: Icons.calculate,
path: null, // آیتم جداکننده
type: _MenuItemType.separator,
),
_MenuItem(
key: 'quick-sales',
label: 'فروش سریع',
icon: Icons.point_of_sale,
selectedIcon: Icons.point_of_sale,
path: _bu('quick-sales'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'invoice',
label: t.invoice,
icon: Icons.receipt,
selectedIcon: Icons.receipt,
path: _bu('invoice'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'receipts-payments',
label: t.receiptsAndPayments,
icon: Icons.account_balance_wallet,
selectedIcon: Icons.account_balance_wallet,
path: _bu('receipts-payments'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'expense-income',
label: t.expenseAndIncome,
icon: Icons.account_balance_wallet,
selectedIcon: Icons.account_balance_wallet,
path: _bu('expense-income'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'transfers',
label: t.transfers,
icon: Icons.swap_horiz,
selectedIcon: Icons.swap_horiz,
path: _bu('transfers'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'checks',
label: t.checks,
icon: Icons.receipt_long,
selectedIcon: Icons.receipt_long,
path: _bu('checks'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'documents',
label: t.documents,
icon: Icons.description,
selectedIcon: Icons.description,
path: _bu('documents'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'group:chart-of-accounts',
label: t.accountingMenu,
icon: Icons.calculate,
selectedIcon: Icons.calculate,
path: null, // برای منوی بازشونده
type: _MenuItemType.expandable,
children: [
_MenuItem(
key: 'chart-of-accounts',
label: t.chartOfAccounts,
icon: Icons.table_chart,
selectedIcon: Icons.table_chart,
path: _bu('chart-of-accounts'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'opening-balance',
label: t.openingBalance,
icon: Icons.play_arrow,
selectedIcon: Icons.play_arrow,
path: _bu('opening-balance'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'year-end-closing',
label: t.yearEndClosing,
icon: Icons.stop,
selectedIcon: Icons.stop,
path: _bu('year-end-closing'),
type: _MenuItemType.simple,
hasAddButton: false,
),
if (widget.authStore.isMultiCurrency)
_MenuItem(
key: 'currency-revaluation',
label: t.currencyRevaluation,
icon: Icons.payments,
selectedIcon: Icons.payments,
path: _bu('currency-revaluation'),
type: _MenuItemType.simple,
hasAddButton: false,
),
],
),
_MenuItem(
key: 'reports',
label: t.reports,
icon: Icons.assessment,
selectedIcon: Icons.assessment,
path: _bu('reports'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'sep_services_plugins',
label: t.servicesAndPlugins,
icon: Icons.extension,
selectedIcon: Icons.extension,
path: null, // آیتم جداکننده
type: _MenuItemType.separator,
),
_MenuItem(
key: 'basalam',
label: t.basalamIntegrationMenuTitle,
icon: Icons.storefront_outlined,
selectedIcon: Icons.storefront,
path: _bu('basalam'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'woocommerce',
label: t.woocommerceIntegrationMenuTitle,
icon: Icons.shopping_cart_outlined,
selectedIcon: Icons.shopping_cart,
path: _bu('woocommerce'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'digipay',
label: t.digipayMenuTitle,
icon: Icons.credit_score_outlined,
selectedIcon: Icons.credit_score,
path: _bu('digipay'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'plugin-marketplace',
label: t.pluginMarketplace,
icon: Icons.store,
selectedIcon: Icons.store,
path: _bu('plugin-marketplace'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'hscript',
label: 'گزارش‌ساز اسکریپتی',
icon: Icons.code_outlined,
selectedIcon: Icons.code,
path: _bu('hscript'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'group:warehouses',
label: t.warehouseManagement,
icon: Icons.warehouse,
selectedIcon: Icons.warehouse,
path: null, // برای منوی بازشونده
type: _MenuItemType.expandable,
children: [
_MenuItem(
key: 'warehouses',
label: t.warehouses,
icon: Icons.store,
selectedIcon: Icons.store,
path: _bu('warehouses'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'warehouse-docs',
label: 'حواله‌های انبار',
icon: Icons.description,
selectedIcon: Icons.description,
path: _bu('warehouse-docs'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'stock-count',
label: 'انبار گردانی',
icon: Icons.inventory,
selectedIcon: Icons.inventory,
path: _bu('stock-count'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'quick-sales-stock-discrepancies',
label: 'مغایرت‌های موجودی فروش سریع',
icon: Icons.rule_folder_outlined,
selectedIcon: Icons.rule_folder,
path: _bu('quick-sales-stock-discrepancies'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'goods-expense-income',
label: 'کالای هزینه/درآمد شده',
icon: Icons.inventory_2_outlined,
selectedIcon: Icons.inventory_2,
path: _bu('goods-expense-income'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'production-orders',
label: 'سفارش‌های تولید',
icon: Icons.precision_manufacturing_outlined,
selectedIcon: Icons.precision_manufacturing,
path: _bu('production-orders'),
type: _MenuItemType.simple,
hasAddButton: true,
),
],
),
_MenuItem(
key: 'storage-files',
label: t.storageSpace,
icon: Icons.storage,
selectedIcon: Icons.storage,
path: _bu('storage-files'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'tax-workspace',
label: t.taxpayers,
icon: Icons.account_balance,
selectedIcon: Icons.account_balance,
path: _bu('tax-workspace'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'group:ai',
label: 'هوش مصنوعی',
icon: Icons.smart_toy_outlined,
selectedIcon: Icons.smart_toy,
path: null, // برای منوی بازشونده
type: _MenuItemType.expandable,
children: [
_MenuItem(
key: 'ai/chat',
label: 'دستیار هوشمند',
icon: Icons.chat_bubble_outline,
selectedIcon: Icons.chat_bubble,
path: _bu('ai/chat'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'ai/subscription',
label: 'اشتراک AI',
icon: Icons.subscriptions_outlined,
selectedIcon: Icons.subscriptions,
path: _bu('ai/subscription'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'ai/usage',
label: 'آمار استفاده',
icon: Icons.bar_chart_outlined,
selectedIcon: Icons.bar_chart,
path: _bu('ai/usage'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'ai/skills/marketplace',
label: 'مارکت‌پلیس مهارت‌ها',
icon: Icons.storefront_outlined,
selectedIcon: Icons.storefront,
path: _bu('ai/skills/marketplace'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'ai/skills/publisher',
label: 'درآمد مهارت‌ها',
icon: Icons.payments_outlined,
selectedIcon: Icons.payments,
path: _bu('ai/skills/publisher'),
type: _MenuItemType.simple,
hasAddButton: false,
),
],
),
_MenuItem(
key: 'workflows',
label: workflowLabel,
icon: Icons.hub_outlined,
selectedIcon: Icons.hub,
path: _bu('workflows'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'group:crm',
label: 'CRM',
icon: Icons.handshake_outlined,
selectedIcon: Icons.handshake,
path: _bu('crm/dashboard'),
type: _MenuItemType.expandable,
children: [
// کار روزانه
_MenuItem(
key: 'crm/tasks',
label: 'صف کار',
icon: Icons.task_alt_outlined,
selectedIcon: Icons.task_alt,
path: _bu('crm/tasks'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'crm/web-chat',
label: 'چت وب',
icon: Icons.chat_bubble_outline,
selectedIcon: Icons.chat_bubble,
path: _bu('crm/web-chat'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'crm/notes-calendar',
label: t.crmMenuNotesCalendar,
icon: Icons.calendar_month_outlined,
selectedIcon: Icons.calendar_month,
path: _bu('crm/notes-calendar'),
type: _MenuItemType.simple,
hasAddButton: false,
),
// قیف فروش
_MenuItem(
key: 'crm/leads',
label: 'سرنخ‌ها',
icon: Icons.contact_phone_outlined,
selectedIcon: Icons.contact_phone,
path: _bu('crm/leads'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'crm/deals',
label: 'فرصت‌های فروش',
icon: Icons.trending_up_outlined,
selectedIcon: Icons.trending_up,
path: _bu('crm/deals'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'crm/activities',
label: 'فعالیت‌ها',
icon: Icons.history,
selectedIcon: Icons.history,
path: _bu('crm/activities'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'crm/customer-360',
label: 'نمای ۳۶۰ مشتری',
icon: Icons.person_search_outlined,
selectedIcon: Icons.person_search,
path: _bu('crm/customer-360'),
type: _MenuItemType.simple,
hasAddButton: false,
),
// بینش
_MenuItem(
key: 'crm/dashboard',
label: 'داشبورد',
icon: Icons.dashboard_outlined,
selectedIcon: Icons.dashboard,
path: _bu('crm/dashboard'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'crm/reports',
label: 'گزارشات',
icon: Icons.assessment_outlined,
selectedIcon: Icons.assessment,
path: _bu('crm/reports'),
type: _MenuItemType.simple,
hasAddButton: false,
),
// پیکربندی
_MenuItem(
key: 'crm/process-definitions',
label: 'فرایندها و مراحل قیف',
icon: Icons.account_tree_outlined,
selectedIcon: Icons.account_tree,
path: _bu('crm/process-definitions'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'crm/sequences',
label: 'توالی‌های خودکار',
icon: Icons.timeline_outlined,
selectedIcon: Icons.timeline,
path: _bu('crm/sequences'),
type: _MenuItemType.simple,
hasAddButton: false,
),
],
),
_MenuItem(
key: 'warranty',
label: t.warranty ?? 'گارانتی',
icon: Icons.verified_user,
selectedIcon: Icons.verified_user,
path: _bu('warranty'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'repair-shop',
label: t.repairShopMenu,
icon: Icons.build_circle_outlined,
selectedIcon: Icons.build_circle,
path: _bu('repair-shop'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'customer-club',
label: t.customerClubMenu,
icon: Icons.card_giftcard_outlined,
selectedIcon: Icons.card_giftcard,
path: _bu('customer-club'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'payroll',
label: t.payrollMenu,
icon: Icons.payments_outlined,
selectedIcon: Icons.payments,
path: _bu('payroll'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'group:office-automation',
label: t.oaMenu,
icon: Icons.mark_email_unread_outlined,
selectedIcon: Icons.mark_email_unread,
path: null,
type: _MenuItemType.expandable,
children: [
_MenuItem(
key: 'office-automation',
label: t.oaCartable,
icon: Icons.inbox_outlined,
selectedIcon: Icons.inbox,
path: _bu('office-automation'),
type: _MenuItemType.simple,
hasAddButton: true,
),
_MenuItem(
key: 'office-automation/org',
label: t.oaOrg,
icon: Icons.account_tree_outlined,
selectedIcon: Icons.account_tree,
path: _bu('office-automation/org'),
type: _MenuItemType.simple,
),
_MenuItem(
key: 'office-automation/external-orgs',
label: t.oaExternalOrgs,
icon: Icons.apartment_outlined,
selectedIcon: Icons.apartment,
path: _bu('office-automation/external-orgs'),
type: _MenuItemType.simple,
),
_MenuItem(
key: 'office-automation/archive',
label: t.oaArchiveTree,
icon: Icons.inventory_2_outlined,
selectedIcon: Icons.inventory_2,
path: _bu('office-automation/archive'),
type: _MenuItemType.simple,
),
_MenuItem(
key: 'office-automation/reports',
label: t.oaReports,
icon: Icons.bar_chart_outlined,
selectedIcon: Icons.bar_chart,
path: _bu('office-automation/reports'),
type: _MenuItemType.simple,
),
],
),
_MenuItem(
key: 'fixed-assets',
label: t.fixedAssetsMenu,
icon: Icons.chair_alt_outlined,
selectedIcon: Icons.chair_alt,
path: _bu('fixed-assets'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'telephony',
label: t.telephonyMenu,
icon: Icons.phone_in_talk_outlined,
selectedIcon: Icons.phone_in_talk,
path: _bu('telephony'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'distribution',
label: t.distributionMenu,
icon: Icons.local_shipping_outlined,
selectedIcon: Icons.local_shipping,
path: _bu('distribution'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'zohal/inquiries',
label: 'استعلامات',
icon: Icons.search_outlined,
selectedIcon: Icons.search,
path: _bu('zohal/inquiries'),
type: _MenuItemType.simple,
hasAddButton: false,
),
_MenuItem(
key: 'sep_others',
label: t.others,
icon: Icons.more_horiz,
selectedIcon: Icons.more_horiz,
path: null, // آیتم جداکننده
type: _MenuItemType.separator,
),
_MenuItem(
key: 'settings',
label: t.settings,
icon: Icons.settings,
selectedIcon: Icons.settings,
path: _bu('settings'),
type: _MenuItemType.simple,
),
_MenuItem(
key: 'report-templates',
label: t.templates,
icon: Icons.picture_as_pdf,
selectedIcon: Icons.picture_as_pdf,
path: _bu('report-templates'),
type: _MenuItemType.simple,
),
];
// فیلتر کردن منو بر اساس دسترسی‌ها
final menuItems = _applyMenuPreferences(_getFilteredMenuItems(allMenuItems));
int selectedIndex = 0;
for (int i = 0; i < menuItems.length; i++) {
final item = menuItems[i];
if (item.type == _MenuItemType.separator) continue; // نادیده گرفتن آیتم جداکننده
if (item.type == _MenuItemType.simple && item.path != null &&
_businessMenuPathMatchesLocation(location, item.path!, widget.businessId)) {
selectedIndex = i;
break;
} else if (item.type == _MenuItemType.expandable && item.children != null) {
for (int j = 0; j < item.children!.length; j++) {
final child = item.children![j];
if (child.path != null &&
_businessMenuPathMatchesLocation(location, child.path!, widget.businessId)) {
selectedIndex = i;
_setExpandableMenuOpen(item, true);
break;
}
}
}
}
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (!mounted) return;
await BusinessPanelUiStore.instance.hydrateIfNeeded();
if (!mounted) return;
// مسیر را در خود callback بخوان تا URL کهنه‌ی build قبلی
// (مثلاً بعد از بستن تب و قبل از go) جلسه تب را زنده نکند.
final ctx = context;
if (!ctx.mounted) return;
String syncPath;
try {
syncPath = GoRouterState.of(ctx).uri.path;
} catch (_) {
syncPath = Uri.tryParse(location)?.path ?? _bu('dashboard');
}
if (syncPath.isEmpty) {
syncPath = _bu('dashboard');
}
BusinessPanelUiStore.instance.onBusinessRouteChanged(
widget.businessId,
syncPath,
isDesktop: useRail,
);
});
Future<void> onSelect(int index, {bool longPress = false}) async {
final item = menuItems[index];
if (item.type == _MenuItemType.separator) return; // آیتم جداکننده قابل کلیک نیست
if (item.type == _MenuItemType.simple && item.path != null) {
final reuseAcrossTabs = _reuseAcrossTabsForSidebarGesture(longPress: longPress);
try {
if (!context.mounted) return;
final ctx = context;
if (GoRouterState.of(ctx).uri.toString() != item.path!) {
if (item.label == t.categories) {
// باز کردن دیالوگ دسته‌بندی‌ها به جای ناوبری
if (widget.authStore.canReadSection('categories')) {
if (!ctx.mounted) return;
await showDialog<bool>(
context: ctx,
builder: (dialogCtx) => CategoryTreeDialog(
businessId: widget.businessId,
authStore: widget.authStore,
),
);
}
} else {
await _navigateMenuPath(ctx, item.path!, desktopRail: useRail, reuseAcrossTabs: reuseAcrossTabs);
}
}
} catch (e) {
// اگر GoRouterState در دسترس نیست، مستقیماً به مسیر برود
if (!context.mounted) return;
final ctx = context;
if (item.label == t.categories) {
if (widget.authStore.canReadSection('categories')) {
if (!ctx.mounted) return;
await showDialog<bool>(
context: ctx,
builder: (dialogCtx) => CategoryTreeDialog(
businessId: widget.businessId,
authStore: widget.authStore,
),
);
}
} else {
await _navigateMenuPath(ctx, item.path!, desktopRail: useRail, reuseAcrossTabs: reuseAcrossTabs);
}
}
} else if (item.type == _MenuItemType.expandable) {
setState(() => _toggleExpandableMenu(item));
}
}
Future<void> onSelectChild(int parentIndex, int childIndex, {bool longPress = false}) async {
final parent = menuItems[parentIndex];
if (parent.type == _MenuItemType.expandable && parent.children != null) {
final child = parent.children![childIndex];
if (child.label == t.categories) {
if (widget.authStore.canReadSection('categories')) {
await showDialog<bool>(
context: context,
builder: (ctx) => CategoryTreeDialog(
businessId: widget.businessId,
authStore: widget.authStore,
),
);
}
return;
}
if (child.path != null) {
final reuseAcrossTabs = _reuseAcrossTabsForSidebarGesture(longPress: longPress);
try {
if (GoRouterState.of(context).uri.toString() != child.path!) {
await _navigateMenuPath(context, child.path!, desktopRail: useRail, reuseAcrossTabs: reuseAcrossTabs);
}
} catch (e) {
// اگر GoRouterState در دسترس نیست، مستقیماً به مسیر برود
await _navigateMenuPath(context, child.path!, desktopRail: useRail, reuseAcrossTabs: reuseAcrossTabs);
}
}
}
}
Future<void> onLogout() async {
await widget.authStore.saveApiKey(null);
if (!context.mounted) return;
// از SnackBarHelper برای نمایش پیام خروج استفاده می‌کنیم تا روی همه لایه‌ها نمایش داده شود
SnackBarHelper.showSuccess(
context,
message: t.logoutDone,
);
context.go('/login');
}
Future<void> showAddPersonDialog() async {
final result = await showDialog<Person?>(
context: context,
builder: (context) => PersonFormDialog(
businessId: widget.businessId,
onSuccess: () {
_refreshPersonsPageIfOpen();
},
),
);
if (result != null) {
_refreshPersonsPageIfOpen();
}
}
void _refreshProductsPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final productsPath = _bu('products');
if (currentPath == productsPath) {
// If we're on the products page, refresh it
_refreshCurrentPage();
}
} catch (_) {
// If GoRouterState is not available, try to refresh anyway
_refreshCurrentPage();
}
}
Future<void> showAddProductDialog() async {
final result = await showDialog<Object?>(
context: context,
builder: (context) => ProductFormDialog(
businessId: widget.businessId,
authStore: widget.authStore,
onSuccess: () {
// Refresh the products page if it's currently open
_refreshProductsPageIfOpen();
},
),
);
if (result != null && result != false) {
// Product was successfully added (returns true or int ID), refresh if products page is open
_refreshProductsPageIfOpen();
}
}
Future<void> showAddCashBoxDialog() async {
final result = await showDialog<bool>(
context: context,
builder: (context) => CashRegisterFormDialog(
businessId: widget.businessId,
onSuccess: () {
// Refresh the cash registers page if it's currently open
_refreshCashRegistersPageIfOpen();
},
),
);
if (result == true) {
// Cash register was successfully added, refresh the cash registers page if open
_refreshCashRegistersPageIfOpen();
}
}
Future<void> showAddPettyCashDialog() async {
final result = await showDialog<bool>(
context: context,
builder: (context) => PettyCashFormDialog(
businessId: widget.businessId,
onSuccess: () {
// Refresh the petty cash page if it's currently open
_refreshPettyCashPageIfOpen();
},
),
);
if (result == true) {
// Petty cash was successfully added, refresh the petty cash page if open
_refreshPettyCashPageIfOpen();
}
}
Future<void> showAddBankAccountDialog() async {
final result = await showDialog<bool>(
context: context,
builder: (context) => BankAccountFormDialog(
businessId: widget.businessId,
onSuccess: () {
// Refresh the bank accounts page if it's currently open
_refreshBankAccountsPageIfOpen();
},
),
);
if (result == true) {
// Bank account was successfully added, refresh the bank accounts page if open
_refreshBankAccountsPageIfOpen();
}
}
Future<void> showAddDocumentDialog() async {
if (!context.mounted) return;
final ctx = context;
final calendarController = widget.calendarController ?? await CalendarController.load();
if (!ctx.mounted) return;
final result = await showDialog<bool>(
context: ctx,
barrierDismissible: false,
builder: (context) => DocumentFormDialog(
businessId: widget.businessId,
calendarController: calendarController,
authStore: widget.authStore,
apiClient: ApiClient(),
fiscalYearId: null,
currencyId: null, // از CurrencyPickerWidget (پیش‌فرض کسب‌وکار) دریافت می‌شود
),
);
if (result == true) {
// Document was successfully added, refresh the documents page if open
_refreshDocumentsPageIfOpen();
}
}
void _refreshLoanFacilitiesPageIfOpen() {
try {
final currentPath = GoRouterState.of(context).uri.path;
final lfPath = _bu('loan-facilities');
if (currentPath == lfPath) {
final pageState = LoanFacilitiesPage.getPageState(widget.businessId);
if (pageState != null && pageState.mounted) {
pageState.refresh();
return;
}
}
} catch (_) {
_refreshCurrentPage();
}
}
Future<void> showLoanFacilityCreateDialog() async {
if (!context.mounted) return;
final ctx = context;
final calendarController = widget.calendarController ?? await CalendarController.load();
if (!ctx.mounted) return;
await LoanFacilitiesPage.showUpsertFacilityDialog(
context: ctx,
businessId: widget.businessId,
calendarController: calendarController,
authStore: widget.authStore,
onSuccess: _refreshLoanFacilitiesPageIfOpen,
);
}
Future<void> showAddWarehouseDialog() async {
final result = await WarehouseFormDialog.show(
context,
businessId: widget.businessId,
onSuccess: () {
// Refresh the warehouses page if it's currently open
_refreshCurrentPage();
},
);
if (result == true) {
// Warehouse was successfully added, refresh the current page
_refreshCurrentPage();
}
}
Future<void> showAddWarehouseDocumentDialog() async {
if (!context.mounted) return;
final calendarController = widget.calendarController ?? await CalendarController.load();
final result = await showDialog<WarehouseDocWizardResult>(
context: context,
builder: (context) => WarehouseDocWizardDialog(
businessId: widget.businessId,
apiClient: ApiClient(),
calendarController: calendarController,
),
);
if (result == null) return;
if (result.isManual) {
// Manual document creation
final calendarController = widget.calendarController ?? await CalendarController.load();
await showDialog(
context: context,
builder: (_) => WarehouseDocumentFormDialog(
businessId: widget.businessId,
calendarController: calendarController,
onSuccess: () => _refreshCurrentPage(),
),
);
return;
}
// Handle invoice-based document creation
await _handleInvoiceWizardResult(result);
}
bool isExpanded(_MenuItem item) => _isExpandableMenuOpen(item);
int getTotalMenuItemsCount() {
int count = 0;
for (final item in menuItems) {
if (item.type == _MenuItemType.separator) {
count++; // آیتم جداکننده هم شمرده می‌شود
} else {
count++; // آیتم اصلی
// نمایش زیرمجموعه‌ها در همه حالت‌ها (Rail و Extended)
if (item.type == _MenuItemType.expandable && isExpanded(item)) {
count += item.children?.length ?? 0;
}
}
}
return count;
}
final shellColors = context.shellColors;
final Color appBarBg = shellColors.topBarBackground;
final Color appBarFg = shellColors.topBarForeground;
final launcherHomePath = MobileLauncherBackInfo.maybeHomeOf(context);
final bool isMobile = !useRail;
final String businessName = currentBusiness?.name ?? '';
final TextStyle? appBarTitleStyle = Theme.of(context).textTheme.titleSmall?.copyWith(
color: appBarFg,
fontWeight: FontWeight.w700,
height: 1.1,
);
final appBar = AppBar(
toolbarHeight: _kBizAppBarToolbarHeight,
elevation: 0,
scrolledUnderElevation: 0,
surfaceTintColor: Colors.transparent,
backgroundColor: appBarBg,
foregroundColor: appBarFg,
iconTheme: IconThemeData(color: appBarFg, size: 21),
actionsIconTheme: IconThemeData(color: appBarFg, size: 21),
automaticallyImplyLeading: false,
leadingWidth: isMobile ? 44 : null,
titleSpacing: 0,
title: Row(
children: [
SizedBox(width: useRail ? 2 : 4),
if (useRail)
IconButton(
tooltip: _desktopRailVisible
? t.businessShellHideSidebarTooltip
: t.businessShellShowSidebarTooltip,
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
minimumSize: const Size(36, 36),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
onPressed: () => setState(() => _desktopRailVisible = !_desktopRailVisible),
icon: BusinessShellMenuGlyph(
color: appBarFg,
size: 21,
sidebarOpen: _desktopRailVisible,
),
),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 22,
maxWidth: isMobile ? 72 : 160,
),
child: const BrandLogo(height: 22),
),
if (!isMobile) ...[
const SizedBox(width: 10),
Flexible(
child: Text(
BrandConfig.appTitle(t),
style: appBarTitleStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
] else if (businessName.isNotEmpty) ...[
const SizedBox(width: 8),
Flexible(
child: Text(
businessName,
style: appBarTitleStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
],
),
leading: useRail
? null
: Builder(
builder: (ctx) => IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
minimumSize: const Size(40, 40),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
icon: BusinessShellMenuGlyph(color: appBarFg, size: 21, sidebarOpen: false),
onPressed: () => Scaffold.of(ctx).openDrawer(),
tooltip: t.menu,
),
),
actions: [
DailyFxRatesToolbarChip(
businessId: widget.businessId,
authStore: widget.authStore,
iconColor: appBarFg,
iconOnly: isMobile,
),
NotificationBellButton(
authStore: widget.authStore,
iconColor: appBarFg,
denseToolbar: true,
),
if (!isMobile) ...[
_bizToolbarIconButton(
tooltip: t.businessShellAiChatTooltip,
icon: Icon(Icons.smart_toy_outlined, color: appBarFg, size: 21),
onPressed: () => _openQuickAiChat(context),
onLongPress: () => _openAiQuickStart(context),
),
_bizToolbarIconButton(
tooltip: t.businessShellCalculatorTooltip,
icon: Icon(Icons.calculate_outlined, color: appBarFg, size: 21),
onPressed: () => _openCalculator(context),
),
],
CombinedUserMenuButton(
authStore: widget.authStore,
localeController: widget.localeController,
calendarController: widget.calendarController,
themeController: widget.themeController,
denseToolbar: true,
),
if (isMobile)
PopupMenuButton<String>(
tooltip: t.businessShellMoreToolsTooltip,
padding: EdgeInsets.zero,
iconSize: 21,
offset: const Offset(0, 8),
icon: Icon(Icons.more_vert_rounded, color: appBarFg, size: 21),
style: _bizToolbarIconStyle,
onSelected: (value) {
switch (value) {
case 'ai':
_openQuickAiChat(context);
case 'ai_quick':
_openAiQuickStart(context);
case 'calculator':
_openCalculator(context);
}
},
itemBuilder: (ctx) => [
PopupMenuItem(
value: 'ai',
child: Row(
children: [
const Icon(Icons.smart_toy_outlined, size: 20),
const SizedBox(width: 12),
Text(t.businessShellAiChatTooltip),
],
),
),
PopupMenuItem(
value: 'ai_quick',
child: Row(
children: [
const Icon(Icons.auto_awesome_rounded, size: 20),
const SizedBox(width: 12),
Text(t.aiQuickLauncherTitle),
],
),
),
PopupMenuItem(
value: 'calculator',
child: Row(
children: [
const Icon(Icons.calculate_outlined, size: 20),
const SizedBox(width: 12),
Text(t.businessShellCalculatorTooltip),
],
),
),
],
),
const SizedBox(width: 2),
],
);
// نوار دوم: تب‌ها یا نام کسب‌وکار / تاریخ (فقط دسکتاپ)
final bool isJalali = widget.calendarController?.isJalali ?? true;
final String dateTimeStr = HesabixDateUtils.formatDateTimeWithWeekday(
DateTime.now(),
isJalali,
t.localeName,
);
final Color secondaryStripBg = Color.alphaBlend(
scheme.primary.withValues(alpha: isDark ? 0.175 : 0.10),
isDark ? scheme.surfaceContainerHigh : scheme.surfaceContainerLow,
);
final Color stripBottomBorder = scheme.outline.withValues(alpha: isDark ? 0.58 : 0.48);
final Color stripMuted = scheme.onSurfaceVariant;
final Color stripTitle = scheme.onSurface;
final ThemeData shellStripTheme = Theme.of(context);
final Widget businessTopBar = DecoratedBox(
decoration: BoxDecoration(
color: secondaryStripBg,
border: Border(bottom: BorderSide(color: stripBottomBorder, width: 1)),
boxShadow: [
BoxShadow(
color: scheme.shadow.withValues(alpha: isDark ? 0.25 : 0.06),
blurRadius: isDark ? 8 : 6,
offset: const Offset(0, 2),
),
],
),
child: SizedBox(
height: _kUnifiedBizTabBarHeight,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 14,
end: 14,
top: _kBizTabStripVerticalPadding,
bottom: _kBizTabStripVerticalPadding,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Row(
children: [
DecoratedBox(
decoration: BoxDecoration(
color: scheme.primary.withValues(alpha: isDark ? 0.35 : 0.18),
borderRadius: BorderRadius.circular(9),
),
child: Padding(
padding: const EdgeInsets.all(7),
child: BusinessShellStorefrontGlyph(size: 18, color: scheme.primary),
),
),
const SizedBox(width: 10),
Expanded(
child: Text(
businessName,
style: shellStripTheme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w700,
letterSpacing: 0.12,
color: stripTitle,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.start,
),
),
],
),
),
if (!isMobile)
DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: scheme.surface.withValues(alpha: isDark ? 0.52 : 0.94),
border: Border.all(color: scheme.outline.withValues(alpha: isDark ? 0.42 : 0.26)),
boxShadow: [
BoxShadow(
color: scheme.shadow.withValues(alpha: isDark ? 0.35 : 0.07),
blurRadius: isDark ? 14 : 10,
spreadRadius: -2,
offset: const Offset(0, 3),
),
],
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.schedule_rounded, size: 17, color: stripMuted.withValues(alpha: 0.95)),
const SizedBox(width: 9),
Flexible(
child: Text(
dateTimeStr,
style: shellStripTheme.textTheme.bodySmall?.copyWith(
color: stripMuted,
fontWeight: FontWeight.w600,
fontSize: 12,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
],
),
),
),
);
final uiStore = BusinessPanelUiStore.instance;
final bool showBizTabs =
useRail && uiStore.shouldShowTabStrip(widget.businessId, isDesktop: true);
final Widget shellMainChild = widget.child;
final double topStripHeight = isMobile ? 0 : _kUnifiedBizTabBarHeight;
final PreferredSizeWidget preferredAppBar = PreferredSize(
preferredSize: Size.fromHeight(topStripHeight + _kBizAppBarToolbarHeight),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
appBar,
if (showBizTabs)
_buildUnifiedDesktopTabStrip(
context: context,
menuRoot: allMenuItems,
barBg: secondaryStripBg,
stripBottomBorder: stripBottomBorder,
businessName: businessName,
dateTimeStr: dateTimeStr,
isMobile: isMobile,
)
else if (!isMobile)
businessTopBar,
],
),
);
final content = Container(
color: scheme.surface,
child: SafeArea(
child: Stack(
children: [
Column(
children: [
TelephonyPhoneBarHost(
businessId: widget.businessId,
authStore: widget.authStore,
pluginActive: _isTelephonyPluginActive(),
),
Expanded(child: shellMainChild),
],
),
TelephonyScreenPopLayer(
businessId: widget.businessId,
authStore: widget.authStore,
pluginActive: _isTelephonyPluginActive(),
),
TelephonyIncomingCallOverlay(
businessId: widget.businessId,
authStore: widget.authStore,
pluginActive: _isTelephonyPluginActive(),
),
],
),
),
);
// Side colors and styles
final Color sideBg = Theme.of(context).brightness == Brightness.dark
? scheme.surfaceContainerHighest
: scheme.surfaceContainerLow;
final Color sideFg = scheme.onSurfaceVariant;
final Color activeBg = scheme.primaryContainer;
final Color activeFg = scheme.onPrimaryContainer;
if (useRail) {
return BusinessShellSideNavScope(
desktopRailSupported: true,
desktopRailVisible: _desktopRailVisible,
setDesktopRailVisible: (visible) => setState(() => _desktopRailVisible = visible),
child: Scaffold(
appBar: preferredAppBar,
body: Row(
children: [
if (_desktopRailVisible) ...[
Container(
width: railExtended ? 240 : 72,
height: double.infinity,
color: sideBg,
child: ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: getTotalMenuItemsCount(),
itemBuilder: (ctx, index) {
// محاسبه ایندکس منو و تشخیص نوع آیتم
int menuIndex = 0;
int childIndex = -1;
bool isChildItem = false;
int currentIndex = 0;
for (int i = 0; i < menuItems.length; i++) {
final item = menuItems[i];
if (currentIndex == index) {
menuIndex = i;
break;
}
currentIndex++;
// نمایش زیرمجموعه‌ها در همه حالت‌ها (Rail و Extended)
if (item.type == _MenuItemType.expandable && isExpanded(item)) {
final childrenCount = item.children?.length ?? 0;
if (index >= currentIndex && index < currentIndex + childrenCount) {
menuIndex = i;
childIndex = index - currentIndex;
isChildItem = true;
break;
}
currentIndex += childrenCount;
}
}
final item = menuItems[menuIndex];
final bool isHovered = index == _hoverIndex;
final bool isSelected = menuIndex == selectedIndex;
final bool active = isSelected || isHovered;
final BorderRadius br = (isSelected && useRail)
? BorderRadius.zero
: (isHovered ? BorderRadius.zero : BorderRadius.circular(8));
final Color bgColor = active
? (isHovered && !isSelected ? activeBg.withValues(alpha: 0.85) : activeBg)
: Colors.transparent;
if (isChildItem && item.children != null && childIndex >= 0 && childIndex < item.children!.length) {
// زیرآیتم با انیمیشن و بهبود بصری
final child = item.children![childIndex];
final bool isChildSelected = child.path != null &&
_businessMenuPathMatchesLocation(location, child.path!, widget.businessId);
final bool isChildHovered = index == _hoverIndex;
final bool isChildActive = isChildSelected || isChildHovered;
final BorderRadius childBr = isChildSelected
? BorderRadius.zero
: (isChildHovered ? BorderRadius.zero : BorderRadius.circular(8));
final Color childBgColor = isChildActive
? (isChildHovered && !isChildSelected
? (isDark ? activeBg.withValues(alpha: 0.5) : activeBg.withValues(alpha: 0.7))
: activeBg)
: Colors.transparent;
return AnimatedContainer(
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: MouseRegion(
onEnter: (_) => setState(() => _hoverIndex = index),
onExit: (_) => setState(() => _hoverIndex = -1),
child: InkWell(
borderRadius: childBr,
onTap: () => onSelectChild(menuIndex, childIndex, longPress: false),
onLongPress: (useRail &&
BusinessPanelUiStore.instance.mode ==
BusinessPanelNavigationMode.tabs &&
BusinessPanelUiStore.instance.sidebarTabBehavior ==
BusinessPanelSidebarTabBehavior.newTabViaLongPress)
? () => onSelectChild(menuIndex, childIndex, longPress: true)
: null,
child: Container(
margin: EdgeInsets.zero,
padding: EdgeInsets.symmetric(
horizontal: railExtended ? 32 : 20,
vertical: 10,
),
decoration: BoxDecoration(
color: childBgColor,
borderRadius: childBr,
),
child: Tooltip(
message: child.label,
waitDuration: const Duration(milliseconds: 500),
child: Row(
mainAxisAlignment: railExtended ? MainAxisAlignment.start : MainAxisAlignment.center,
children: [
_buildSidebarMenuIcon(
child,
color: isChildActive ? activeFg : sideFg,
size: railExtended ? 20 : 22,
active: isChildActive,
),
if (railExtended) ...[
const SizedBox(width: 12),
Expanded(
child: Text(
child.label,
style: TextStyle(
color: isChildActive ? activeFg : sideFg,
fontWeight: isChildActive ? FontWeight.w600 : FontWeight.w400,
fontSize: 13,
),
),
),
if (child.hasAddButton && _canAddForSection(_sectionForLabel(child.label, t)))
GestureDetector(
onTap: () {
// Navigate to add new item
if (child.label == t.personsList) {
showAddPersonDialog();
} else if (child.label == t.products) {
showAddProductDialog();
} else if (child.label == t.categories) {
// Navigate to add category
} else if (child.label == t.productAttributes) {
// Navigate to add product attribute
} else if (child.label == t.accounts) {
showAddBankAccountDialog();
} else if (child.label == t.pettyCash) {
showAddPettyCashDialog();
} else if (child.label == t.cashBox) {
showAddCashBoxDialog();
} else if (child.label == t.wallet) {
showWalletTopUpDialog();
} else if (child.label == t.checks) {
showAddCheckDialog();
} else if (child.label == t.invoice) {
context.go(_bu('invoice/new'));
} else if (child.label == t.receiptsAndPayments) {
showAddReceiptPaymentDialog();
} else if (child.label == t.expenseAndIncome) {
showAddExpenseIncomeDialog();
} else if (child.label == t.warehouses) {
showAddWarehouseDialog();
} else if (child.label == 'حواله‌های انبار') {
showAddWarehouseDocumentDialog();
} else if (child.label == 'کالای هزینه/درآمد شده') {
context.go(_bu('goods-expense-income'));
} else if (child.label == 'سفارش‌های تولید') {
context.go(_bu('production-orders'));
} else if (child.label == 'فرایندها و مراحل قیف') {
context.go('${_bu('crm/process-definitions')}?openAdd=1');
} else if (child.label == 'سرنخ‌ها') {
context.go('${_bu('crm/leads')}?openAdd=1');
} else if (child.label == 'فرصت‌های فروش') {
context.go('${_bu('crm/deals')}?openAdd=1');
} else if (child.label == 'فعالیت‌ها') {
context.go('${_bu('crm/activities')}?openAdd=1');
} else if (child.label == t.loanFacilities) {
showLoanFacilityCreateDialog();
}
},
child: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
color: isChildActive
? activeFg.withValues(alpha: 0.15)
: sideFg.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Icon(
Icons.add,
size: 14,
color: isChildActive ? activeFg : sideFg,
),
),
),
],
],
),
),
),
),
),
);
} else {
// آیتم اصلی (ساده، بازشونده، یا جداکننده)
if (item.type == _MenuItemType.separator) {
// آیتم جداکننده
return Container(
margin: EdgeInsets.symmetric(
horizontal: railExtended ? 16 : 8,
vertical: 12,
),
child: Row(
children: [
if (railExtended) ...[
Expanded(
child: Divider(
color: sideFg.withValues(alpha: 0.3),
thickness: 1,
),
),
const SizedBox(width: 12),
Text(
item.label,
style: TextStyle(
color: sideFg.withValues(alpha: 0.7),
fontSize: 11,
fontWeight: FontWeight.w600,
letterSpacing: 0.5,
),
),
const SizedBox(width: 12),
Expanded(
child: Divider(
color: sideFg.withValues(alpha: 0.3),
thickness: 1,
),
),
] else ...[
Expanded(
child: Divider(
color: sideFg.withValues(alpha: 0.3),
thickness: 1,
),
),
],
],
),
);
} else {
// آیتم ساده یا آیتم بازشونده
Widget menuItemWidget = MouseRegion(
onEnter: (_) => setState(() => _hoverIndex = index),
onExit: (_) => setState(() => _hoverIndex = -1),
child: InkWell(
borderRadius: br,
onTap: () {
if (item.type == _MenuItemType.expandable) {
setState(() => _toggleExpandableMenu(item));
} else {
onSelect(menuIndex, longPress: false);
}
},
onLongPress: (!useRail ||
item.type != _MenuItemType.simple ||
item.path == null ||
BusinessPanelUiStore.instance.mode !=
BusinessPanelNavigationMode.tabs ||
BusinessPanelUiStore.instance.sidebarTabBehavior !=
BusinessPanelSidebarTabBehavior.newTabViaLongPress)
? null
: () => onSelect(menuIndex, longPress: true),
child: Container(
margin: EdgeInsets.zero,
padding: EdgeInsets.symmetric(
horizontal: railExtended ? 16 : 0,
vertical: 12,
),
decoration: BoxDecoration(
color: bgColor,
borderRadius: br,
),
child: Row(
mainAxisAlignment: railExtended ? MainAxisAlignment.start : MainAxisAlignment.center,
children: [
Stack(
clipBehavior: Clip.none,
children: [
_buildSidebarMenuIcon(
item,
color: active ? activeFg : sideFg,
size: railExtended ? 24 : 28,
active: active,
),
// آیکون expand/collapse کوچک در گوشه برای حالت Rail
if (!railExtended && item.type == _MenuItemType.expandable)
Positioned(
right: -4,
bottom: -4,
child: Container(
width: 14,
height: 14,
decoration: BoxDecoration(
color: sideBg,
shape: BoxShape.circle,
border: Border.all(
color: sideFg.withValues(alpha: 0.3),
width: 1,
),
),
child: AnimatedRotation(
turns: isExpanded(item) ? 0.5 : 0,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: Icon(
Icons.expand_more,
color: sideFg,
size: 10,
),
),
),
),
],
),
if (railExtended) ...[
const SizedBox(width: 12),
Expanded(
child: Text(
item.label,
style: TextStyle(
color: active ? activeFg : sideFg,
fontWeight: active ? FontWeight.w600 : FontWeight.w500,
fontSize: 14,
),
),
),
if (item.type == _MenuItemType.expandable)
AnimatedRotation(
turns: isExpanded(item) ? 0.5 : 0,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: Icon(
Icons.expand_more,
color: sideFg,
size: 20,
),
)
else if (item.hasAddButton)
Builder(builder: (ctx) {
final section = _sectionForLabel(item.label, t);
final canAdd = section != null && (widget.authStore.hasBusinessPermission(section, 'add'));
if (!canAdd) return const SizedBox.shrink();
return GestureDetector(
onTap: () {
if (item.label == t.people) {
showAddPersonDialog();
} else if (item.label == t.accounts) {
showAddBankAccountDialog();
} else if (item.label == t.cashBox) {
showAddCashBoxDialog();
} else if (item.label == t.invoice) {
context.go(_bu('invoice/new'));
} else if (item.label == t.receiptsAndPayments) {
showAddReceiptPaymentDialog();
} else if (item.label == t.expenseAndIncome) {
showAddExpenseIncomeDialog();
} else if (item.label == t.transfers) {
showAddTransferDialog();
} else if (item.label == t.checks) {
showAddCheckDialog();
} else if (item.label == t.documents) {
showAddDocumentDialog();
}
},
child: Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: sideFg.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Icon(
Icons.add,
size: 16,
color: sideFg,
),
),
);
}),
],
],
),
),
),
);
// اضافه کردن Tooltip برای حالت Rail (عرض کم)
if (!railExtended) {
menuItemWidget = Tooltip(
message: item.label,
waitDuration: const Duration(milliseconds: 500),
child: menuItemWidget,
);
}
return menuItemWidget;
}
}
},
),
),
const VerticalDivider(thickness: 1, width: 1),
],
Expanded(child: content),
],
),
),
);
}
return BusinessShellSideNavScope(
desktopRailSupported: false,
desktopRailVisible: false,
setDesktopRailVisible: (_) {},
child: Scaffold(
appBar: preferredAppBar,
drawer: Drawer(
backgroundColor: sideBg,
child: SafeArea(
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 8),
children: [
if (launcherHomePath != null) ...[
ListTile(
leading: Icon(Icons.apps_rounded, color: sideFg),
title: Text(
t.businessShellBackToLauncher,
style: TextStyle(color: sideFg, fontWeight: FontWeight.w600),
),
onTap: () {
context.pop();
context.go(launcherHomePath);
},
),
const Divider(),
],
// آیتم‌های منو
for (int i = 0; i < menuItems.length; i++) ...[
Builder(builder: (ctx) {
final item = menuItems[i];
final bool active = i == selectedIndex;
if (item.type == _MenuItemType.separator) {
// آیتم جداکننده در منوی موبایل
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Expanded(
child: Divider(
color: sideFg.withValues(alpha: 0.3),
thickness: 1,
),
),
const SizedBox(width: 12),
Text(
item.label,
style: TextStyle(
color: sideFg.withValues(alpha: 0.7),
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 12),
Expanded(
child: Divider(
color: sideFg.withValues(alpha: 0.3),
thickness: 1,
),
),
],
),
);
} else if (item.type == _MenuItemType.simple) {
final section = _sectionForLabel(item.label, t);
final canAdd = section != null && (widget.authStore.hasBusinessPermission(section, 'add'));
return ListTile(
leading: _buildSidebarMenuIcon(
item,
color: active ? activeFg : sideFg,
size: 24,
active: active,
),
title: Text(item.label, style: TextStyle(color: active ? activeFg : sideFg, fontWeight: active ? FontWeight.w600 : FontWeight.w400)),
selected: active,
selectedTileColor: activeBg,
trailing: (item.hasAddButton && canAdd)
? GestureDetector(
onTap: () {
context.pop();
// در حال حاضر فقط اشخاص پشتیبانی می‌شود
if (item.label == t.people) {
showAddPersonDialog();
} else if (item.label == t.invoice) {
// Navigate to add invoice
context.go(_bu('invoice/new'));
} else if (item.label == t.expenseAndIncome) {
// Show add expense/income dialog
showAddExpenseIncomeDialog();
} else if (item.label == t.transfers) {
// Show add transfer dialog
showAddTransferDialog();
} else if (item.label == t.checks) {
// Show add check dialog
showAddCheckDialog();
} else if (item.label == t.documents) {
// Show add document dialog
showAddDocumentDialog();
}
},
child: Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: sideFg.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Icon(Icons.add, size: 16, color: sideFg),
),
)
: null,
onTap: () {
context.pop();
onSelect(i);
},
);
} else if (item.type == _MenuItemType.expandable) {
// فیلتر کردن زیرآیتم‌ها بر اساس دسترسی
final visibleChildren = (item.children ?? []).where((child) => _hasAccessToMenuItem(child)).toList();
return ExpansionTile(
leading: _buildSidebarMenuIcon(
item,
color: sideFg,
size: 24,
active: false,
),
title: Text(item.label, style: TextStyle(color: sideFg)),
initiallyExpanded: isExpanded(item),
onExpansionChanged: (expanded) {
setState(() => _setExpandableMenuOpen(item, expanded));
},
children: visibleChildren.map((child) {
final childSection = _sectionForLabel(child.label, t);
final childCanAdd = child.hasAddButton && _canAddForSection(childSection);
return ListTile(
leading: const SizedBox(width: 24),
title: Text(child.label),
trailing: childCanAdd ? GestureDetector(
onTap: () {
context.pop();
// Navigate to add new item
if (child.label == t.products) {
// Show add product dialog
showAddProductDialog();
} else if (child.label == t.categories) {
// Navigate to add category
} else if (child.label == t.productAttributes) {
// Navigate to add product attribute
} else if (child.label == t.accounts) {
// Open add bank account dialog
showAddBankAccountDialog();
} else if (child.label == t.pettyCash) {
// Open add petty cash dialog
showAddPettyCashDialog();
} else if (child.label == t.cashBox) {
// Open add cash register dialog
showAddCashBoxDialog();
} else if (child.label == t.wallet) {
// Show wallet top-up dialog
showWalletTopUpDialog();
} else if (child.label == t.checks) {
// Navigate to add check
} else if (child.label == t.invoice) {
// Navigate to add invoice
context.go(_bu('invoice/new'));
} else if (child.label == t.receiptsAndPayments) {
// Show add receipt payment dialog
showAddReceiptPaymentDialog();
} else if (child.label == t.expenseAndIncome) {
// Show add expense/income dialog
showAddExpenseIncomeDialog();
} else if (child.label == t.warehouses) {
// Show add warehouse dialog
showAddWarehouseDialog();
} else if (child.label == 'حواله‌های انبار') {
// Show add warehouse document dialog
showAddWarehouseDocumentDialog();
} else if (child.label == 'سفارش‌های تولید') {
context.go(_bu('production-orders'));
} else if (child.label == 'فرایندها و مراحل قیف') {
context.go('${_bu('crm/process-definitions')}?openAdd=1');
} else if (child.label == 'سرنخ‌ها') {
context.go('${_bu('crm/leads')}?openAdd=1');
} else if (child.label == 'فرصت‌های فروش') {
context.go('${_bu('crm/deals')}?openAdd=1');
} else if (child.label == 'فعالیت‌ها') {
context.go('${_bu('crm/activities')}?openAdd=1');
} else if (child.label == t.loanFacilities) {
showLoanFacilityCreateDialog();
}
},
child: Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: sideFg.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Icon(
Icons.add,
size: 16,
color: sideFg,
),
),
) : null,
onTap: () {
context.pop();
onSelectChild(i, item.children!.indexOf(child));
},
);
}).toList(),
);
}
return const SizedBox.shrink();
}),
],
const Divider(),
ListTile(
leading: const Icon(Icons.logout),
title: Text(t.logout),
onTap: onLogout,
),
],
),
),
),
body: content,
),
);
}
Future<void> _handleInvoiceWizardResult(WarehouseDocWizardResult wizardResult) async {
if (wizardResult.invoiceId == null) return;
final apiClient = ApiClient();
final invoiceService = InvoiceService(apiClient: apiClient);
bool loaderDismissed = false;
void dismissLoader() {
if (!loaderDismissed && mounted) {
loaderDismissed = true;
Navigator.of(context, rootNavigator: true).pop();
}
}
showDialog(
context: context,
barrierDismissible: false,
builder: (_) => const Center(child: CircularProgressIndicator()),
).then((_) => loaderDismissed = true);
try {
final invoiceData = await invoiceService.getInvoice(
businessId: widget.businessId,
invoiceId: wizardResult.invoiceId!,
);
final warehouseService = WarehouseService(apiClient: apiClient);
final quantitiesData = await warehouseService.getInvoiceLineQuantities(
businessId: widget.businessId,
invoiceId: wizardResult.invoiceId!,
);
dismissLoader();
if (!mounted) return;
final invoiceItem = Map<String, dynamic>.from(invoiceData['item'] ?? const {});
final quantities = InvoiceLineQuantitiesIndex.fromApiResponse(quantitiesData);
final initialLines = extractWarehouseLinesFromInvoice(
invoiceItem,
wizardResult.docType ?? 'issue',
quantities: quantities,
);
if (initialLines.isEmpty) {
SnackBarHelper.showInfo(
context,
message: 'هیچ کالایی برای این فاکتور ثبت نشده است',
);
return;
}
if (!quantities.hasAnyRemaining) {
SnackBarHelper.showInfo(
context,
message: 'همه اقلام این فاکتور قبلاً حواله شده‌اند',
);
return;
}
final calendarController = widget.calendarController ?? await CalendarController.load();
await showDialog(
context: context,
builder: (_) => WarehouseDocumentFormDialog(
businessId: widget.businessId,
calendarController: calendarController,
initialDocType: wizardResult.docType,
lockDocType: true,
initialLines: initialLines,
sourceInvoiceId: wizardResult.invoiceId,
sourceInvoiceCode: wizardResult.invoiceCode,
sourceInvoiceType: wizardResult.sourceLabel,
onSuccess: () => _refreshCurrentPage(),
),
);
} catch (e) {
dismissLoader();
if (!mounted) return;
SnackBarHelper.showError(
context,
message: 'خطا در دریافت فاکتور: ${ErrorExtractor.forContext(e, context)}',
);
} finally {
dismissLoader();
}
}
String _expandableMenuKey(_MenuItem item) {
final key = item.key?.trim();
if (key != null && key.isNotEmpty) return key;
return item.label;
}
bool _isExpandableMenuOpen(_MenuItem item) =>
_expandedMenuByKey[_expandableMenuKey(item)] ?? false;
void _setExpandableMenuOpen(_MenuItem item, bool open) {
_expandedMenuByKey[_expandableMenuKey(item)] = open;
}
void _toggleExpandableMenu(_MenuItem item) {
final key = _expandableMenuKey(item);
_expandedMenuByKey[key] = !(_expandedMenuByKey[key] ?? false);
}
Widget _buildSidebarMenuIcon(
_MenuItem item, {
required Color color,
required double size,
required bool active,
}) {
if (item.key == 'telephony') {
return BusinessShellTelephonyGlyph(
color: color,
size: size,
filled: active,
);
}
return Icon(
active ? item.selectedIcon : item.icon,
color: color,
size: size,
);
}
String _menuKey(_MenuItem item) {
if (item.key != null && item.key!.trim().isNotEmpty) {
return item.key!;
}
final p = item.path;
if (p != null && p.trim().isNotEmpty) {
final normalized = p.split('?').first;
final tail = BusinessRoutePaths.stripBusinessPrefixAndTab(normalized, widget.businessId);
if (tail.isNotEmpty) return tail;
}
if (item.type == _MenuItemType.expandable) {
final children = item.children ?? const <_MenuItem>[];
for (final child in children) {
final kp = child.path;
if (kp == null || kp.isEmpty) continue;
final childTail = BusinessRoutePaths.stripBusinessPrefixAndTab(kp.split('?').first, widget.businessId);
if (childTail.isNotEmpty) {
final segment = childTail.split('/').first;
if (segment.isNotEmpty) return 'group:$segment';
}
}
}
return 'label:${item.label.trim()}';
}
List<_MenuItem> _applyMenuPreferences(List<_MenuItem> items) {
final hidden = _menuPreferences.hiddenKeys.toSet();
List<_MenuItem> applyChildren(_MenuItem parent) {
final children = parent.children ?? const <_MenuItem>[];
if (children.isEmpty) return children;
final parentKey = _menuKey(parent);
final order = _menuPreferences.childrenOrder[parentKey] ?? const <String>[];
final filtered = children.where((child) => !hidden.contains(_menuKey(child))).toList();
if (order.isEmpty) return filtered;
final byKey = <String, _MenuItem>{for (final it in filtered) _menuKey(it): it};
final out = <_MenuItem>[];
for (final key in order) {
final found = byKey.remove(key);
if (found != null) out.add(found);
}
out.addAll(byKey.values);
return out;
}
final visibleRoot = items
.where((item) =>
item.type == _MenuItemType.separator || !hidden.contains(_menuKey(item)))
.map((item) => item.type == _MenuItemType.expandable
? item.copyWith(children: applyChildren(item))
: item)
.toList();
final order = _menuPreferences.rootOrder;
if (order.isEmpty) return visibleRoot;
final byKey = <String, _MenuItem>{for (final it in visibleRoot) _menuKey(it): it};
final nonSepKeys =
byKey.entries.where((e) => e.value.type != _MenuItemType.separator).map((e) => e.key).toSet();
// اگر ترجیحات قدیمی/ناسازگار باشند، ترتیب پیش‌فرض فعلی حفظ شود (جداکننده‌ها در محاسبه لحاظ نمی‌شوند).
final knownNonSep =
order.where(nonSepKeys.contains).length;
final knownCount = knownNonSep;
if (knownCount < 3 || knownCount * 3 < byKey.length) {
return visibleRoot;
}
final out = <_MenuItem>[];
for (final key in order) {
final found = byKey.remove(key);
if (found != null) out.add(found);
}
out.addAll(byKey.values);
return out;
}
// فیلتر کردن منو بر اساس دسترسی‌ها
List<_MenuItem> _getFilteredMenuItems(List<_MenuItem> allItems) {
final filteredItems = allItems.where((item) {
if (item.type == _MenuItemType.separator) {
return true;
}
if (item.type == _MenuItemType.simple) {
final hasAccess = _hasAccessToMenuItem(item);
return hasAccess;
}
if (item.type == _MenuItemType.expandable) {
final hasAccess = _hasAccessToExpandableMenuItem(item);
return hasAccess;
}
return false;
}).toList();
return filteredItems;
}
bool _hasAccessToMenuItem(_MenuItem item) {
final t = AppLocalizations.of(context);
final section = _sectionForMenuItem(item, t);
if (item.path != null && item.path!.contains('/woocommerce')) {
if (!_isWooCommerceHesabixPluginActive()) {
return false;
}
if (widget.authStore.currentBusiness?.isOwner == true) {
return true;
}
return widget.authStore.hasBusinessPermission('woocommerce', 'view');
}
if (item.path != null && item.path!.contains('/digipay')) {
if (!_isDigipayPluginActive()) {
return false;
}
if (widget.authStore.currentBusiness?.isOwner == true) {
return true;
}
return widget.authStore.hasBusinessPermission('digipay', 'view');
}
if (item.path != null && item.path!.contains('/crm/web-chat')) {
if (widget.authStore.currentBusiness?.isOwner == true) return true;
return widget.authStore.canViewCrmWebChat();
}
// داشبورد اصلی کسب‌وکار همیشه قابل مشاهده است (داشبورد CRM تابع canReadSection('crm') است)
if (item.path != null &&
item.path!.endsWith('/dashboard') &&
!item.path!.contains('/crm/')) {
return true;
}
// بررسی فعال بودن پلاگین گارانتی
if (section == 'warranty') {
if (!_showPluginGatedMenu(_isWarrantyPluginActive())) {
return false;
}
}
// بررسی فعال بودن پلاگین تعمیرگاه
if (section == 'repair_shop') {
if (!_showPluginGatedMenu(_isRepairShopPluginActive())) {
return false;
}
}
// باشگاه مشتریان
if (section == 'customer_club') {
if (!_showPluginGatedMenu(_isCustomerClubPluginActive())) {
return false;
}
}
// پخش مویرگی
if (section == 'distribution') {
if (!_showPluginGatedMenu(_isDistributionPluginActive())) {
return false;
}
}
// حقوق و دستمزد
if (section == 'payroll') {
if (!_showPluginGatedMenu(_isPayrollPluginActive())) {
return false;
}
}
if (section == 'office_automation') {
if (!_showPluginGatedMenu(_isOfficeAutomationPluginActive())) {
return false;
}
}
if (section == 'fixed_assets') {
if (!_showPluginGatedMenu(_isFixedAssetsPluginActive())) {
return false;
}
}
// طراحی برچسب بارکد
if (section == 'barcode_labels') {
if (!_showPluginGatedMenu(_isPluginCodeLicensed('barcode_label_studio'))) {
return false;
}
}
// مرکز تماس استریسک/ایزابل
if (section == 'telephony') {
if (!_showPluginGatedMenu(_isTelephonyPluginActive())) {
return false;
}
}
// اتصال باسلام
if (section == 'basalam') {
if (!_showPluginGatedMenu(_isBasalamPluginActive())) {
return false;
}
}
// سامانه مودیان
if (section == 'moadian') {
if (!_showPluginGatedMenu(_isMoadianPluginActive())) {
return false;
}
}
// اگر سکشن تعریف نشده، نمایش داده نشود
if (section == null) {
return false;
}
// بررسی دسترسی‌های مختلف برای نمایش منو
// اگر کاربر مالک است، همه منوها قابل مشاهده هستند
if (_isBusinessOwner()) {
return true;
}
// برای کاربران عضو، بررسی دسترسی
// تنظیمات: نیازمند دسترسی join
if (section == 'settings' && item.label == AppLocalizations.of(context).settings) {
final hasJoin = widget.authStore.hasBusinessPermission('settings', 'join');
final canManageDefaultShortcuts = widget.authStore.hasBusinessPermission(
'quick_sales',
'manage_default_payment_shortcuts',
);
return hasJoin || canManageDefaultShortcuts;
}
// استعلامات: نیازمند دسترسی read برای settings
if (section == 'settings' && (item.label == 'استعلامات' || item.label == 'Inquiries')) {
final hasRead = widget.authStore.hasBusinessPermission('settings', 'read') ||
widget.authStore.hasBusinessPermission('settings', 'join');
return hasRead;
}
// سایر سکشن‌ها: بررسی دسترسی view
final hasAccess = widget.authStore.canReadSection(section);
// Debug: بررسی دقیق‌تر دسترسی‌ها
// viewPerm is checked implicitly through hasAccess
return hasAccess;
}
bool _hasAccessToExpandableMenuItem(_MenuItem item) {
if (item.children == null) {
return false;
}
// اگر حداقل یکی از زیرآیتم‌ها قابل دسترسی باشد، منو نمایش داده شود
final hasAccess = item.children!.any((child) => _hasAccessToMenuItem(child));
return hasAccess;
}
/// بررسی دسترسی افزودن برای یک سکشن (CRM از write و بقیه از add استفاده می‌کنند)
bool _canAddForSection(String? section) {
if (section == null) return false;
if (section == 'crm') {
return widget.authStore.hasBusinessPermission(section, 'write');
}
return widget.authStore.hasBusinessPermission(section, 'add');
}
// تبدیل کلید/برچسب منو به کلید سکشن دسترسی
String? _sectionForMenuItem(_MenuItem item, AppLocalizations t) {
switch (item.key) {
case 'hscript':
return 'reports';
case 'payroll':
return 'payroll';
case 'office-automation':
case 'group:office-automation':
return 'office_automation';
case 'fixed-assets':
return 'fixed_assets';
case 'barcode-labels':
return 'barcode_labels';
case 'telephony':
return 'telephony';
case 'customer-club':
return 'customer_club';
case 'repair-shop':
return 'repair_shop';
case 'warranty':
return 'warranty';
case 'distribution':
return 'distribution';
case 'tax-workspace':
return 'moadian';
case 'plugin-marketplace':
return 'marketplace';
}
final path = item.path;
if (path != null) {
if (path.contains('/hscript')) return 'reports';
if (path.contains('/payroll')) return 'payroll';
if (path.contains('/office-automation')) return 'office_automation';
if (path.contains('/fixed-assets')) return 'fixed_assets';
if (path.contains('/barcode-labels')) return 'barcode_labels';
if (path.contains('/telephony')) return 'telephony';
if (path.contains('/customer-club')) return 'customer_club';
if (path.contains('/repair-shop')) return 'repair_shop';
if (path.contains('/warranty')) return 'warranty';
if (path.contains('/distribution')) return 'distribution';
if (path.contains('/tax-workspace')) return 'moadian';
}
return _sectionForLabel(item.label, t);
}
// تبدیل برچسب محلی‌شده منو به کلید سکشن دسترسی
String? _sectionForLabel(String label, AppLocalizations t) {
if (label == t.reports) return 'reports';
if (label == 'گزارش‌ساز اسکریپتی' || label == 'HScript Reports') return 'reports';
if (label == t.people) return 'people';
if (label == 'CRM' ||
label == 'داشبورد' ||
label == 'فرایندها و مراحل قیف' ||
label == 'فرایندها و مراحل قیف' ||
label == 'سرنخ‌ها' ||
label == 'فرصت‌های فروش' ||
label == 'فعالیت‌ها' ||
label == 'گزارشات' ||
label == t.crmMenuNotesCalendar ||
label == 'چت وب') {
return 'crm';
}
if (label == t.products) return 'products';
if (label == 'باندل‌های کالا' || label == 'Product bundles') return 'products';
if (label == t.categories) return 'categories';
if (label == t.productAttributes) return 'product_attributes';
if (label == t.accounts) return 'bank_accounts';
if (label == t.pettyCash) return 'petty_cash';
if (label == t.cashBox) return 'cash';
if (label == t.wallet) return 'wallet';
if (label == t.loanFacilities) return 'loan_facilities';
if (label == t.checks) return 'checks';
if (label == 'فروش سریع') return 'invoices'; // فروش سریع نیازمند دسترسی invoices.add است
if (label == t.invoice) return 'invoices';
if (label == t.receiptsAndPayments) return 'people_transactions';
if (label == t.expenseAndIncome) return 'expenses_income';
if (label == t.transfers) return 'transfers';
if (label == t.documents) return 'accounting_documents';
if (label == t.yearEndClosing) return 'fiscal_years';
if (label == t.chartOfAccounts) return 'chart_of_accounts';
if (label == t.openingBalance) return 'opening_balance';
if (label == t.currencyRevaluation) return 'currency_revaluation';
if (label == t.warehouses) return 'warehouses';
if (label == 'حواله‌های انبار') return 'warehouse_transfers';
// انبارگردانی (Stock Count) در نهایت به ایجاد/مدیریت حواله‌های تعدیل منجر می‌شود؛
// بنابراین در مدل دسترسی فعلی زیر مجموعه‌ی warehouse_transfers در نظر گرفته می‌شود.
if (label == 'انبار گردانی' || label == 'انبارگردانی' || label == 'Stock Count') return 'warehouse_transfers';
if (label == 'مغایرت‌های موجودی فروش سریع') return 'inventory';
if (label == 'کالای هزینه/درآمد شده' ||
label == 'کالای هزینه‌شده / کالای درآمدشده' ||
label == 'Goods Expense/Income') {
return 'goods_expense_income';
}
if (label == 'سفارش‌های تولید' || label == 'Production Orders') {
return 'inventory';
}
if (label == t.storageSpace) return 'storage';
if (label == t.taxpayers) return 'moadian';
if (label == t.settings) return 'settings';
if (label == t.pluginMarketplace) return 'marketplace';
if (label == t.warranty || label == 'گارانتی' || label == 'Warranty') return 'warranty';
if (label == t.repairShopMenu || label == 'تعمیرگاه' || label == 'Repair Shop') return 'repair_shop';
if (label == t.customerClubMenu || label == 'Customer Club') return 'customer_club';
if (label == t.payrollMenu ||
label == t.payrollTitle ||
label == 'Payroll' ||
label == 'حقوق و دستمزد') {
return 'payroll';
}
if (label == t.oaMenu ||
label == t.oaOrg ||
label == t.oaCartable ||
label == t.oaExternalOrgs ||
label == t.oaArchiveTree ||
label == t.oaReports ||
label == 'Office automation' ||
label == 'اتوماسیون اداری') {
return 'office_automation';
}
if (label == t.fixedAssetsMenu ||
label == t.fixedAssetsTitle ||
label == 'Fixed assets' ||
label == 'اموال و دارایی ثابت') {
return 'fixed_assets';
}
if (label == t.distributionMenu || label == 'Field distribution') return 'distribution';
if (label == t.telephonyMenu || label == 'مرکز تماس' || label == 'Telephony') return 'telephony';
if (label == t.basalamIntegrationMenuTitle) return 'basalam';
if (label == t.woocommerceIntegrationMenuTitle) return 'woocommerce';
if (label == t.digipayMenuTitle) return 'digipay';
if (label == 'هوش مصنوعی' || label == 'AI Tools') return 'ai';
if (label == 'چت با AI' || label == 'AI Chat') return 'ai';
if (label == 'اشتراک AI' || label == 'AI Subscription') return 'ai';
if (label == 'آمار استفاده' || label == 'AI Usage') return 'ai';
if (label == 'استعلامات' || label == 'Inquiries') return 'settings';
if (label == _workflowMenuLabel(t)) return 'settings';
return null;
}
String _workflowMenuLabel(AppLocalizations t) {
return t.localeName.startsWith('fa') ? 'اتوماسیون‌ها' : 'Automations';
}
}
enum _MenuItemType { simple, expandable, separator }
class _MenuItem {
final String? key;
final String label;
final IconData icon;
final IconData selectedIcon;
final String? path;
final _MenuItemType type;
final List<_MenuItem>? children;
final bool hasAddButton;
const _MenuItem({
this.key,
required this.label,
required this.icon,
required this.selectedIcon,
this.path,
required this.type,
this.children,
this.hasAddButton = false,
});
_MenuItem copyWith({
String? key,
String? label,
IconData? icon,
IconData? selectedIcon,
String? path,
_MenuItemType? type,
List<_MenuItem>? children,
bool? hasAddButton,
}) {
return _MenuItem(
key: key ?? this.key,
label: label ?? this.label,
icon: icon ?? this.icon,
selectedIcon: selectedIcon ?? this.selectedIcon,
path: path ?? this.path,
type: type ?? this.type,
children: children ?? this.children,
hasAddButton: hasAddButton ?? this.hasAddButton,
);
}
}