/*
 * @Author: ChenYaJin
 * @Date: 2023-10-23 17:51:51
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-11-09 14:44:04
 * @Description: 车位搜索列表
 */

part of '../index.dart';

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

    return Wisdom.column(
      children: [
        Listener(
          onPointerUp: (e) => store.onSetExpand(false),
          child: Consumer<_Store>(
            builder: (ctx, store, child) {
              return WSearch(
                hintText: '请输入车位名称进行搜索',
                onSubmitted: (value) => store.onParkSearchTrigger(value),
                onCancel: () => store.onParkSearchTrigger(''),
                moonlight: false,
                padding: EdgeInsets.symmetric(vertical: 10.pt),
                isDark: false,
                initValue: store.parkSearchWord,
                isControlOutside: true,
                controller: TextEditingController(text: store.parkSearchWord),
              );
            },
          ),
        ),
        WisScrollView(
          key: store.parkScrollViewKey,
          onInit: () => store.getParkList(isLoad: false),
          onRefresh: () => store.getParkList(isLoad: false),
          onLoad: () => store.getParkList(isLoad: true),
          slivers: [
            SliverToBoxAdapter(
              child: Wisdom.column(
                margin: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 15.pt),
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(8.pt)),
                boxShadow: [
                  BoxShadow(
                    color: Color(0x08000000),
                    offset: Offset(0, 2.pt),
                    blurRadius: 10.pt,
                    spreadRadius: 2.5.pt,
                  ),
                ],
                children: [
                  if (store.parkList.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.parkList) ...[
                    Wisdom.row(
                        onTap: () => store.route2ReceiptDetail(item),
                        padding: EdgeInsets.symmetric(
                            vertical: 10.pt, horizontal: 15.pt),
                        children: [
                          WisText(
                            '${item.assetName}',
                            size: 15.pt,
                            overflow: TextOverflow.ellipsis,
                          ).asExpanded(),
                          Wisdom.row(
                            children: [
                              Icon(Icons.arrow_forward_ios, size: 13.pt),
                            ],
                          )
                        ]),
                  ],
                ],
              ),
            ),
          ],
        ).asExpanded(),
      ],
    );
  }
}
