/*
 * @Author: XianKaiQun
 * @Date: 2020-08-17 11:47:25
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-09-28 15:21:35
 * @Description: 
 */
part of '../index.dart';

///防作弊
class _PreventCheatingComponent extends StatelessWidget {
  const _PreventCheatingComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateRepairHandleStore>(context);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final theme = Theme.of(context);
    final textTheme = theme.textTheme;
    return WisCard(
      margin: EdgeInsets.symmetric(vertical: 7.5.pt, horizontal: 15.pt),
      padding: EdgeInsets.all(15.pt),
      isSliver: true,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Wisdom.rich(
            children: [
              if (store.cheatPhoto)
                TextSpan(
                  text: '* ',
                  style: TextStyle(color: colorScheme.danger),
                ),
              TextSpan(
                text: '现场照片',
                style: textTheme.titleMedium!.copyWith(
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
          SizedBox(height: 15.pt),
          Wrap(
            runSpacing: 10.pt,
            spacing: 10.pt,
            children: <Widget>[
              for (var i = 0; i < store.imageIds.length; i++)
                () {
                  final imageId = store.imageIds[i];
                  final url = AppParseUtil.image(imageId);
                  final photoList = store.imageIds
                      .map((id) =>
                          CachedNetworkImageProvider(AppParseUtil.image(id)))
                      .toList();
                  return Stack(
                    children: <Widget>[
                      Wisdom(
                        onTap: () => WisPhotoViewUtil.show(photoList, i),
                        padding: EdgeInsets.only(top: 8.pt, right: 8.pt),
                        child: WImage.network(
                          url,
                          fit: BoxFit.cover,
                          width: 80.pt,
                          height: 80.pt,
                        ),
                      ),
                      Positioned(
                        top: 0,
                        right: 0,
                        child: WDot.delete(
                          onTap: () => store.removeimageId(i),
                        ),
                      ),
                    ],
                  );
                }(),
              if (store.imageIds.length < store.cheatPhotoMaxCount!)
                WLoadingWrapper(
                  action: () => store.photograph(),
                  builder: (context, action, child) {
                    return Wisdom(
                      onTap: action,
                      margin: EdgeInsets.only(top: 8.pt, right: 8.pt),
                      padding: EdgeInsets.only(top: 10.pt),
                      color: colorScheme.background,
                      alignment: Alignment.center,
                      width: 80.pt,
                      height: 80.pt,
                      child: child,
                    );
                  },
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Wisdom(
                        child: Icon(Icons.camera_alt),
                      ),
                      Text(
                        '${store.imageIds.length}/${store.cheatPhotoMaxCount}',
                        style: TextStyle(
                          color: Colors.grey,
                          fontSize: 10.pt,
                        ),
                      )
                    ],
                  ),
                ),
            ],
          ),
        ],
      ),
    );
  }
}
