import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

import '../controls/padding.dart';
import '../globals.dart';
import '../routes.dart';
import '../services/auth_service.dart';
import '../services/status_service.dart';

class SplashScreen extends StatelessWidget {
  const SplashScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final statusService = context.watch<StatusService>();
    final accountsService = context.watch<AccountsService>();
    if (!accountsService.initializing && !accountsService.loggedIn) {
      context.pushNamed(ScreenPaths.signin);
    }

    return Scaffold(
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          SvgPicture.asset('icon/relatica_logo.svg', width: 128),
          const VerticalPadding(),
          Text(
            'Relatica',
            style: Theme.of(context).textTheme.headlineLarge,
          ),
          const VerticalPadding(),
          if (getIt<AccountsService>().initializing) ...[
            const CircularProgressIndicator(),
            const VerticalPadding(),
            const Text('Logging in accounts...'),
            const VerticalPadding(),
          ],
          Text(
            statusService.status,
            softWrap: true,
            textAlign: TextAlign.center,
          ),
        ],
      )),
    );
  }
}
