import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/goods_details/evaluate/model/goods_details_evaluate_model.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

///
/// 商品详情评价Widget
///
class GoodsDetailsEvaluateWidget extends StatelessWidget {
  final Map<String, dynamic> model;
  GoodsDetailsEvaluateModel _modell;

  GoodsDetailsEvaluateWidget(this.model, {Key key}) : super(key: key) {
    try {
      _modell = GoodsDetailsEvaluateModel.fromJson(jsonDecode(model['data']));
    } catch (e) {
      Logger.log('GoodsDetailsEvaluateWidget e = $e}');
    }
  }

  /// 点击查看更多
  void _openLookMore() {}

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => _openLookMore(),
      behavior: HitTestBehavior.opaque,
      child: Container(
        color: Colors.white,
        margin: const EdgeInsets.only(top: 6),
        width: double.infinity,
        padding: const EdgeInsets.only(top: 15, bottom: 15, left: 12.5, right: 12.5),
        child: getMainWidget(_modell),
      ),
    );
  }

  /// 评价以及查看更多
  Widget getMainWidget(GoodsDetailsEvaluateModel model) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        getLeftWidget(model),
        Text(model?.more ?? '查看更多 >', style: TextStyle(color: HexColor.fromHex(model?.more_color ?? '#999999'), fontSize: 11)),
      ],
    );
  }


  /// 左边图标加文字
  Widget getLeftWidget(GoodsDetailsEvaluateModel model){
    return Row(
      children: <Widget>[
        CachedNetworkImage(
          imageUrl: model?.icon ?? '',
          width: 12,
        ),
        const SizedBox(width: 2.5),
        Text(model?.title ?? '宝贝评价', style: TextStyle(color: HexColor.fromHex(model?.title_color ?? '#333333'), fontSize: 12)),
      ],
    );
  }

}
