// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/image_operate_panel/controller.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/image_operate_panel/widgets/measure_item_button.dart';
import 'package:flyinsono/lab/pages/lab_image/widgets/image_operate_panel/widgets/measure_multi_items_button.dart';
import 'package:get/get.dart';

class MeasureButtonList extends GetView<ImageOperatePanelController> {
  MeasureButtonList({
    Key? key,
    required this.tabHashCode,
  }) : super(key: key);
  final String tabHashCode;
  @override
  String? get tag => tabHashCode;
  ScrollController meatureItemScrollController = ScrollController();
  @override
  Widget build(BuildContext context) {
    return GetBuilder<ImageOperatePanelController>(
        tag: tabHashCode,
        id: ImageOperatePanelController.imageMeasureStyle,
        builder: (_) {
          return Container(
            child: RawScrollbar(
              thumbVisibility: true,
              thickness: 4.0,
              radius: Radius.circular(2.0),
              thumbColor: LabColors.text100,
              trackColor: Colors.blue,
              trackBorderColor: Colors.blueAccent,
              controller: meatureItemScrollController,
              child: ListView(
                controller: meatureItemScrollController,
                padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
                children: [
                  ...controller.measureItems.asMap().entries.map(
                    (e) {
                      if (e.value.itemMeta.childItems.isNotEmpty) {
                        return Obx(() => MeasureMultiItemsButton(
                              isSelected:
                                  controller.selectedMeasureItemIndex == e.key,
                              description: e.value.description,
                              itemMeta: e.value.itemMeta,
                              activeChildItemIndex:
                                  controller.selectedChildMeasureItemIndex,
                              onTap: () {
                                controller.changeMeasureItem(e.key);
                              },
                              onChangeChildItem: (index) {
                                controller.changeChildMeasureItem(index);
                              },
                            ));
                      }
                      return Obx(
                        () => MeasureItemButton(
                          isSelected:
                              controller.selectedMeasureItemIndex == e.key,
                          description: e.value.description,
                          onTap: () {
                            controller.changeMeasureItem(e.key);
                          },
                        ),
                      );
                    },
                  ).toList(),
                ],
              ),
            ),
          );
        });
  }
}
