import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:keyboard/resource/string.gen.dart';

import '../data/bean/character_info.dart';
import '../resource/assets.gen.dart';
import '../resource/colors.gen.dart';

class CharacterDetailsDialog {
  static const String tag = 'CharacterDetailsDialog';

  static void show({
    required CharacterInfo characterInfo,
    required VoidCallback clickCallback,
    VoidCallback ? onDismiss,
  }) {
    SmartDialog.show(
      tag: tag,
      backType: SmartBackType.block,
      clickMaskDismiss: false,
      maskColor: ColorName.black70,
      builder: (_) {
        return SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                margin: EdgeInsets.only(left: 30.w, right: 30.w),
                padding: EdgeInsets.only(bottom: 28.h),
                alignment: Alignment.topCenter,
                width: double.infinity,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: Assets.images.bgCharacterDialog.provider(),
                    fit: BoxFit.cover,
                  ),
                  borderRadius: BorderRadius.circular(20.r),
                ),
                child: Column(
                  children: [
                    Container(
                      padding: EdgeInsets.only(
                        top: 12.h,
                        left: 12.w,
                        right: 12.w,
                        bottom: 12.h,
                      ),
                      margin: EdgeInsets.only(
                        left: 20.w,
                        right: 20.w,
                        top: 20.h,
                      ),
                      width: double.infinity,
                      decoration: ShapeDecoration(
                        color: Colors.white,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(20.r),
                        ),
                        shadows: [
                          BoxShadow(
                            color: const Color(0xFFDDE2F9),
                            blurRadius: 10.r,
                            offset: Offset(0, 4),
                            spreadRadius: 0,
                          ),
                        ],
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          Container(
                            padding: EdgeInsets.only(
                              top: 20.h,
                              left: 20.w,
                              right: 20.w,
                            ),
                            height: 236.w,
                            width: 236.w,
                            decoration: BoxDecoration(
                              image: DecorationImage(
                                image:
                                    Assets.images.bgCharacterDialogImage
                                        .provider(),
                                fit: BoxFit.fill,
                              ),
                              borderRadius: BorderRadius.circular(20.r),
                            ),
                            child: CachedNetworkImage(
                              imageUrl: characterInfo.imageUrl ?? "",
                              fit: BoxFit.fill,
                            ),
                          ),
                          SizedBox(height: 10.h),
                          Row(
                            crossAxisAlignment: CrossAxisAlignment.start,

                            children: [
                              Assets.images.iconCharacterDialogLogo.image(
                                width: 32.r,
                                height: 32.r,
                              ),
                              SizedBox(width: 10.w),
                              Expanded(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Row(
                                      children: [
                                        Text(
                                          characterInfo.name ?? "",
                                          style: TextStyle(
                                            color: Colors.black.withAlpha(204),
                                            fontSize: 14.sp,
                                            fontWeight: FontWeight.w700,
                                          ),
                                        ),
                                        SizedBox(width: 4.w),
                                        characterInfo.isVip == true
                                            ? Assets.images.iconCharacterVip
                                                .image(
                                                  width: 38.w,
                                                  height: 16.h,
                                                )
                                            : Container(),
                                      ],
                                    ),
                                    Text(
                                      characterInfo.description ?? "",
                                      softWrap: true,
                                      style: TextStyle(
                                        color: Colors.black.withAlpha(153),
                                        fontSize: 12.sp,
                                        fontWeight: FontWeight.w400,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                    SizedBox(height: 24.h),
                    GestureDetector(
                      onTap: () {
                        clickCallback.call();
                        SmartDialog.dismiss(tag: tag);
                      },
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 30.w),
                        width: double.infinity,
                        height: 48.h,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(50.r),
                          gradient:
                              characterInfo.isAdd == true
                                  ? null
                                  : const LinearGradient(
                                    colors: [
                                      Color(0xFF7D46FC),
                                      Color(0xFFBC87FF),
                                    ],
                                    begin: Alignment.topLeft,
                                    end: Alignment.bottomRight,
                                  ),
                          color:
                              characterInfo.isAdd == true
                                  ? const Color(0xFFEDE8FF)
                                  : null,
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            if (characterInfo.isLock == true &&
                                characterInfo.isVip == true)
                              Padding(
                                padding: EdgeInsets.only(right: 2.w),
                                child: Assets.images.iconCharacterLock.image(
                                  width: 18.r,
                                  height: 18.r,
                                ), // 锁定图标
                              ),
                            Text(
                              characterInfo.isAdd == true
                                  ? StringName.addedToKeyboard
                                  : StringName.addToKeyboard,
                              style: TextStyle(
                                color:
                                    characterInfo.isAdd == true
                                        ? const Color(0xFF7D46FC)
                                        : Colors.white,
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 24.h),
                child: GestureDetector(
                  onTap: () {
                    SmartDialog.dismiss(tag: tag);
                    onDismiss?.call();
                  },
                  child: Assets.images.iconCharacterDialogClose.image(
                    width: 40.r,
                    height: 40.r,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
