import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:kell_web/app.dart';
import 'package:kell_web/composition/app_config.dart';
import 'package:kell_web/composition/app_scope.dart';
import 'package:kell_web/composition/app_services.dart';

Widget _buildTestApp() {
  const config = AppConfig(
    environment: AppEnvironment.fake,
    wcSiteUrl: '',
    wcConsumerKey: '',
    wcConsumerSecret: '',
  );
  return AppScope(services: AppServices.fake(), config: config, child: const KellWebApp());
}

void main() {
  testWidgets('app shell loads dashboard route', (WidgetTester tester) async {
    await tester.pumpWidget(_buildTestApp());
    await tester.pumpAndSettle();

    expect(find.text('Kell Creations'), findsOneWidget);
    expect(find.text('Dashboard'), findsWidgets);
  });

  testWidgets('dashboard shows summary cards', (WidgetTester tester) async {
    await tester.pumpWidget(_buildTestApp());
    await tester.pumpAndSettle();

    expect(find.text('Overview'), findsOneWidget);
    expect(find.text('Total Products'), findsOneWidget);
    expect(find.text('In Stock'), findsOneWidget);
    expect(find.text('Low Stock'), findsOneWidget);
    expect(find.text('Draft'), findsOneWidget);
  });

  testWidgets('dashboard shows quick actions section', (WidgetTester tester) async {
    await tester.pumpWidget(_buildTestApp());
    await tester.pumpAndSettle();

    // Scroll down to reveal the quick actions section.
    await tester.scrollUntilVisible(
      find.text('Quick Actions'),
      200,
      scrollable: find.byType(Scrollable).first,
    );
    await tester.pumpAndSettle();

    expect(find.text('Quick Actions'), findsOneWidget);
    expect(find.text('New Product'), findsOneWidget);
    expect(find.text('View Inventory'), findsOneWidget);
    expect(find.text('View Orders'), findsOneWidget);
  });

  testWidgets('dashboard shows recent activity empty state', (WidgetTester tester) async {
    await tester.pumpWidget(_buildTestApp());
    await tester.pumpAndSettle();

    // Scroll down to reveal the recent activity section.
    await tester.scrollUntilVisible(
      find.text('Recent Activity'),
      200,
      scrollable: find.byType(Scrollable).first,
    );
    await tester.pumpAndSettle();

    expect(find.text('Recent Activity'), findsOneWidget);
  });

  testWidgets('environment badge shows FAKE in fake mode', (WidgetTester tester) async {
    await tester.pumpWidget(_buildTestApp());
    await tester.pumpAndSettle();

    expect(find.text('FAKE'), findsOneWidget);
  });
}
