import 'package:cpt_auth/modules/auth_login/auth_login_page.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:domain/entity/id_name_entity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared/utils/log_utils.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/widget_export.dart';

import '../select_estate_view_model.dart';

//输入文本框
class AttachSearchDialog extends HookConsumerWidget {
  final ValueChanged<IdNameEntity?> onSelected;

  AttachSearchDialog({
    required this.onSelected,
  });

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final state = ref.watch(selectEstateViewModelProvider);

    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 38),
      padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
      decoration: BoxDecoration(
        color: context.appColors.whiteBG,
        borderRadius: BorderRadius.circular(5.0), // 5个圆角
        boxShadow: [
          BoxShadow(
            color: const Color(0xFF656565).withOpacity(0.1), // 阴影颜色，并且设置透明度
            offset: const Offset(0, 1.5), // 阴影的偏移量
            blurRadius: 2.5, // 模糊半径
            spreadRadius: 1.5, // 扩散半径
          ),
        ],
      ),
      constraints: const BoxConstraints(
        maxHeight: 200, // 设置最大高度
      ),
      child: ListView.builder(
        padding: EdgeInsets.zero,
        shrinkWrap: true,
        physics: const AlwaysScrollableScrollPhysics(),
        itemCount: state.estateList?.length ?? 0,
        itemBuilder: (context, index) {
          final item = state.estateList?[index];
          return MyTextView(
            item?.name ?? "",
            fontSize: 15,
            paddingTop: 10,
            paddingBottom: 10,
            isFontRegular: true,
            onClick: () {
              onSelected(item); // 选中回调
              onCancel();
            },
            textColor: context.appColors.textBlack,
          );
        },
      ),
    );
  }
}

//取消弹框
void onCancel() async {
  SmartDialog.dismiss();
}
