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

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

  final ITSupportSection section;
  final bool expanded, refreshing;
  final int pendingCount;
  final VoidCallback onMenu, onToggle, onRefresh, onOutbox;

  @override
  Widget build(BuildContext context) => Container(
    decoration: const BoxDecoration(color: Colors.white, border: Border(bottom: BorderSide(color: supportBorder))),
    child: Column(mainAxisSize: MainAxisSize.min, children: [
      SizedBox(height: 58, child: Row(children: [
        const SizedBox(width: 12),
        _iconButton(Icons.menu_rounded, 'Open workspace menu', onMenu),
        const SizedBox(width: 10),
        Container(width: 34, height: 34, color: const Color(0xFFEAF3EE), child: Icon(section.icon, color: supportGreen, size: 19)),
        const SizedBox(width: 10),
        Expanded(child: Text(section.title, maxLines: 1, overflow: TextOverflow.ellipsis,
          style: const TextStyle(color: supportInk, fontWeight: FontWeight.w800, fontSize: 15))),
        if (refreshing) const Padding(padding: EdgeInsets.only(right: 8), child: SizedBox(width: 16, height: 16,
          child: CircularProgressIndicator(strokeWidth: 2, color: supportGreen))),
        _iconButton(Icons.sync_rounded, 'Refresh data', onRefresh, size: 34),
        const SizedBox(width: 4),
        Tooltip(message: 'Outbox ($pendingCount)', child: InkWell(onTap: onOutbox,
          child: SizedBox(width: 36, height: 36, child: Center(child: Badge(
            label: Text('$pendingCount'), isLabelVisible: pendingCount > 0,
            child: const Icon(Icons.outbox_outlined, color: supportGreen, size: 20)))))),
        const SizedBox(width: 4),
        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: supportBorder), color: const Color(0xFFF6F8F7)),
            child: Icon(expanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down, size: 19, color: supportGreen)))),
        const SizedBox(width: 12),
      ])),
      AnimatedSize(duration: const Duration(milliseconds: 220), curve: Curves.easeInOutCubic,
        alignment: Alignment.topCenter,
        child: expanded ? Container(height: 36, width: double.infinity, color: const Color(0xFFF4F7F5),
          padding: const EdgeInsets.symmetric(horizontal: 18), alignment: Alignment.centerLeft,
          child: Text('IT SERVICE DESK  /  ${section.title.toUpperCase()}',
            style: const TextStyle(color: Color(0xFF718078), fontSize: 11, fontWeight: FontWeight.w700, letterSpacing: .4)))
          : const SizedBox(width: double.infinity, height: 0)),
    ]),
  );

  Widget _iconButton(IconData icon, String tooltip, VoidCallback onTap, {double size = 36}) => 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: supportBorder)),
      child: Icon(icon, size: 19, color: supportGreen))));
}
