/*
 * @Author: ChenYaJin
 * @Date: 2023-10-23 17:51:51
 * @LastEditors: wuwei
 * @LastEditTime: 2024-02-02 15:25:33
 * @Description: 房屋搜索列表
 */

part of '../index.dart';

class _HouseListComponent extends StatelessWidget {
  const _HouseListComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final _Store store = Provider.of<_Store>(context);
    final colorScheme = WTheme.of(context).colorScheme;

    return Wisdom.column(
      children: [
        Listener(
          onPointerUp: (e) => store.onSetExpand(false),
          child: Consumer<_Store>(
            builder: (ctx, store, child) {
              return WSearch(
                hintText: '请输入房屋名称进行搜索',
                onSubmitted: (value) => store.onHouseSearchTrigger(value),
                onCancel: () => store.onHouseSearchTrigger(''),
                moonlight: false,
                padding: EdgeInsets.symmetric(vertical: 10.pt),
                isDark: false,
                initValue: store.houseSearchWord,
              );
            },
          ),
        ),
        WisScrollView(
          key: store.houseScrollViewKey,
          onInit: () => store.getHouseData(),
          // onRefresh: () => store.getHouseData(isLoad: false),
          // onLoad: () => store.getHouseList(isLoad: true),
          slivers: [
            Wisdom.row(
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(8.pt),
                  topRight: Radius.circular(8.pt)),
              color: Colors.white,
              margin: EdgeInsets.fromLTRB(
                15.pt,
                0,
                15.pt,
                0,
              ),
              padding: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 0),
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                if (store.currentHouseFilterData.isEmpty) ...[
                  Wisdom.column(
                    width: (MediaQuery.of(context).size.width - 30) / 4,
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    onTap: () => store.onClearFilterData(),
                    padding: EdgeInsets.fromLTRB(0, 10.pt, 0, 5.pt),
                    children: [
                      WisText(
                        '选择楼栋',
                        overflow: TextOverflow.ellipsis,
                        size: 15.pt,
                        color: store.currentHouseFilterData.isNotEmpty
                            ? colorScheme.grey
                            : colorScheme.mainTitle,
                      ),
                      SizedBox(height: 5.pt),
                      Wisdom(
                        height: 3.5.pt,
                        width: 45.pt,
                        borderRadius: BorderRadius.circular(20.pt),
                        color: store.currentHouseFilterData.isNotEmpty
                            ? Colors.transparent
                            : colorScheme.green,
                      ),
                    ],
                  ).asFlexible(flex: 1),
                ],
                if (store.currentHouseFilterData.isNotEmpty) ...[
                  for (var item in store.currentHouseFilterData) ...[
                    Wisdom(
                      width: (MediaQuery.of(context).size.width - 30) / 4,
                      child: Wisdom.column(
                        onTap: () => store.onClickFilterItem(item),
                        padding: EdgeInsets.fromLTRB(0, 10.pt, 0, 5.pt),
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          WisText(
                            '${store.assetTypeNameList[item.status]}:${item.name}',
                            overflow: TextOverflow.ellipsis,
                            color:
                                colorScheme.grey,
                            size: 15.pt,
                          ),
                          SizedBox(height: 5.pt),
                         
                            SizedBox(height: 3.5.pt),
                          
                        ],
                      ),
                    ).asFlexible(flex: 1),
                  ],
                  if (store.currentHouseFilterData.length > 0 &&
                      store.currentHouseFilterData.length < 4) ...[
                    Wisdom(
                      width: (MediaQuery.of(context).size.width - 30) / 4,
                      child: Wisdom.column(
                        padding: EdgeInsets.fromLTRB(0, 10.pt, 0, 5.pt),
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          WisText(
                            '${store.currentHouseFilterData.length == 1 ? '选择单元' : store.currentHouseFilterData.length ==  2 ? '选择楼层' : '选择房屋'}',
                            overflow: TextOverflow.ellipsis,
                            color: colorScheme.mainTitle,
                            size: 15.pt,
                          ),
                          SizedBox(height: 5.pt),
                          Wisdom(
                            height: 3.5.pt,
                            width: 45.pt,
                            borderRadius: BorderRadius.circular(20.pt),
                            color: colorScheme.green,
                          ),
                        ],
                      ),
                    ).asFlexible(flex: 1),
                  ]
                ],
              ],
            ).asSliver(),
            SliverToBoxAdapter(
              child: Wisdom.column(
                margin: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 15.pt),
                color: Colors.white,
                borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(8.pt),
                    bottomRight: Radius.circular(8.pt)),
                boxShadow: [
                  BoxShadow(
                    color: Color(0x08000000),
                    offset: Offset(0, 2.pt),
                    blurRadius: 10.pt,
                    spreadRadius: 2.5.pt,
                  ),
                ],
                children: [
                  Divider(
                    height: 15.pt,
                    color: colorScheme.divider2,
                  ),
                  if (store.houseList.isEmpty)
                    Wisdom.column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      margin: EdgeInsets.only(bottom: 10.pt),
                      padding: EdgeInsets.symmetric(vertical: 15.pt),
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8.pt),
                      height: MediaQuery.of(context).size.height * 0.5,
                      children: [
                        WEmptyWidget(
                          text: Text('暂无数据~~'),
                        ),
                      ],
                    ),
                  for (var item in store.houseList) ...[
                    Wisdom.row(
                        onTap: () => store.onClickHouseItem(item),
                        padding: EdgeInsets.symmetric(
                            vertical: 7.5.pt, horizontal: 15.pt),
                        children: [
                          WisText(
                            '${item.name}',
                            overflow: TextOverflow.ellipsis,
                            size: 15.pt,
                          ).asExpanded(),
                          Wisdom.row(
                            children: [
                              Icon(Icons.arrow_forward_ios, size: 13.pt),
                            ],
                          )
                        ]),
                  ],
                  SizedBox(height: 7.5.pt),
                ],
              ),
            ),
          ],
        ).asExpanded(),
      ],
    );
  }
}
