import 'dart:ui' as ui;
import 'package:app_package/app_package.dart';
import 'package:community_package/src/view_models/private_community_index.model.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import './type_tag.dart';

class ListItem extends StatelessWidget {
  const ListItem({
    Key? key,
    this.item,
    this.isDetail = false,
  }) : super(key: key);
  final item;
  final bool isDetail;
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store =
        Provider.of<PrivateCommunityIndexStore>(context, listen: true);
    return WisCard(
      margin:
          EdgeInsets.only(top: 10.pt, bottom: 0.pt, left: 15.pt, right: 15.pt),
      color: Colors.white,
      padding: EdgeInsets.all(5.pt),
      child: Wisdom.column(
        onTap: () => {
          if (!isDetail)
            {
              store.routeToDetail(item),
            }
        },
        color: Colors.white,
        padding: EdgeInsets.symmetric(
          vertical: 10.pt,
          horizontal: 15.pt,
        ),
        margin: EdgeInsets.only(bottom: 10.pt),
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.min,
        children: [
          Wisdom.row(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            margin: EdgeInsets.only(bottom: 15.pt),
            children: [
              if (item?.logo?.isEmpty)
                WImage.asset(
                  'lib/assets/icon_place_community.png',
                  height: 44.pt,
                  width: 44.pt,
                  borderRadius: BorderRadius.circular(22.pt),
                  package: 'community_package',
                ),
              if (item?.logo != null && item?.logo != '')
                WImage.network(
                  AppParseUtil.image(item?.logo),
                  height: 44.pt,
                  width: 44.pt,
                  borderRadius: BorderRadius.circular(22.pt),
                ),
              Wisdom.column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                margin: EdgeInsets.only(left: 15.pt),
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text.rich(
                    TextSpan(
                      children: [
                        WidgetSpan(
                          child: Wisdom(
                            margin: EdgeInsets.only(bottom: 3.pt),
                            child: Text(
                              '${item?.name ?? ''}',
                              style: TextStyle(
                                color: colorScheme.mainTitle,
                                fontWeight: FontWeight.w600,
                                fontSize: 15.pt,
                              ),
                            ),
                          ),
                        ),

                        /// 小区类型标签
                        if (item?.type != null && item.type.length > 0)
                          for (var type in item.type)
                            WidgetSpan(
                              child: TypeTag(type: type),
                              alignment: ui.PlaceholderAlignment.middle,
                            ),
                      ],
                    ),
                  ),
                  Wisdom.row(
                    children: [
                      Text(
                        '${item?.address}',
                        style: TextStyle(
                          color: colorScheme.minor,
                          fontWeight: FontWeight.w300,
                          fontSize: 14.pt,
                        ),
                      ),
                    ],
                  )
                ],
              ).asExpanded(),
            ],
          ),
          Divider(
            color: colorScheme.divider,
          ),
          Wisdom.row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            margin: EdgeInsets.only(top: 15.pt),
            children: [
              Expanded(
                child: Wisdom.column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  padding: EdgeInsets.symmetric(
                    horizontal: 5.pt,
                  ),
                  border: Border(
                      right: BorderSide(
                    color: Color(0xffE6E6E6),
                    width: 0.5.pt,
                  )),
                  children: [
                    Text(
                      '${item?.buildNum ?? '--'}',
                      style: TextStyle(
                        color: Color(0xFF4FA3FA),
                        fontSize: 15.pt,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    Text(
                      '楼栋数量',
                      style: TextStyle(
                        color: colorScheme.mainTitle,
                        fontSize: 13.pt,
                        fontWeight: FontWeight.w300,
                      ),
                    ),
                  ],
                ),
                flex: 1,
              ),
              Expanded(
                child: Wisdom.column(
                  padding: EdgeInsets.symmetric(
                    horizontal: 5.pt,
                  ),
                  border: Border(
                      right: BorderSide(
                    color: Color(0xffE6E6E6),
                    width: 0.5.pt,
                  )),
                  children: [
                    Text(
                      '${item?.unitNum ?? '--'}',
                      style: TextStyle(
                        color: Color(0xFF4FA3FA),
                        fontSize: 15.pt,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    Text(
                      '单元数量',
                      style: TextStyle(
                        color: colorScheme.mainTitle,
                        fontSize: 13.pt,
                        fontWeight: FontWeight.w300,
                      ),
                    ),
                  ],
                ),
                flex: 1,
              ),
              Expanded(
                child: Wisdom.column(
                  padding: EdgeInsets.symmetric(
                    horizontal: 5.pt,
                  ),
                  border: Border(
                      right: BorderSide(
                    color: Color(0xffE6E6E6),
                    width: 0.5.pt,
                  )),
                  children: [
                    Text(
                      '${item?.houseNum ?? '--'}',
                      style: TextStyle(
                        color: Color(0xFF4FA3FA),
                        fontSize: 15.pt,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    Text(
                      '房屋数量',
                      style: TextStyle(
                        color: colorScheme.mainTitle,
                        fontSize: 13.pt,
                        fontWeight: FontWeight.w300,
                      ),
                    ),
                  ],
                ),
                flex: 1,
              ),
              Expanded(
                child: Wisdom.column(
                  padding: EdgeInsets.symmetric(
                    horizontal: 5.pt,
                  ),
                  children: [
                    Text(
                      '${item?.residentNum ?? '--'}',
                      style: TextStyle(
                        color: Color(0xFF4FA3FA),
                        fontSize: 15.pt,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    Text(
                      '住户数量',
                      style: TextStyle(
                        color: colorScheme.mainTitle,
                        fontSize: 13.pt,
                        fontWeight: FontWeight.w300,
                      ),
                    ),
                  ],
                ),
                flex: 1,
              ),
            ],
          ),
        ],
      ),
    );
  }
}
