import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/components/rect_icon_button.dart';
import 'package:flyinsono/lab/pages/lab_project/controller.dart';
import 'package:flyinsono/lab/pages/lab_project/widgets/project_member_item.dart';
import 'package:flyinsono/lab/style/lab_box_decoration.dart';
import 'package:get/get.dart';

class ProjectMemberDialog extends GetView<LabProjectController> {
  const ProjectMemberDialog({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 450,
      child: ListView(
        children: [
          Row(
            children: [
              Flexible(
                flex: 1,
                child: Align(
                  alignment: Alignment.center,
                  child: LayoutBuilder(builder: (
                    BuildContext context,
                    BoxConstraints constraints,
                  ) {
                    bool visible = constraints.maxWidth > 50;
                    return Visibility(
                      visible: visible,
                      child: Container(
                        margin: EdgeInsets.only(
                          left: 16,
                          right: 16,
                          bottom: 16,
                        ),
                        constraints: BoxConstraints(
                          maxWidth: constraints.maxWidth,
                          minWidth: 20,
                        ),
                        height: 40,
                        decoration: LabBoxDecoration.base,
                        child: Row(
                          children: [
                            SizedBox(
                              width: 10,
                            ),
                            Expanded(
                              child: Container(
                                height: 28,
                                child: Center(
                                  child: TextField(
                                    scrollPadding: EdgeInsets.all(0),
                                    controller: controller
                                        .projectMemberSearchInputController,
                                    style: TextStyle(
                                      fontSize: 14,
                                      color: LabColors.text900,
                                    ),
                                    textAlignVertical: TextAlignVertical.bottom,
                                    decoration: InputDecoration(
                                      hintStyle: TextStyle(
                                        fontSize: 14,
                                        color: LabColors.text600,
                                      ),
                                      isCollapsed: true,
                                      contentPadding: EdgeInsets.all(0),
                                      hintText: "搜索",
                                      border: OutlineInputBorder(
                                        borderSide: BorderSide.none,
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            Padding(
                              padding: const EdgeInsets.all(2.0),
                              child: RectIconButton(
                                iconSize: 20,
                                icon: Icons.search,
                                onPressed: () {
                                  // print('todo search');
                                  controller.searchMember();
                                },
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                  }),
                ),
              ),
            ],
          ),
          Container(
            alignment: controller.allMemberModelListSort.length < 5
                ? Alignment.centerLeft
                : Alignment.center,
            padding: EdgeInsets.only(
              left: controller.allMemberModelListSort.length < 5 ? 16 : 0,
            ),
            child: GetBuilder<LabProjectController>(
                id: LabProjectController.projectMember,
                builder: (context) {
                  return Wrap(
                    children: controller.allMemberModelListSort
                        .map(
                          (e) => ProjectMemberItem(
                            member: e,
                            onChangeSelectMember: (MemberModel member) {
                              controller.onChangeMember(member);
                            },
                            isSelected: controller.selectMemberModelList
                                .where((element) => element.name == e.name)
                                .isNotEmpty,
                          ),
                        )
                        .toList(),
                  );
                }),
          ),
        ],
      ),
    );
  }
}
