import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:fis_ui/index.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/image_measure_overlay/controller.dart';

class AccessibilityLayer extends GetView<ImageMeasureOverlayController> {
  AccessibilityLayer({
    Key? key,
    required this.tabHashCode,
  }) : super(key: key);

  @override
  String? get tag => tabHashCode;

  final String tabHashCode;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ImageMeasureOverlayController>(
      tag: tabHashCode,
      id: ImageMeasureOverlayController.accessibilityLayerId,
      builder: (_) {
        if (controller.app == null) return const SizedBox();
        if (!controller.showAccessibility) return const SizedBox();
        final aliment = _getAlignmentFromLocation(controller
            .measureDataController!.measureSystemSetting.showResultLocation);
        return Align(
          alignment: aliment,
          child: Container(
            child: _buildTip(),
          ),
        );
      },
    );
  }

  /// 面板对齐方式
  Alignment _getAlignmentFromLocation(int locationNum) {
    switch (locationNum) {
      case 0:
        return Alignment.topRight;
      case 1:
        return Alignment.topRight;
      case 2:
        return Alignment.topLeft;
      case 3:
        return Alignment.topRight;
      default:
        return Alignment.topRight;
    }
  }

  /// 右键右上角角标
  FWidget _buildTip() {
    return FContainer(
      height: 24,
      margin: const EdgeInsets.symmetric(horizontal: 10),
      padding: const EdgeInsets.all(5),
      decoration: const BoxDecoration(
        color: Color.fromRGBO(71, 71, 71, 1),
        borderRadius: BorderRadius.all(Radius.circular(5)),
      ),
      child: FRow(mainAxisSize: MainAxisSize.min, children: [
        const FIcon(
          Icons.error_outline,
          color: Colors.white,
          size: 14,
        ),
        const FSizedBox(width: 5),
        FFittedBox(
          fit: BoxFit.fitHeight,
          child: FText(
            "使用方向键可以微调测量点",
            style: const TextStyle(
              height: 1,
              fontSize: 20,
              color: Color.fromRGBO(213, 213, 213, 1),
            ),
          ),
        ),
      ]),
    );
  }
}
