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

///
/// 商品详情底部Widget
///
class GoodsDetailsFooterWidget extends StatelessWidget {

  final Map<String, dynamic> model;

  const GoodsDetailsFooterWidget(this.model);

  @override
  Widget build(BuildContext context) {
    return GooddsDetailsFooterContainer();
  }
}

class GooddsDetailsFooterContainer extends StatefulWidget {
  @override
  _GooddsDetailsFooterContainerState createState() => _GooddsDetailsFooterContainerState();
}

class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContainer> {
  /// 打开首页
  void _openHome() {}

  /// 收藏
  void _collectOnClick() {}

  /// 分享
  void _shareOnClick() {}

  /// 自购省
  void _savemoneyOnClick() {}

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 70,
      width: double.infinity,
      padding: const EdgeInsets.only(bottom: 10, top: 12.5, left: 21, right: 12.5),
      decoration: BoxDecoration(
        boxShadow:[
          BoxShadow(color: Colors.grey[300], offset: Offset(0.0, 0.0), blurRadius: 5.0, spreadRadius: 2.0),
          BoxShadow(color: Colors.grey[300], offset: Offset(0.0, 0.0)),
        ],
        color: Colors.white
      ),
      child: _getMainWidet(),
    );
  }

  /// 主Widget
  Widget _getMainWidet() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        /// 首页与收藏
        _getLeftWidget(),

        /// 分享赚与自购省
        _getRightWidget(),
      ],
    );
  }

  /// 首页 和 收藏
  Widget _getLeftWidget() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () => _openHome(),
            child: Padding(
              padding: const EdgeInsets.only(right: 35),
              child: _getCustomWidget('首页', '999999', null),
            )),
        GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () => _collectOnClick(),
            child: Padding(padding: const EdgeInsets.only(right: 0), child: _getCustomWidget('收藏', '999999', null)))
      ],
    );
  }

  /// 分享赚与自购省
  Widget _getRightWidget() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[_getFxzButton(), _getZgsButton()],
    );
  }

  /// 分享赚，
  Widget _getFxzButton() {
    return GestureDetector(
      onTap: () => _shareOnClick(),
      child: Container(
        alignment: Alignment.center,
        padding: const EdgeInsets.only(left: 30, right: 30, top: 5, bottom: 5),
        decoration: BoxDecoration(
          gradient: LinearGradient(colors: [HexColor.fromHex('#FFCA66'), HexColor.fromHex('#FFD961')], begin: Alignment.centerLeft, end: Alignment.centerRight),
          borderRadius: BorderRadius.only(
            bottomLeft: Radius.circular(25),
            topLeft: Radius.circular(25)
          )
        ),
        child: Column(
          children: <Widget>[
            RichText(
              text: TextSpan(text: '¥', style: TextStyle(fontSize: 12, color: HexColor.fromHex('FFFFFF')), children: [
                TextSpan(text: '3.10', style: TextStyle(fontSize: 15, color: HexColor.fromHex('#FFFFFF'))),
              ]),
            ),
            Text('分享赚', style: TextStyle(color: HexColor.fromHex('#FFFFFF'), fontSize: 15))
          ],
        ),
      ),
    );
  }

  /// 自购省
  Widget _getZgsButton() {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () => _savemoneyOnClick(),
      child: Container(
        alignment: Alignment.center,
        padding: const EdgeInsets.only(left: 30, right: 30, top: 5, bottom: 5),
        decoration: BoxDecoration(
          gradient: LinearGradient(colors: [HexColor.fromHex('#FF6969'), HexColor.fromHex('#FF4646')], begin: Alignment.centerLeft, end: Alignment.centerRight),
            borderRadius: BorderRadius.only(
                bottomRight: Radius.circular(25),
                topRight: Radius.circular(25)
            )
        ),
        child: Column(
          children: <Widget>[
            RichText(
              text: TextSpan(text: '¥', style: TextStyle(fontSize: 12, color: HexColor.fromHex('FFFFFF')), children: [
                TextSpan(text: '23.10', style: TextStyle(fontSize: 15, color: HexColor.fromHex('#FFFFFF'))),
              ]),
            ),
            Text('自购省', style: TextStyle(color: HexColor.fromHex('#FFFFFF'), fontSize: 15))
          ],
        ),
      ),
    );
  }

  Widget _getCustomWidget(String text, String textColor, String icon) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        /// 图标
        Container(height: 25, width: 25, color: Colors.red, margin: const EdgeInsets.only(bottom: 3)),

        /// 图片
        Text(text, style: TextStyle(color: HexColor.fromHex(textColor), fontSize: 11))
      ],
    );
  }
}
