import 'package:flutter/material.dart';
import '../it_support_section.dart';
import '../it_support_widgets.dart';

class ITSupportWorkspaceMenu extends StatelessWidget {
  const ITSupportWorkspaceMenu({super.key, required this.open, required this.width,
    required this.selected, required this.onClose, required this.onSelect});
  final bool open;
  final double width;
  final ITSupportSection selected;
  final VoidCallback onClose;
  final ValueChanged<ITSupportSection> onSelect;

  @override
  Widget build(BuildContext context) => Positioned.fill(child: IgnorePointer(
    ignoring: !open,
    child: Stack(children: [
      Positioned.fill(child: GestureDetector(onTap: onClose,
        child: AnimatedOpacity(duration: const Duration(milliseconds: 230), curve: Curves.easeOut,
          opacity: open ? 1 : 0, child: Container(color: Colors.black.withOpacity(.28))))),
      AnimatedPositioned(duration: const Duration(milliseconds: 280), curve: Curves.easeOutCubic,
        left: open ? 0 : -width - 10, top: 0, bottom: 0, width: width,
        child: Material(elevation: 10, color: Colors.white, child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
          Container(height: 66, color: supportGreen, padding: const EdgeInsets.symmetric(horizontal: 17),
            child: Row(children: [const Expanded(child: Text('IT WORKSPACE', style: TextStyle(color: Colors.white,
              fontWeight: FontWeight.w900, letterSpacing: .8))), IconButton(onPressed: onClose,
              tooltip: 'Close menu', icon: const Icon(Icons.close, color: Colors.white))])),
          Container(height: 3, color: const Color(0xFF174B37)),
          const SizedBox(height: 12),
          ...ITSupportSection.values.map((section) {
            final active = section == selected;
            return AnimatedContainer(duration: const Duration(milliseconds: 210), curve: Curves.easeOut,
              decoration: BoxDecoration(color: active ? const Color(0xFFEAF3EE) : Colors.white,
                border: Border(left: BorderSide(color: active ? supportGreen : Colors.transparent, width: 3))),
              child: InkWell(onTap: () => onSelect(section), child: SizedBox(height: 51,
                child: Row(children: [const SizedBox(width: 18), Icon(section.icon, size: 19,
                  color: active ? supportGreen : const Color(0xFF8A958E)), const SizedBox(width: 14),
                  Text(section.title, style: TextStyle(color: active ? supportGreen : supportInk,
                    fontWeight: active ? FontWeight.w800 : FontWeight.w600))]))));
          }),
          const Spacer(), const Divider(height: 1),
          const Padding(padding: EdgeInsets.all(16), child: Text('University-wide IT support',
            style: TextStyle(color: Color(0xFF718078), fontSize: 12, fontWeight: FontWeight.w600))),
        ]))),
    ]),
  ));
}
