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

import '../routes.dart';
import '../store/actions.dart';
import '../store/store.dart';
import '../widgets/desktop/desktop_my_cards.dart';
import '../widgets/mobile/mobile_my_cards.dart';

class MyCards extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    store.dispatch(UpdateContext(context));

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      if (store.state.user == null) {
        store.dispatch(UpdateRedirectRoute('/my-cards'));
        Routes.router.navigateTo(context, '/login', replace: true);
        return;
      }
    });

    if (store.state.user == null) {
      return Center(
        child: Image.asset(
          'assets/images/denied.png',
          width: 48,
          height: 48,
          fit: BoxFit.fill,
        ),
      );
    }

    return ResponsiveBuilder(
      builder: (context, sizingInformation) =>
          ScreenTypeLayout(
            mobile: MobileMyCards(),
            tablet: DesktopMyCards(),
            desktop: DesktopMyCards(),
          ),
    );
  }

}