import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/provider/account.dart';

import 'package:pweb/widgets/sidebar/destinations.dart';
import 'package:pweb/widgets/sidebar/side_menu.dart';
import 'package:pweb/widgets/sidebar/user.dart';


class PayoutSidebar extends StatelessWidget {
  const PayoutSidebar({
    super.key,
    required this.selected,
    required this.onSelected,
    this.onLogout,
    this.userName,
    this.avatarUrl,
    this.items,
  });

  final PayoutDestination selected;
  final ValueChanged<PayoutDestination> onSelected;
  final Future<void> Function()? onLogout;

  final String? userName;
  final String? avatarUrl;
  final List<PayoutDestination>? items;

  @override
  Widget build(BuildContext context) {
    final accountName = context.select<AccountProvider, String?>(
      (provider) => provider.account?.fullName,
    );
    final accountAvatar = context.select<AccountProvider, String?>(
      (provider) => provider.account?.avatarUrl,
    );
    final resolvedUserName = userName ?? accountName;
    final resolvedAvatarUrl = avatarUrl ?? accountAvatar;

    final menuItems =
        items ??
        <PayoutDestination>[
          PayoutDestination.dashboard,
          PayoutDestination.recipients,
          PayoutDestination.invitations,
          PayoutDestination.reports,
          // PayoutDestination.methods,
          // PayoutDestination.organizationSettings,
          //TODO Add when ready
        ];

    final theme = Theme.of(context);

    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        UserProfileCard(
          theme: theme,
          avatarUrl: resolvedAvatarUrl,
          userName: resolvedUserName,
          selected: selected,
          onSelected: onSelected,
        ),
        const SizedBox(height: 8),
        SideMenuColumn(
          theme: theme,
          avatarUrl: resolvedAvatarUrl,
          userName: resolvedUserName,
          items: menuItems,
          selected: selected,
          onSelected: onSelected,
        ),
      ],
    );
  }
}
