/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2022-11-02 10:26:39
 * @LastEditTime : 2023-05-10 10:13:17
 * @Description  : Do not edit
 */

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

class WisCard extends StatelessWidget {
  WisCard({
    Key? key,
    this.onTap,
    this.color,
    this.isSliver = false,
    this.shadowColor = const Color(0x08000000), //30%透明度
    this.elevation,
    this.shape,
    this.borderOnForeground = true,
    this.margin,
    this.padding = EdgeInsets.zero,
    this.clipBehavior,
    this.child,
    this.semanticContainer = true,
    this.decoration,
  }) : super(key: key);

  final void Function()? onTap;
  final Color? color;
  final bool isSliver;
  final Color shadowColor;
  final double? elevation;
  final ShapeBorder? shape;
  final bool borderOnForeground; // = true;
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;
  final Clip? clipBehavior;
  final Widget? child;
  final bool? semanticContainer; // = true;
  final BoxDecoration? decoration;

  static double _defaultElevation = 8.pt;

  @override
  Widget build(BuildContext context) {
    final CardThemeData cardTheme = CardTheme.of(context);
    Widget? current = child;
    if (onTap != null) {
      current = InkWell(
        onTap: onTap,
        child: current,
      );
    }
    if (padding != null && padding != EdgeInsets.zero) {
      current = Padding(
        padding: padding!,
        child: current,
      );
    }
    current = Semantics(
      container: semanticContainer!,
      child: Container(
        decoration: decoration ??
            BoxDecoration(boxShadow: [
              BoxShadow(
                color: Color(0x08000000),
                offset: Offset(0, 2.pt),
                blurRadius: 10.pt,
                spreadRadius: 2.5.pt,
              ),
            ]),
        margin: margin ?? cardTheme.margin ?? const EdgeInsets.all(4.0),
        child: Material(
          // type: MaterialType.card,
          color: color ?? Colors.white,
          elevation: elevation ?? cardTheme.elevation ?? _defaultElevation,
          shadowColor: Colors.transparent,
          shape: shape ??
              cardTheme.shape ??
              const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(12)),
              ),
          borderOnForeground: borderOnForeground,
          clipBehavior: clipBehavior ?? cardTheme.clipBehavior ?? Clip.none,
          child: Semantics(
            explicitChildNodes: !semanticContainer!,
            child: current,
          ),
        ),
      ),
    );
    if (isSliver == true) {
      current = SliverToBoxAdapter(
        child: current,
      );
    }
    return current;
  }
}
