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

part of '../index.dart';

class _CarListComponent extends StatelessWidget {
  const _CarListComponent({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.onCarSearchTrigger(value),
                onCancel: () => store.onCarSearchTrigger(''),
                moonlight: false,
                padding: EdgeInsets.symmetric(vertical: 10.pt),
                isDark: false,
                initValue: store.carSearchWord,
              );
            },
          ),
        ),
        WisScrollView(
          key: store.carScrollViewKey,
          onInit: () => store.getCarList(isLoad: false),
          onRefresh: () => store.getCarList(isLoad: false),
          onLoad: () => store.getCarList(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.carList.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.carList) ...[
                    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(),
      ],
    );
  }
}
