// lib/features/admin/tabs/faq/admin_faq_main_tab.dart

/*import 'package:flutter/material.dart';
import 'published_faq_sub_tab.dart';
import 'draft_faq_sub_tab.dart';

const Color _standardGold = Color.fromARGB(255, 204, 117, 4);
const Color _darkGreen = Color.fromARGB(255, 2, 105, 48);

// =====================================================================
// HOVER WRAPPER WIDGETS
// =====================================================================
class FaqHoverClickable extends StatefulWidget {
  final Widget Function(bool isHovered) builder;
  final VoidCallback? onTap;

  const FaqHoverClickable({super.key, required this.builder, this.onTap});

  @override
  State<FaqHoverClickable> createState() => _FaqHoverClickableState();
}

class _FaqHoverClickableState extends State<FaqHoverClickable> {
  bool _isHovered = false;

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (_) => setState(() => _isHovered = true),
      onExit: (_) => setState(() => _isHovered = false),
      cursor: widget.onTap != null ? SystemMouseCursors.click : SystemMouseCursors.basic,
      child: GestureDetector(
        onTap: widget.onTap,
        child: widget.builder(_isHovered),
      ),
    );
  }
}

class FaqHoverMenuLink extends StatefulWidget {
  final String title;
  final IconData icon;
  final bool isSelected;
  final VoidCallback onTap;

  const FaqHoverMenuLink({
    super.key,
    required this.title,
    required this.icon,
    required this.isSelected,
    required this.onTap,
  });

  @override
  State<FaqHoverMenuLink> createState() => _FaqHoverMenuLinkState();
}

class _FaqHoverMenuLinkState extends State<FaqHoverMenuLink> {
  bool _isHovered = false;

  @override
  Widget build(BuildContext context) {
    final showHighlight = _isHovered || widget.isSelected;

    return MouseRegion(
      onEnter: (_) => setState(() => _isHovered = true),
      onExit: (_) => setState(() => _isHovered = false),
      cursor: SystemMouseCursors.click,
      child: GestureDetector(
        onTap: widget.onTap,
        child: AnimatedContainer(
          duration: const Duration(milliseconds: 150),
          padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 18),
          decoration: BoxDecoration(
            color: widget.isSelected 
                ? _darkGreen.withOpacity(0.08) 
                : (_isHovered ? Colors.grey.shade50 : Colors.transparent),
            border: Border(
              left: BorderSide(
                color: showHighlight ? _standardGold : Colors.transparent,
                width: 4,
              ),
            ),
          ),
          child: Row(
            children: [
              Icon(
                widget.icon,
                color: widget.isSelected ? _darkGreen : Colors.grey.shade500,
                size: 22,
              ),
              const SizedBox(width: 16),
              Text(
                widget.title,
                style: TextStyle(
                  fontSize: 14,
                  fontWeight: widget.isSelected ? FontWeight.bold : FontWeight.w600,
                  color: widget.isSelected ? _darkGreen : Colors.grey.shade700,
                  letterSpacing: 0.5,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// =====================================================================
// MAIN FAQ DASHBOARD SHELL
// =====================================================================
class AdminFaqMainTab extends StatefulWidget {
  const AdminFaqMainTab({super.key});

  @override
  State<AdminFaqMainTab> createState() => _AdminFaqMainTabState();
}

class _AdminFaqMainTabState extends State<AdminFaqMainTab> {
  int _currentViewIndex = 0;
  bool _showHeader = false; 
  bool _isSidebarOpen = false;

  final List<String> _menuItems = [
    'Published FAQs',
    'Drafts & Hidden',
  ];

  final List<IconData> _menuIcons = [
    Icons.public_rounded,
    Icons.visibility_off_rounded,
  ];

  void _switchTab(int index) {
    setState(() {
      _currentViewIndex = index;
      _isSidebarOpen = false; 
    });
  }

  void _toggleSidebar() {
    setState(() {
      _isSidebarOpen = !_isSidebarOpen;
    });
  }

  Widget _getCurrentTab() {
    switch (_currentViewIndex) {
      case 0: return const PublishedFaqSubTab(key: ValueKey(0));
      case 1: return const DraftFaqSubTab(key: ValueKey(1));
      default: return const PublishedFaqSubTab(key: ValueKey(0));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey.shade100,
      body: LayoutBuilder(
        builder: (context, constraints) {
          final isDesktop = constraints.maxWidth > 800;

          return Stack(
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  AnimatedSize(
                    duration: const Duration(milliseconds: 500),
                    curve: Curves.fastOutSlowIn,
                    alignment: Alignment.topCenter,
                    clipBehavior: Clip.hardEdge,
                    child: _showHeader 
                      ? Container(
                          decoration: BoxDecoration(
                            color: Colors.white,
                            border: Border(bottom: BorderSide(color: Colors.grey.shade300, width: 1)),
                          ),
                          padding: const EdgeInsets.all(24.0),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: Row(
                                  children: [
                                     FaqHoverClickable(
                                       onTap: _toggleSidebar,
                                       builder: (isHovered) => Container(
                                         padding: const EdgeInsets.all(8),
                                         margin: const EdgeInsets.only(right: 16),
                                         decoration: BoxDecoration(
                                           color: isHovered ? Colors.grey.shade100 : Colors.transparent,
                                           border: Border.all(color: Colors.grey.shade300),
                                           borderRadius: BorderRadius.zero,
                                         ),
                                         child: const Icon(Icons.menu_rounded, color: _darkGreen, size: 28),
                                       ),
                                     ),
                                    const SizedBox(width: 16),
                                    Expanded(
                                      child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RichText(
                                            text: TextSpan(
                                              children: [
                                                TextSpan(text: 'ROCKVIEW ', style: TextStyle(color: _darkGreen, fontSize: isDesktop ? 24 : 18, fontWeight: FontWeight.w900, letterSpacing: 1.2)),
                                                TextSpan(text: 'KNOWLEDGE BASE', style: TextStyle(color: _standardGold, fontSize: isDesktop ? 24 : 18, fontWeight: FontWeight.w400, letterSpacing: 1.2)),
                                              ],
                                            ),
                                          ),
                                          const SizedBox(height: 8),
                                          Row(
                                            children: [
                                              Container(width: 8, height: 8, decoration: const BoxDecoration(color: Colors.green, shape: BoxShape.circle)),
                                              const SizedBox(width: 8),
                                              Text('System Online & Synchronized', style: TextStyle(fontSize: isDesktop ? 13 : 11, color: Colors.grey.shade600, fontWeight: FontWeight.w600)),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              if (isDesktop) _buildSharpCollapseButton(onTap: () => setState(() => _showHeader = false)),
                            ],
                          ),
                        )
                      : const SizedBox(width: double.infinity, height: 0.0),
                  ),

                  if (!_showHeader) const SizedBox(height: 48), 
                  
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.only(top: 24.0),
                      child: AnimatedSwitcher(
                        duration: const Duration(milliseconds: 400),
                        switchInCurve: Curves.easeOutCubic,
                        switchOutCurve: Curves.easeInCubic,
                        transitionBuilder: (Widget child, Animation<double> animation) {
                          final slideAnimation = Tween<Offset>(begin: const Offset(-0.05, 0.0), end: Offset.zero).animate(animation);
                          final fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(animation);
                          return FadeTransition(opacity: fadeAnimation, child: SlideTransition(position: slideAnimation, child: child));
                        },
                        child: _getCurrentTab(),
                      ),
                    ),
                  ),
                ],
              ),
              
              if (!_showHeader) Positioned(top: 24, left: 24, child: _buildFloatingHamburger()),
              if (!_showHeader) Positioned(top: 0, left: 0, right: 0, child: Center(child: _buildChevron(onTap: () => setState(() => _showHeader = true)))),
              if (_isSidebarOpen) Positioned.fill(child: GestureDetector(onTap: _toggleSidebar, child: Container(color: Colors.black.withOpacity(0.3)))),
              
              AnimatedPositioned(
                duration: const Duration(milliseconds: 350),
                curve: Curves.fastOutSlowIn,
                top: 0, bottom: 0, left: _isSidebarOpen ? 0 : -320,
                child: Container(
                  width: 320,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(right: BorderSide(color: Colors.grey.shade300, width: 1)),
                    boxShadow: [
                      if (_isSidebarOpen) BoxShadow(color: Colors.black.withOpacity(0.15), blurRadius: 30, offset: const Offset(5, 0)),
                    ],
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      Container(
                        padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 28),
                        decoration: const BoxDecoration(color: _darkGreen, border: Border(bottom: BorderSide(color: _standardGold, width: 4))),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            const Text('WORKSPACE', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold, letterSpacing: 1.5)),
                            IconButton(onPressed: _toggleSidebar, icon: const Icon(Icons.close_rounded, color: Colors.white), splashRadius: 20, padding: EdgeInsets.zero, constraints: const BoxConstraints()),
                          ],
                        ),
                      ),
                      Expanded(
                        child: ListView.builder(
                          padding: const EdgeInsets.symmetric(vertical: 16),
                          itemCount: _menuItems.length,
                          itemBuilder: (context, index) {
                            return FaqHoverMenuLink(
                              title: _menuItems[index],
                              icon: _menuIcons[index],
                              isSelected: _currentViewIndex == index,
                              onTap: () => _switchTab(index),
                            );
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          );
        },
      ),
    );
  }

  Widget _buildFloatingHamburger() {
    return FaqHoverClickable(
      onTap: _toggleSidebar,
      builder: (isHovered) => AnimatedContainer(
        duration: const Duration(milliseconds: 200),
        padding: const EdgeInsets.all(12),
        decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.zero, border: Border.all(color: Colors.grey.shade300, width: 1),
          boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 2))],
        ),
        child: const Icon(Icons.menu_rounded, color: _darkGreen, size: 24),
      ),
    );
  }

  Widget _buildSharpCollapseButton({required VoidCallback onTap}) {
    return FaqHoverClickable(
      onTap: onTap,
      builder: (isHovered) => AnimatedContainer(
        duration: const Duration(milliseconds: 200),
        padding: const EdgeInsets.all(8),
        decoration: BoxDecoration(color: isHovered ? _standardGold : Colors.transparent, borderRadius: BorderRadius.zero, border: Border.all(color: _standardGold, width: 2)),
        child: Icon(Icons.keyboard_arrow_up_rounded, color: isHovered ? Colors.white : _standardGold, size: 24),
      ),
    );
  }

  Widget _buildChevron({required VoidCallback onTap}) {
    return FaqHoverClickable(
      onTap: onTap,
      builder: (isHovered) => AnimatedContainer(
        duration: const Duration(milliseconds: 200),
        curve: Curves.easeOut,
        padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
        decoration: BoxDecoration(
          color: isHovered ? _standardGold : Colors.white, border: Border.all(color: _standardGold, width: 2),
          boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 4))],
        ),
        child: Icon(Icons.keyboard_arrow_down_rounded, color: isHovered ? Colors.white : _darkGreen, size: 24),
      ),
    );
  }
}*/