import 'package:flutter/material.dart';
import 'package:huixiang/retrofit/data/activity.dart';
import 'package:huixiang/retrofit/data/article.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class WebHeader extends StatefulWidget {
  final Map arguments;
  final Activity activity;
  final Article article;
  final double fontSize;

  WebHeader(this.arguments, this.activity, this.article, this.fontSize);

  @override
  State<StatefulWidget> createState() {
    return _WebHeader();
  }
}

class _WebHeader extends State<WebHeader> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          color: Colors.white,
          padding: EdgeInsets.all(12),
          alignment: Alignment.centerLeft,
          child: Text(
            widget.activity != null
                ? widget.activity.mainTitle
                : widget.article != null
                    ? widget.article.mainTitle
                    : "",
            style: TextStyle(
              fontSize: widget.fontSize,
              fontWeight: FontWeight.bold,
              color: Color(0xFF353535),
            ),
          ),
        ),
        Container(
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 12.w),
          child: Row(
            children: [
              InkWell(
                child: Text(
                  "${widget.activity != null ? (widget.activity.storeName ?? "")
                      : (widget.article != null && widget.article.author != null)
                      ? (widget.article.author.name ?? "") : ""}",
                  style: TextStyle(
                    fontWeight: FontWeight.normal,
                    fontSize: widget.fontSize - 2,
                    color: Colors.blue,
                  ),
                ),
                onTap: () {
                  if (widget.activity != null) {
                    if (widget.arguments["source"] != null &&
                        widget.arguments["source"] == widget.activity.storeId) {
                      Navigator.of(context).pop();
                    } else {
                      // Navigator.of(context).pushNamed(
                      //   '/router/union_detail_page',
                      //   arguments: {
                      //     "id": widget.activity.storeId,
                      //     "source": widget.arguments["activityId"]
                      //   },
                      // );
                      ///TODO: 进入店铺
                      // if(widget.stores[selectIndex].posType.code == "NORMALSTORE") {
                      //   toScan(widget.stores[selectIndex]);
                      // } else {
                      //   Navigator.of(context).pushNamed(
                      //     '/router/store_order',
                      //     arguments: {
                      //       "id": widget.activity.storeId,
                      //       "tenant": widget.stores[selectIndex].tenantCode,
                      //       "storeName": widget.activity.storeName
                      //     },
                      //   );
                      // }
                    }
                  }
                },
              ),
              SizedBox(
                width: 10.w,
              ),
              Text(
                widget.activity != null
                    ? widget.activity.createTime
                    : widget.article != null
                        ? widget.article.createTime
                        : "",
                style: TextStyle(
                  fontWeight: FontWeight.normal,
                  fontSize: widget.fontSize - 4,
                  color: Colors.grey,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}