import 'package:flutter/material.dart';
import '../marketing_section.dart';
import 'marketing_ui.dart';

class MarketingWorkspaceHeader extends StatelessWidget {
  const MarketingWorkspaceHeader({
    super.key,
    required this.section,
    required this.expanded,
    required this.refreshing,
    required this.onMenu,
    required this.onToggle,
    required this.onRefresh,
  });
  final MarketingSection section;
  final bool expanded;
  final bool refreshing;
  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: marketingLine))),
    child: Column(mainAxisSize: MainAxisSize.min, children: [
      SizedBox(height: 58, child: Row(children: [
        const SizedBox(width: 12),
        _squareIcon(Icons.menu, 'Open workspace menu', onMenu),
        const SizedBox(width: 12),
        Container(width: 34, height: 34, color: const Color(0xFFEAF3EE), child: Icon(section.icon, color: marketingGreen, size: 19)),
        const SizedBox(width: 10),
        Expanded(child: Text(section.title, maxLines: 1, overflow: TextOverflow.ellipsis,
          style: const TextStyle(color: marketingGreenDark, 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: marketingGreen))),
        _squareIcon(Icons.refresh, 'Refresh data', 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: marketingLine), color: marketingCanvas),
            child: Icon(expanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down, size: 19, color: marketingGreen)),
        )),
        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: marketingCanvas,
              padding: const EdgeInsets.symmetric(horizontal: 20),
              alignment: Alignment.centerLeft,
              child: Text('Marketing Department  /  ${section.title}',
                maxLines: 1, overflow: TextOverflow.ellipsis,
                style: const TextStyle(color: marketingMuted, fontSize: 12)),
            )
          : const SizedBox(width: double.infinity, height: 0),
      ),
    ]),
  );

  Widget _squareIcon(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: marketingLine)),
        child: Icon(icon, size: 20, color: marketingGreen)),
    ),
  );
}
