import 'package:flutter/material.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';

class ExpandToolBar extends FStatefulWidget implements FPage {
  @override
  FState<FStatefulWidget> createState() {
    return ExpandToolBarState();
  }

  final String? title;
  final void Function(bool) onTap;
  final bool isExpand;

  ExpandToolBar(
    this.onTap, {
    this.isExpand = false,
    this.title,
  });

  @override
  String get pageName => 'ExpandToolBar';
}

class ExpandToolBarState extends FState<ExpandToolBar> {
  bool _isShowToolbar = false;

  @override
  void initState() {
    _isShowToolbar = widget.isExpand;
    super.initState();
  }

  @override
  FWidget build(BuildContext context) {
    return FMouseRegion(
      cursor: SystemMouseCursors.click,
      child: FGestureDetector(
        businessParent: widget,
        name: 'switchToolBar',
        onTap: () {
          setState(() {
            _isShowToolbar = !_isShowToolbar;
          });
          widget.onTap.call(_isShowToolbar);
        },
        child: FContainer(
          margin: EdgeInsets.symmetric(horizontal: 10),
          alignment: Alignment.center,
          width: double.infinity,
          height: 30,
          color: FTheme.ins.colorScheme.primary,
          child: FRow(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              FSizedBox(width: 5),
              FExpanded(
                child: FText(
                  widget.title ?? '',
                  style: TextStyle(color: Colors.white),
                ),
              ),
              FIcon(
                _isShowToolbar
                    ? Icons.keyboard_arrow_up
                    : Icons.keyboard_arrow_down,
                color: Colors.white,
                size: 25,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
