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

const hrGreen = Color(0xFF026930);
const hrDarkGreen = Color(0xFF034D26);
const hrGold = Color(0xFFCC7504);
const hrInk = Color(0xFF24332B);
const hrMuted = Color(0xFF68776E);
const hrLine = Color(0xFFDDE4DF);
const hrCanvas = Color(0xFFF5F7F6);

class HRWorkspaceHeader extends StatelessWidget {
  const HRWorkspaceHeader({
    super.key,
    required this.section,
    required this.expanded,
    required this.onMenu,
    required this.onToggle,
    required this.onRefresh,
  });

  final HRSection section;
  final bool expanded;
  final VoidCallback onMenu;
  final VoidCallback onToggle;
  final VoidCallback onRefresh;

  @override
  Widget build(BuildContext context) => Container(
        decoration: const BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(color: hrLine)),
        ),
        child: Column(mainAxisSize: MainAxisSize.min, children: [
          SizedBox(height: 58, child: Row(children: [
            const SizedBox(width: 12),
            _icon(Icons.menu, 'Open HR menu', onMenu),
            const SizedBox(width: 10),
            Container(
              width: 34,
              height: 34,
              color: const Color(0xFFEAF3EE),
              child: Icon(section.icon, color: hrGreen, size: 19),
            ),
            const SizedBox(width: 10),
            Expanded(child: Text(section.title,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(color: hrDarkGreen, fontWeight: FontWeight.w800, fontSize: 15))),
            _icon(Icons.refresh, 'Refresh section', onRefresh, size: 34),
            const SizedBox(width: 7),
            Tooltip(
              message: expanded ? 'Collapse header' : 'Expand header',
              child: InkWell(
                onTap: onToggle,
                child: Container(
                  width: 32,
                  height: 32,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(border: Border.all(color: hrLine), color: hrCanvas),
                  child: Icon(expanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
                      size: 19, color: hrGreen),
                ),
              ),
            ),
            const SizedBox(width: 12),
          ])),
          AnimatedSize(
            duration: const Duration(milliseconds: 220),
            curve: Curves.easeInOutCubic,
            alignment: Alignment.topCenter,
            child: expanded
                ? Container(
                    height: 38,
                    width: double.infinity,
                    color: hrCanvas,
                    padding: const EdgeInsets.symmetric(horizontal: 20),
                    alignment: Alignment.centerLeft,
                    child: Text('Human Resources  /  ${section.title}',
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: const TextStyle(color: hrMuted, fontSize: 12)),
                  )
                : const SizedBox(width: double.infinity, height: 0),
          ),
        ]),
      );

  Widget _icon(IconData icon, String tooltip, VoidCallback onTap, {double size = 38}) => Tooltip(
        message: tooltip,
        child: InkWell(
          onTap: onTap,
          child: Container(
            width: size,
            height: size,
            alignment: Alignment.center,
            decoration: BoxDecoration(color: Colors.white, border: Border.all(color: hrLine)),
            child: Icon(icon, size: 20, color: hrGreen),
          ),
        ),
      );
}
