import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/common/model/event_bus/jobs/job_do_papers_switch_operation_bus.dart';
import 'package:marking_app/pages/common/event_bus_mixin.dart';
import 'package:marking_app/pages/homework_correction/hooks/do_papers_job/use_swith_operation_bar.dart';
import 'package:marking_app/utils/my_text.dart';

// 底部floating按钮 控制底部操作工具栏
class ButtonFloatingAction extends HookWidget with EventBusMixin<JobDoPapersSwitchOperationBus> {
  @override
  Widget build(BuildContext context) {
    UseSwithOperationBar _useSwithOperationBar = UseSwithOperationBar.use(); // 底部功能栏开关

    // 监听底部功能栏开关
    useValueChanged<bool, bool>(_useSwithOperationBar.operationBarSwitch.value, (_, __) {
      bool newVal = _useSwithOperationBar.operationBarSwitch.value;
      if (newVal) {
        eventFire(model: JobDoPapersSwitchOperationBus(newVal));
      }
      return null;
    });

    useEffect(() {
      eventOn(callback: (JobDoPapersSwitchOperationBus val) {
        if (!val.flag) _useSwithOperationBar.operationBarSwitch.value = false;
      });
      return () {
        eventCancel();
      };
    }, []);

    if (_useSwithOperationBar.operationBarSwitch.value) return SizedBox();

    return FloatingActionButton(
      backgroundColor: Colors.white,
      tooltip: "点击打开工具栏",
      child: Icon(
        Icons.edit,
        size: 20.sp,
        color: Theme.of(context).primaryColor,
      ),
      elevation: 8, // Control the shadow's elevation
      onPressed: () {
        _useSwithOperationBar.operationBarSwitch.value = true;
      },
    );
  }
}
