import 'package:flutter/material.dart';
import '../education_section.dart';
import 'education_ui.dart';

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

  static const sections = EducationSection.values;

  @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: 240),
            curve: Curves.easeOut,
            opacity: open ? 1 : 0,
            child: Container(color: Colors.black.withOpacity(.32)),
          ),
        )),
        AnimatedPositioned(
          duration: const Duration(milliseconds: 280),
          curve: Curves.easeOutCubic,
          left: open ? 0 : -width - 12,
          top: 0,
          bottom: 0,
          width: width,
          child: Material(
            elevation: 12,
            color: Colors.white,
            child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
              Container(
                height: 70,
                color: educationGreen,
                padding: const EdgeInsets.symmetric(horizontal: 18),
                child: Row(children: [
                  const Expanded(child: Text('WORKSPACE', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w900, letterSpacing: 1.1))),
                  IconButton(onPressed: onClose, tooltip: 'Close menu', icon: const Icon(Icons.close, color: Colors.white)),
                ]),
              ),
              Container(height: 3, color: educationGreenDark),
              const SizedBox(height: 12),
              ...sections.map((section) {
                final active = section == selected;
                return AnimatedContainer(
                  duration: const Duration(milliseconds: 200),
                  curve: Curves.easeOut,
                  margin: const EdgeInsets.only(bottom: 2),
                  decoration: BoxDecoration(
                    color: active ? const Color(0xFFEAF3EE) : Colors.white,
                    border: Border(left: BorderSide(color: active ? educationGreen : Colors.transparent, width: 3)),
                  ),
                  child: InkWell(
                    onTap: () => onSelect(section),
                    child: SizedBox(height: 54, child: Row(children: [
                      const SizedBox(width: 20),
                      Icon(section.icon, size: 20, color: active ? educationGreen : const Color(0xFF929A95)),
                      const SizedBox(width: 15),
                      Text(section.title, style: TextStyle(color: active ? educationGreen : const Color(0xFF515B55), fontWeight: active ? FontWeight.w800 : FontWeight.w600)),
                    ])),
                  ),
                );
              }),
              const Spacer(),
              const Divider(height: 1),
              const Padding(padding: EdgeInsets.all(17), child: Text('Rockview University', style: TextStyle(color: educationMuted, fontSize: 12, fontWeight: FontWeight.w600))),
            ]),
          ),
        ),
      ]),
    ),
  );
}
