import 'package:flutter/Material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:keyboard/module/store/subscribe/recover_subscribe_controller.dart';
import 'package:keyboard/resource/string.gen.dart';

import '../../../base/base_view.dart';
import '../../../resource/assets.gen.dart';
import '../../../resource/colors.gen.dart';
import '../../../widget/gradient_btn.dart';

/// 点击确认时回调
typedef OnConfirmCallback = void Function();

/// 关闭弹窗时回调
typedef OnCloseCallback = void Function();

/// 恢复订阅弹窗内容
class RecoverSubscribeView extends BaseView<RecoverSubscribeController> {
  final String desc;

  final OnConfirmCallback onConfirmCallback;

  final OnCloseCallback onCloseCallback;

  const RecoverSubscribeView({
    super.key,
    required this.desc,
    required this.onConfirmCallback,
    required this.onCloseCallback,
  });

  @override
  backgroundColor() => Colors.transparent;

  @override
  Widget buildBody(BuildContext context) {
    return Stack(
      children: [
        Container(
          padding: EdgeInsets.symmetric(vertical: 24.h, horizontal: 16.w),
          decoration: BoxDecoration(
            color: ColorName.white,
            borderRadius: BorderRadius.all(Radius.circular(16.r)),
          ),
          child: Column(
            // 包裹内容
            mainAxisSize: MainAxisSize.min,
            children: [
              // 标题
              _buildTitle(),
              SizedBox(height: 12.h),
              _buildDesc(desc),
              SizedBox(height: 24.h),
              _buildSaveBtn(),
            ],
          ),
        ),
        Positioned(
          top: 0,
          right: 0,
          child: InkWell(
            onTap: () {
              controller.doClose(onCloseCallback);
            },
            splashColor: ColorName.transparent,
            child: Container(
              padding: EdgeInsets.all(14.w),
              child: Assets.images.iconCustomDirectionEditClose.image(
                width: 24.w,
                height: 24.w,
              ),
            ),
          ),
        ),
      ],
    );
  }

  /// 标题
  Widget _buildTitle() {
    return Text(
      StringName.recoverSubscribeTitle,
      style: TextStyle(
        fontSize: 16.sp,
        color: ColorName.black80,
        fontWeight: FontWeight.bold,
      ),
    );
  }

  /// 描述
  Widget _buildDesc(String desc) {
    return Text(
      desc,
      style: TextStyle(
        fontSize: 16.sp,
        color: ColorName.black60,
        fontWeight: FontWeight.w400,
      ),
    );
  }

  /// 保存按钮
  Widget _buildSaveBtn() {
    return SizedBox(
      width: double.infinity,
      child: GradientTextBtn(
        StringName.recoverSubscribeConfirm,
        onPressed: () {
          controller.doOnConfirm(onConfirmCallback);
        },
      ),
    );
  }
}
