import 'dart:convert';

import 'package:flutter/material.dart';
import 'model/goods_details_recommend_titile_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

///
/// 商品详情的推荐列表小标题
///
class GoodsDetailsRecommendTitleWidget extends StatelessWidget {
  final Map<String, dynamic> data;
  GoodsDetailsRecommendTitileModel model;

  GoodsDetailsRecommendTitleWidget(this.data, {Key key}) : super(key: key) {
    try {
      model = GoodsDetailsRecommendTitileModel.fromJson(jsonDecode(data['data']));
    } catch (e, s) {
      Logger.error(e, s);
    }
  }

  @override
  Widget build(BuildContext context) {

    if( null == model) return Container();

    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(top: ParseUtil.stringParseDouble(model?.topMargin, defVal: 0), left: ParseUtil.stringParseDouble(model?.leftRightMargin), right: ParseUtil.stringParseDouble(model?.leftRightMargin)),
      padding: EdgeInsets.only(top: 15, bottom: 15),
      decoration: BoxDecoration(
        color: HexColor.fromHex(model?.bgColor),
        borderRadius: BorderRadius.only(
          topRight: Radius.circular(ParseUtil.stringParseDouble(model?.topRightRadius)),
          topLeft: Radius.circular(ParseUtil.stringParseDouble(model?.topLeftRadius)),
          bottomRight: Radius.circular(ParseUtil.stringParseDouble(model?.bottomRightRadius)),
          bottomLeft: Radius.circular(ParseUtil.stringParseDouble(model?.bottomLeftRadius)),
        )
      ),
      child: _buildMainWidget(),
    );
  }

  Widget _buildMainWidget() {
    Widget rlt;
    switch(model?.moduleType ?? '') {
      case 'product_detail_recommend_title1':
        rlt = _buildWidgetStyle1();
        break;
      default:
        rlt = Container();
        break;
    }
    return rlt;

  }

  // module_type = product_detail_recommend_title1
  Widget _buildWidgetStyle1() {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          CachedNetworkImage(imageUrl: model?.icon ?? '', width: 15),
          const SizedBox(width: 7.5),
          Text(model?.title, style: TextStyle(color: HexColor.fromHex(model?.titleColor), fontSize: 14, fontWeight: FontWeight.bold),)
        ],
      ),
    );
  }

}
