/*
 * @Author: XianKaiQun
 * @Date: 2020-09-29 11:39:03
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-10-22 17:59:41
 * @Description: 
 */

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

///标签
class WTag extends StatelessWidget {
  const WTag({
    Key? key,
    this.child,
    this.color,
    this.plain = true,
    this.backgroundColor,
    this.padding,
    this.margin,
    this.borderRadius,
    this.border,
  }) : super(key: key);
  final Widget? child;

  ///标签主色
  final Color? color;

  ///是否朴素，会影响主色的判断
  final bool plain;

  ///背景颜色，为空会根据主色自行调整
  final Color? backgroundColor;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;

  ///边框,为空会根据主色进行调整
  final Border? border;

  ///圆角   默认2pt
  final BorderRadius? borderRadius;

  @override
  Widget build(BuildContext context) {
    final _margin = margin ?? EdgeInsets.only(right: 5.pt);
    final _padding = padding ?? EdgeInsets.symmetric(horizontal: 3.pt);
    final _color = color ?? Theme.of(context).primaryColor;
    final _textColor = plain ? _color : Colors.white;

    ///有背景颜色就优先用背景颜色
    final _bgColor = backgroundColor != null
        ? backgroundColor
        : (plain ? _color.withOpacity(0.1) : _color);

    return DefaultTextStyle(
      style: DefaultTextStyle.of(context).style.copyWith(
            color: _textColor,
            height: 1,
            fontWeight: FontWeight.w300,
            fontSize: 10.pt,
          ),
      textHeightBehavior: TextHeightBehavior(
        applyHeightToFirstAscent: false,
        applyHeightToLastDescent: false,
      ),
      child: Wisdom(
        color: _bgColor,
        padding: _padding,
        margin: _margin,
        border: border != null
            ? border
            : Border.fromBorderSide(
                BorderSide(
                  color: _color,
                  width: 0.5.pt,
                ),
              ),
        borderRadius:
            borderRadius != null ? borderRadius : BorderRadius.circular(2.pt),
        child: child,
      ),
    );
  }
}
