import 'package:flutter/material.dart';

enum EmptyType {
  data,
}

class Empty extends StatelessWidget {
  final EmptyType type;
  final String? text;
  final Widget? child;

  const Empty({
    super.key,
    this.type = EmptyType.data,
    this.text,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    var emptyImg = switch (type) {
      EmptyType.data => Image.asset('assets/image/empty_data.png'),
    };
    var emptyText = switch (type) {
      EmptyType.data => '暂无数据',
    };
    return Container(
      padding: EdgeInsets.all(0),
      child: Column(
        children: [
          FractionallySizedBox(
            widthFactor: 0.5,
            child: Container(
              margin: EdgeInsets.only(bottom: 15),
              child: emptyImg,
            ),
          ),
          Text(
            text ?? emptyText,
            style: Theme.of(context).textTheme.labelLarge,
            textAlign: TextAlign.center,
          ),
          child != null
              ? Container(
                  margin: EdgeInsets.only(top: 15),
                  child: child,
                )
              : SizedBox(),
        ],
      ),
    );
  }
}
