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

class AppThemeComponent {
  static ComponentThemeData get components => ComponentThemeData.raw(
        appBar: CustomAppBar(),
        bottomNavigationBar: CustomBottomBar(),
        loadingWidget: CustomLoadingWidget(),
        errorWidget: CustomErrorWidget(),
      );
}

class CustomAppBar extends AppBarComponent {
  const CustomAppBar({super.title});
  @override
  Widget build(BuildContext context) => AppBar(
        title: Text(title ?? 'Title'),
      );

  @override
  AppBarComponent? configure(
          {String? title, Widget? leading, List<Widget>? actions}) =>
      CustomAppBar(
        title: title ?? this.title,
      );
}

class CustomBottomBar extends BottomNavigationBarComponent {
  @override
  Widget build(BuildContext context) => BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.e_mobiledata,
              ),
              label: 'Icon 1'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.do_not_disturb_off,
              ),
              label: 'Icon 2'),
        ],
        backgroundColor: Colors.blue,
      );

  @override
  BottomNavigationBarComponent? configure(
          {void Function(BuildContext p1, int p2)? onTap,
          int currentIndex = 0}) =>
      this;
}

class CustomLoadingWidget extends LoadingWidgetComponent {
  CustomLoadingWidget({super.color});

  @override
  Widget build(BuildContext context) =>
      Center(child: CircularProgressIndicator(color: color));

  @override
  LoadingWidgetComponent? configure({Color? color}) => CustomLoadingWidget(
        color: color ?? this.color,
      );
}

class CustomErrorWidget extends ErrorWidgetComponent {
  CustomErrorWidget({super.error});

  @override
  Widget build(BuildContext context) => ColoredBox(
        color: Colors.red,
        child: Center(child: Text(error ?? 'Error')),
      );

  @override
  ErrorWidgetComponent? configure({String? error}) => CustomErrorWidget(
        error: error ?? this.error,
      );
}
