import 'package:fis_ui/index.dart';
import 'package:fis_i18n/i18n.dart';
import 'package:flutter/material.dart';
import 'package:fis_ui/base_define/page.dart';

class FExpandableToolbar extends StatefulWidget implements FPage {
  final FWidget toolAreaChild; // 左侧工具区域
  final FWidget buttonAreaChild; // 右侧按钮区域
  FExpandableToolbar({
    required this.toolAreaChild,
    required this.buttonAreaChild,
  });

  @override
  _FExpandableToolbarState createState() => _FExpandableToolbarState();

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

class _FExpandableToolbarState extends State<FExpandableToolbar> {
  bool _isShowToolbar = true;

  @override
  Widget build(BuildContext context) {
    return _buildSwitchToolBar();
  }

  FWidget _buildSwitchToolBar() {
    return FAlign(
      alignment: Alignment.bottomLeft,
      child: FSizedBox(
        height: 80,
        child: FRow(
          children: [
            FMouseRegion(
              cursor: SystemMouseCursors.click,
              child: FGestureDetector(
                businessParent: widget,
                name: 'switchToolBar',
                onTap: () {
                  setState(() {
                    _isShowToolbar = !_isShowToolbar;
                  });
                },
                child: FContainer(
                  margin: EdgeInsets.only(left: 5),
                  alignment: Alignment.center,
                  width: 40,
                  height: 80,
                  color: Colors.black.withOpacity(0.5),
                  child: FColumn(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      FIcon(
                        _isShowToolbar
                            ? Icons.chevron_left
                            : Icons.chevron_right,
                        color: Colors.white,
                        size: 25,
                      ),
                      FSizedBox(height: 5),
                      FText(
                        _isShowToolbar
                            ? i18nBook.college.collapse.t
                            : i18nBook.college.expand.t,
                        style: TextStyle(color: Colors.white),
                      ),
                    ],
                  ),
                ),
              ),
            ),
            FExpanded(
              child: _isShowToolbar ? widget.toolAreaChild : FContainer(),
            ),
            FColumn(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                FContainer(
                  padding: EdgeInsets.only(right: 10, bottom: 10),
                  child: widget.buttonAreaChild,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
