import 'package:flutter/material.dart';
import '../hr_section.dart';
import 'hr_workspace_header.dart';

class HRWorkspaceMenu extends StatelessWidget {
  const HRWorkspaceMenu({
    super.key,
    required this.open,
    required this.width,
    required this.selected,
    required this.showEmployeeCvs,
    required this.onClose,
    required this.onSelect,
  });

  final bool open;
  final double width;
  final HRSection selected;
  final bool showEmployeeCvs;
  final VoidCallback onClose;
  final ValueChanged<HRSection> onSelect;

  List<HRSection> get _sections => HRSection.values
      .where((section) => showEmployeeCvs || section != HRSection.employeeCvs)
      .toList();

  @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: hrGreen,
                    padding: const EdgeInsets.symmetric(horizontal: 18),
                    child: Row(children: [
                      const Expanded(child: Text('HUMAN RESOURCES',
                          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: hrGold),
                  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 ? hrGold : 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 ? hrGreen : const Color(0xFF929A95)),
                          const SizedBox(width: 15),
                          Text(section.title,
                              style: TextStyle(color: active ? hrGreen : 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: hrMuted, fontSize: 12, fontWeight: FontWeight.w600)),
                  ),
                ]),
              ),
            ),
          ]),
        ),
      );
}
