/*
 * @Author: WuWei
 * @Date: 2020-06-17 15:12:49
 * @LastEditors: WuWei
 * @LastEditTime: 2020-06-18 10:03:02
 * @Description:
 */
part of '../index.dart';

class _ParkCar extends StatelessWidget {
  const _ParkCar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<SearchParkDetailStore>(context);

    return SliverToBoxAdapter(
        child: Wisdom(
            padding: EdgeInsets.all(10.pt),
            child: Wisdom.column(
              mainAxisSize: MainAxisSize.min,
              color: Colors.white,
              borderRadius: BorderRadius.circular(14.pt),
              boxShadow: [
                BoxShadow(
                  color: Color(0x40000000),
                  blurRadius: 10.pt,
                  spreadRadius: -5.pt,
                )
              ],
              children: <Widget>[
                Wisdom.row(
                  mainAxisSize: MainAxisSize.max,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(14.pt),
                  ),
                  padding: EdgeInsets.all(15.pt),
                  color: Color(0xFFE5EAFF),
                  children: <Widget>[
                    Wisdom(
                      borderRadius: BorderRadius.circular(100.pt),
                      width: 12.pt,
                      height: 12.pt,
                      color: Color(0xFF666666),
                      margin: EdgeInsets.only(right: 5.pt),
                    ),
                    WisText.c666(
                      '相关车辆',
                      size: 16.pt,
                    )
                  ],
                ),
                store.parkDetail?.cars != null &&
                        store.parkDetail?.cars?.length != null &&
                        store.parkDetail!.cars!.length > 0
                    ? (Wisdom.column(
                      mainAxisSize: MainAxisSize.min,
                  padding: EdgeInsets.all(15.pt),
                        children: store.parkDetail!.cars!
                            .map((item) => new _CarItem(
                                item: item,
                                isLast: store.parkDetail!.cars!.length ==
                                    (store.parkDetail!.cars!.indexOf(item) + 1),
                                index: store.parkDetail!.cars!.indexOf(item)))
                            .toList())) as Widget
                    : Wisdom.row(
                        padding:
                            EdgeInsets.fromLTRB(15.pt, 22.pt, 15.pt, 22.pt),
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: <Widget>[
                          WisText.c999(
                            '暂无数据',
                            size: 14.pt,
                          )
                        ],
                      )
              ],
            )));
  }
}

class _CarItem extends StatelessWidget {
  const _CarItem({
    Key? key,
    this.item,
    this.index,
    this.isLast = false,
  }) : super(key: key);

  /// 是否最后一个元素[isLast]
  final bool isLast;

  /// 元素索引 [index]
  final int? index;

  /// 元素[item]
  final item;

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<SearchParkDetailStore>(context);

    return Wisdom.column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      padding:
          EdgeInsets.fromLTRB(0, index == 0 ? 0 : 15.pt, 0, isLast ? 0 : 15.pt),
      border: Border(
          bottom: BorderSide(color: isLast ? Colors.white : Color(0xFFF4F4F4))),
      children: <Widget>[
        Wisdom(
          margin: EdgeInsets.only(bottom: 5.pt),
          child: WisText('${item?.carNo ?? ''}'),
        ),
        Wisdom.row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            WisText.c999(
              '车辆类型：${store.carType[item?.type] ?? ''}',
              size: 12.pt,
            ),
            WisText.c999(
              '是否包月：${(item?.monthSubscribe!= null && item.monthSubscribe)? '是' : '否'}',
              size: 12.pt,
            )
          ],
        ),
      ],
    );
  }
}
