import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/pages/organization/org_personnel/controller.dart';
import 'package:flyinsono/pages/organization/org_personnel/widgets/org_member_info.dart';
import 'package:get/get.dart';

class SelectOrgMemberInfo extends StatefulWidget
    implements FInteractiveContainer {
  SelectOrgMemberInfo({
    Key? key,
    this.userItem,
    this.name = '',
    this.code = '',
    this.pageName = 'SelectOrgMemberInfo',
  }) : super(key: key);

  @override
  final String pageName;

  /// 当前的组织信息
  final String? code;

  /// 用户信息
  final UserDTO? userItem;

  /// 当前组织的名
  final String? name;

  @override
  State<SelectOrgMemberInfo> createState() => _SelectOrgMemberState();
}

class _SelectOrgMemberState extends State<SelectOrgMemberInfo> {
  final orgPesonnelController = Get.find<OrgPesonnelController>();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  FWidget build(BuildContext context) {
    return FScaffold(
      appBar: FAppBar(
        title: FText(
          i18nBook.organization.orgStructure.t,
        ),
        actions: [
          FGestureDetector(
            businessParent: this.widget,
            name: "confirm",
            onTap: () => orgPesonnelController
                .updateUserOrganizationInfoAsync(widget.userItem!.userCode),
            child: FCenter(
              child: FRow(
                children: [
                  FText(
                    i18nBook.common.confirm.t,
                  ),
                  const FSizedBox(
                    width: 20,
                  )
                ],
              ),
            ),
          ),
        ],
        centerTitle: true,
        elevation: 0,
        leading: FIconButton(
          businessParent: widget,
          name: "back",
          icon: FIcon(
            Icons.arrow_back_ios_new,
          ),
          onPressed: () {
            Get.back();
          },
        ),
      ),
      body: FMaterial(
        color: Colors.white,
        child: FSafeArea(
          child: FColumn(
            children: [
              OrgMemberInfo(
                orgMemberInfoImage: FContainer(
                  width: 65,
                  height: 65,
                  child: FCircleAvatar(
                    child: _orgMemberImage(''),
                  ),
                ),
                onClick: () {},
                userItem: widget.userItem,
              ),
            ],
          ),
        ),
      ),
    );
  }

  ///组织成员头像
  FWidget _orgMemberImage(String? isImage) {
    FWidget child;
    isImage!.isEmpty
        ? child = FImage.asset('assets/images/avatar_man.png')
        : child = FImage.network(isImage);
    return child;
  }
}
