import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/pages/organization/org_info/state.dart';
import 'package:flyinsono/pages/user/user_device/controller.dart';
import 'package:fis_theme/theme.dart';

///部门选择
class DepartmentSelect extends FisView<DeviceController> {
  @override
  FWidget build(BuildContext context) {
    final select = FObx(() {
      var deviceInfo = controller.state.deviceInfo;
      return FSelect<OrgModel, String>(
        fontFamily: FTheme.ins.localeSetting.fontFamily,
        source: controller.state.depOptions,
        hintText: i18nBook.user.departmentIn.t,
        value: (deviceInfo.departmentCode != null &&
                deviceInfo.departmentCode!.isNotEmpty)
            ? deviceInfo.departmentCode
            : null,
        clearable: true,
        height: 36,
        optionLabelExtractor: (data) => data.name,
        optionValueExtractor: (data) => data.code,
        onSelectChanged: (value, index) {
          deviceInfo.departmentCode = value;
        },
      );
    });

    return FExpanded(
      child: select,
    );
  }
}
