/*
 * @Author: WuWei
 * @Date: 2020-08-10 11:52:33
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-11-02 09:41:52
 * @Description:
 */
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../view_models/private_index_store.dart';

class ListItem extends StatelessWidget {
  const ListItem({Key? key, this.item, this.isLast, this.toDetail})
      : super(key: key);
  final item;
  final isLast;
  final Function? toDetail;

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<PrivateIndexStore>(context, listen: true);

    return WisCard(
      margin: EdgeInsets.only(left: 15.pt, right: 15.pt, top: 10.pt),
      child: Wisdom.row(
        onTap: () => toDetail!(),
        padding: EdgeInsets.all(15.pt),
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Wisdom.column(
            children: <Widget>[
              Wisdom.row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  if (item?.invalid == true)
                    Image.asset(
                      'lib/assets/cancel.png',
                      height: 18.pt,
                      width: 18.pt,
                      package: 'pay_package',
                    )
                  else if (item?.moneyFlow == 'out')
                    Image.asset(
                      'lib/assets/out.png',
                      height: 18.pt,
                      width: 18.pt,
                      package: 'pay_package',
                    )
                  else
                    Image.asset(
                      'lib/assets/in.png',
                      height: 18.pt,
                      width: 18.pt,
                      package: 'pay_package',
                    ),
                  SizedBox(width: 5.pt),
                  Wisdom.row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      WisText(
                        item?.assetName ?? '--',
                        color: colorScheme.primary,
                        size: 16.pt,
                        weight: FontWeight.w300,
                        overflow: TextOverflow.ellipsis,
                      ).asExpanded(),
                    ],
                  ).asExpanded(),
                  WisText(
                    '￥${item?.payFee ?? '0'}',
                    color: store.getMoneyFlowColorFun(item),
                    weight: FontWeight.bold,
                    size: 16.pt,
                  )
                ],
              ),
              Wisdom.row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                margin: EdgeInsets.only(top: 10.pt),
                children: <Widget>[
                  WisText(
                    '${item?.payAt ?? '--'}',
                    color: colorScheme.minor,
                    size: 14.pt,
                    weight: FontWeight.w300,
                  ),
                  SizedBox(width: 5.pt),
                  Wisdom(
                    child: WTag(
                      plain: true,
                      color: store.getPayWayColorFun(item?.payWay),
                      child: Text.rich(
                        TextSpan(children: [
                          WidgetSpan(
                            child: WisText(
                              item?.payWay ?? '--',
                              size: 13.pt,
                            ),
                          ),
                          WidgetSpan(
                            child: WisText(
                              '-' + item?.payType,
                              size: 13.pt,
                            ),
                          ),
                        ]),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                  ).asFlexible(flex: 1),
                ],
              ),
            ],
          ).asExpanded(),
        ],
      ),
    );
  }
}
