import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/pages/user/user_device/controller.dart';
import 'package:get/get.dart';

List<String> deleteList = [];

///删除分享成员
class DeleteMemberUser extends FStatefulWidget {
  const DeleteMemberUser({
    Key? key,
    required this.title,
    required this.positationalText,
    this.image,
    this.isImage = false,
    this.onClick,
    this.hintText = '',
    this.imageUrl = '',
    this.listObject,
    required this.businessParent,
  }) : super(key: key);
  final FWidget title;
  final FWidget positationalText;
  final FWidget? image;
  final bool? isImage;
  final String? hintText;
  final Function? onClick;
  final String? imageUrl;
  final dynamic listObject;
  final FInteractiveContainer businessParent;
  @override
  FState<DeleteMemberUser> createState() => _DeleteMemberUserState();
}

class _DeleteMemberUserState extends FState<DeleteMemberUser> {
  final userDeviceController = Get.put(DeviceController());
  @override
  FWidget build(BuildContext context) {
    return FMaterial(
      color: Colors.white,
      child: FColumn(
        children: [
          FSlidable(
            endActionPane: _buildRemoveActionPane(),
            child: FInkWell(
              onTap: () {},
              child: FContainer(
                margin: EdgeInsets.symmetric(
                  horizontal: 20,
                ),
                padding: EdgeInsets.symmetric(
                  horizontal: 13,
                  vertical: 10,
                ),
                decoration: BoxDecoration(
                  border: Border.all(
                    color: Color.fromRGBO(228, 228, 228, 1),
                  ),
                  borderRadius: BorderRadius.all(Radius.circular(4)),
                ),
                child: FContainer(
                  child: _buildShareUserInfoRow(),
                ),
              ),
            ),
          ),
          FSizedBox(
            height: 15,
          )
        ],
      ),
    );
  }

  ///移除用户
  ActionPane _buildRemoveActionPane() {
    return ActionPane(
      motion: ScrollMotion(),
      children: [
        SlidableAction(
          onPressed: (BuildContext context) {
            userDeviceController.state.selectList = [
              widget.listObject.userCode.toString()
            ];
            userDeviceController
                .deleteShareDeviceToUserAsync(widget.businessParent);
          },
          backgroundColor: Theme.of(context).colorScheme.error,
          foregroundColor: Colors.white,
          icon: Icons.delete,
          label: i18nBook.common.remove.t,
        ),
      ],
    );
  }

  ///分享用户信息
  FWidget _buildShareUserInfoRow() {
    return FRow(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        FRow(
          children: [
            widget.image!,
            FSizedBox(
              width: 12,
            ),
            FColumn(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                widget.title,
                FSizedBox(
                  height: 3,
                ),
                widget.positationalText,
              ],
            ),
          ],
        ),
        FObx(
          () {
            if (userDeviceController.state.batchOperation)
              return FContainer(
                child: FCheckbox(
                  value: widget.listObject.userCode,
                  onChange: (value, isCheck) {
                    if (isCheck!) {
                      deleteList.add(
                        widget.listObject.userCode.toString(),
                      );
                    } else {
                      deleteList.remove(
                        widget.listObject.userCode.toString(),
                      );
                    }
                    userDeviceController.state.selectList = deleteList;
                  },
                ),
              );
            else
              return FContainer();
          },
        )
      ],
    );
  }
}
