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

class LLSLabel extends StatelessWidget {
  const LLSLabel({
    Key? key,
    this.type = LLSLabelType.typo4,
    this.child,
    required this.text,
    this.icon,
    this.dividerBorderRadius,
    this.textColor,
    this.dividerAlignment,
    this.dividerColor,
    this.showDivider = true,
    this.dividerWidth,
    this.backgroundImage,
    this.backgroundImagecolorFilter,
  })  : assert(text != null || child != null),
        super(key: key);

  final Widget? child;

  final String? text;

  final Widget? icon;

  final Color? dividerColor;

  final Color? textColor;

  final BorderRadius? dividerBorderRadius;

  final Alignment? dividerAlignment;

  final bool showDivider;

  final double? dividerWidth;

  final ImageProvider? backgroundImage;

  final ColorFilter? backgroundImagecolorFilter;

  final LLSLabelType type;

  @override
  Widget build(BuildContext context) {
    double? fontSize;

    if (type == LLSLabelType.typo1) {
      fontSize = 25.0;
    } else if (type == LLSLabelType.typo2) {
      fontSize = 22.0;
    } else if (type == LLSLabelType.typo3) {
      fontSize = 19.0;
    } else if (type == LLSLabelType.typo4) {
      fontSize = 17.0;
    } else if (type == LLSLabelType.typo5) {
      fontSize = 15.0;
    } else if (type == LLSLabelType.typo6) {
      fontSize = 13.0;
    }

    return Container(
      padding: EdgeInsets.all(backgroundImage != null ? 10 : 0),
      decoration: BoxDecoration(
        image: backgroundImage != null
            ? DecorationImage(
                image: backgroundImage!,
                fit: BoxFit.cover,
                colorFilter: backgroundImagecolorFilter ??
                    const ColorFilter.mode(Colors.black54, BlendMode.darken),
              )
            : null,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            children: <Widget>[
              icon ?? Container(),
              icon != null
                  ? const Padding(padding: EdgeInsets.only(left: 10))
                  : Container(),
              text != null
                  ? Expanded(
                      child: Text(
                        text!,
                        style: TextStyle(
                            color: textColor ??
                                (backgroundImage != null
                                    ? Colors.white
                                    : Colors.black),
                            fontSize: fontSize,
                            letterSpacing: 0.3,
                            fontWeight: FontWeight.w500),
                      ),
                    )
                  : child!
            ],
          ),
          showDivider && fontSize != null
              ? Container(
                  margin: const EdgeInsets.only(top: 3, bottom: 3),
                  alignment: dividerAlignment,
                  child: Container(
                    width: dividerWidth != null ? dividerWidth : 70,
                    height: fontSize / 5,
                    decoration: BoxDecoration(
                      color: dividerColor ??
                          (backgroundImage != null
                              ? Colors.white
                              : Colors.black),
                      borderRadius: dividerBorderRadius ??
                          const BorderRadius.all(
                            Radius.circular(5),
                          ),
                    ),
                  ),
                )
              : Container()
        ],
      ),
    );
  }
}
