/*
 * @Author: wangyang 1147192855@qq.com
 * @Date: 2022-07-14 18:16:06
 * @LastEditors: wangyang 1147192855@qq.com
 * @LastEditTime: 2022-08-01 16:17:33
 * @FilePath: \marking_app\lib\provider\user_provider.dart
 * @Description: APP上传文件状态
 */

import 'package:marking_app/common/model/marking/annotation_graffiti_switch.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:marking_app/common/mixin/common.dart';

// 涂鸦批注开关
final annotationGraffitiSwitchProvider =
    StateNotifierProvider<AnnotationGraffitiSwitchProviderHandle, AnnotationGraffitiSwitch>(
        (ref) => AnnotationGraffitiSwitchProviderHandle(AnnotationGraffitiSwitch()));

class AnnotationGraffitiSwitchProviderHandle extends StateNotifier<AnnotationGraffitiSwitch> with CommonMixin {
  AnnotationGraffitiSwitchProviderHandle(AnnotationGraffitiSwitch progress) : super(progress);

  void init() {
    setSwitch(false);
  }

  // 批注涂鸦开关
  void setSwitch(bool flag) {
    if (state.annotationSwitch == flag) return;

    state.annotationSwitch = flag;
    // state.openBrush = false;
    // state.openEraser = false;
    // state.openClearAll = false;
    // state.magnifier = false;
    // state.trajectoryDisplay = false;
    state = AnnotationGraffitiSwitch.fromJson(state.toJson());
  }

  // 设置画笔
  void setSwitchBrush() {
    state.openBrush = !state.openBrush;
    state.openEraser = false;
    state.openClearAll = false;
    state.magnifier = false;
    state.trajectoryDisplay = false;
    state = AnnotationGraffitiSwitch.fromJson(state.toJson());
  }

  // 设置橡皮擦
  void setSwitchEraser() {
    state.openBrush = false;
    state.openEraser = !state.openEraser;
    state.openClearAll = false;
    state.magnifier = false;
    state.trajectoryDisplay = false;
    state = AnnotationGraffitiSwitch.fromJson(state.toJson());
  }

  // 设置放大镜
  void setMagnifier() {
    state.openBrush = false;
    state.openEraser = false;
    state.openClearAll = false;
    state.trajectoryDisplay = false;
    state.magnifier = !state.magnifier;
    state = AnnotationGraffitiSwitch.fromJson(state.toJson());
  }

  // 设置笔记回显
  void setTrajectory() {
    state.openBrush = false;
    state.openEraser = false;
    state.openClearAll = false;
    state.magnifier = false;
    state.trajectoryDisplay = !state.trajectoryDisplay;
    state = AnnotationGraffitiSwitch.fromJson(state.toJson());
  }
}
