import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:chat/configs/app_colors.dart';
import 'package:chat/controllers/private_controller.dart';
import 'package:chat/routes/contact_routes.dart';
import 'package:chat/services/tim/conversation_service.dart';
import 'package:chat/views/home/widgets/action_item.dart';
import 'package:chat/widgets/custom_avatar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ConversationInfoPrivatePage extends StatelessWidget {
  const ConversationInfoPrivatePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetX<PrivateController>(builder: (_) {
      return Scaffold(
        appBar: AppBar(
          title: const Text('聊天信息'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                padding: const EdgeInsets.all(16),
                decoration: const BoxDecoration(color: AppColors.white),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    InkWell(
                      onTap: () {
                        Get.toNamed(
                          ContactRoutes.friendProfile,
                        );
                      },
                      child: Column(
                        children: [
                          CustomAvatar(
                            _.currentFriend.value.userProfile?.faceUrl,
                            size: 54,
                          ),
                          const SizedBox(height: 4),
                          Text(
                            _.currentFriend.value.conversation!.showName!,
                            style: const TextStyle(
                              color: AppColors.unactive,
                              fontSize: 12,
                            ),
                          ),
                        ],
                      ),
                    ),
                    const SizedBox(width: 16),
                    InkWell(
                      onTap: () {
                        Get.toNamed(
                          ContactRoutes.groupCreate,
                        );
                      },
                      child: Container(
                        width: 54,
                        height: 54,
                        decoration: BoxDecoration(
                          color: AppColors.unactive.withOpacity(0.1),
                          border: Border.all(
                            color: AppColors.unactive.withOpacity(0.3),
                            width: 0.4,
                            style: BorderStyle.solid,
                          ),
                          borderRadius: BorderRadius.circular(8),
                        ),
                        child: const Center(
                          child: Icon(
                            Icons.add,
                            color: AppColors.unactive,
                          ),
                        ),
                      ),
                    )
                  ],
                ),
              ),
              const SizedBox(height: 8),
              ActionItem(
                '查找聊天记录',
                isFirst: true,
                isLast: true,
                onTap: () {
                  // Get.toNamed(
                  //   ImRoutes.conversationSearch,
                  // );
                },
              ),
              const SizedBox(height: 8),
              ActionItem(
                '消息免打扰',
                isFirst: true,
                rightWidget: SizedBox(
                  height: 24,
                  child: Switch(
                    value: _.currentFriend.value.conversation!.recvOpt == 1,
                    onChanged: (e) async {
                      _.changeReceiveOpt();
                    },
                    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  ),
                ),
              ),
              ActionItem(
                '置顶聊天',
                isLast: true,
                rightWidget: SizedBox(
                  height: 24,
                  child: Switch(
                    value: _.currentFriend.value.conversation!.isPinned!,
                    onChanged: (e) async {
                      _.togglePinned();
                    },
                    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  ),
                ),
              ),
              const SizedBox(height: 8),
              ActionItem(
                '清空聊天记录',
                isFirst: true,
                isLast: true,
                onTap: () async {
                  OkCancelResult result = await showOkCancelAlertDialog(
                    style: AdaptiveStyle.iOS,
                    context: Get.context!,
                    title: '系统提示',
                    message: '将删除该聊天记录，是否继续？',
                    okLabel: '确定',
                    cancelLabel: '取消',
                    defaultType: OkCancelAlertDefaultType.ok,
                  );

                  if (result == OkCancelResult.ok) {
                    TimConversationService.to.clearHistoryMessage(
                      _.currentFriend.value.conversation!,
                    );
                  }
                },
              ),
            ],
          ),
        ),
      );
    });
  }
}
