// ignore_for_file: non_constant_identifier_names

import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/services/remedical.m.dart';
import 'package:fis_measure/process/workspace/measure_data_controller.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'widgets/common.dart';
import 'widgets/radio_group.dart';

class UnitConfig extends FStatelessWidget {
  UnitConfig({
    Key? key,
    required this.businessParent,
  }) : super(key: key);

  ///父级节点
  final FInteractiveContainer businessParent;

  /// 测量数据
  final measureData = Get.find<MeasureDataController>();

  /// [URM长度单位] 可选项
  static final List<Unit> C_URM_DISTANCE_UNIT_LIST = [
    Unit.cm,
    Unit.mm,
    Unit.um,
    Unit.inch,
    Unit.ft,
  ];

  /// [长度单位] 可选项
  static final List<Unit> C_DISTANCE_UNIT_LIST = [
    Unit.cm,
    Unit.mm,
    Unit.inch,
    Unit.ft,
  ];

  /// [面积单位] 可选项
  static final List<Unit> C_AREA_UNIT_LIST = [
    Unit.cm2,
    Unit.mm2,
    Unit.m2,
  ];

  /// [速度单位] 可选项
  static final List<Unit> C_VELOCITY_UNIT_LIST = [
    Unit.mms,
    Unit.cms,
    Unit.ms,
  ];

  /// [时间单位] 可选项
  static final List<Unit> C_TIME_UNIT_LIST = [
    Unit.msec,
    Unit.s,
  ];

  @override
  FWidget build(BuildContext context) {
    return FContainer(
        width: 550,
        height: 500,
        padding: const EdgeInsets.symmetric(
          vertical: 15,
          horizontal: 15,
        ),
        margin: const EdgeInsets.symmetric(
          horizontal: 15,
        ),
        child: ConfigBody(
          businessParent: businessParent,
          measureData: measureData,
        ));
  }
}

class ConfigBody extends FStatefulWidget {
  const ConfigBody({
    Key? key,
    required this.businessParent,
    required this.measureData,
  }) : super(key: key);

  ///父级节点
  final FInteractiveContainer businessParent;
  final MeasureDataController measureData;
  @override
  FState<ConfigBody> createState() => _ConfigBodyState();
}

class _ConfigBodyState extends FState<ConfigBody> {
  @override
  void initState() {
    super.initState();
  }

  @override
  FWidget build(BuildContext context) {
    return FListView(
      shrinkWrap: true,
      children: [
        PatternBodyItem(
          patternBodyItemTitle: i18nBook.measure.measureUnit.t,
          patternBodyItem: FColumn(
            children: [
              /// [URM长度单位]
              PatternItem(
                title: i18nBook.measure.urmDistanceUnit.t,
                item: PatternItemRadio(
                  tabList: UnitConfig.C_URM_DISTANCE_UNIT_LIST,
                  businessParent: widget.businessParent,
                  value:
                      widget.measureData.measureSystemSetting.uRMDistanceUnit,
                  type: PatternValueType.unit,
                  onChangeState: (value) {
                    setState(() {
                      widget.measureData.measureSystemSetting.uRMDistanceUnit =
                          value;
                    });
                  },
                ),
              ),

              /// [长度单位]
              PatternItem(
                title: i18nBook.measure.distanceUnit.t,
                item: PatternItemRadio(
                  tabList: UnitConfig.C_DISTANCE_UNIT_LIST,
                  businessParent: widget.businessParent,
                  value: widget.measureData.measureSystemSetting.distanceUnit,
                  type: PatternValueType.unit,
                  onChangeState: (value) {
                    setState(() {
                      widget.measureData.measureSystemSetting.distanceUnit =
                          value;
                    });
                  },
                ),
              ),

              /// [面积单位]
              PatternItem(
                title: i18nBook.measure.areaUnit.t,
                item: PatternItemRadio(
                  tabList: UnitConfig.C_AREA_UNIT_LIST,
                  businessParent: widget.businessParent,
                  value: widget.measureData.measureSystemSetting.areaUnit,
                  type: PatternValueType.unit,
                  onChangeState: (value) {
                    setState(() {
                      widget.measureData.measureSystemSetting.areaUnit = value;
                    });
                  },
                ),
              ),

              /// [速度单位]
              PatternItem(
                title: i18nBook.measure.velocityUnit.t,
                item: PatternItemRadio(
                  tabList: UnitConfig.C_VELOCITY_UNIT_LIST,
                  businessParent: widget.businessParent,
                  value: widget.measureData.measureSystemSetting.velocityUnit,
                  type: PatternValueType.unit,
                  onChangeState: (value) {
                    setState(() {
                      widget.measureData.measureSystemSetting.velocityUnit =
                          value;
                    });
                  },
                ),
              ),

              /// [时间单位]
              PatternItem(
                title: i18nBook.measure.timeUnit.t,
                item: PatternItemRadio(
                  tabList: UnitConfig.C_TIME_UNIT_LIST,
                  businessParent: widget.businessParent,
                  value: widget.measureData.measureSystemSetting.timeUnit,
                  type: PatternValueType.unit,
                  onChangeState: (value) {
                    setState(() {
                      widget.measureData.measureSystemSetting.timeUnit = value;
                    });
                  },
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
