import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:feature_orders/feature_orders.dart';
import 'package:feature_orders/src/presentation/widgets/order_card.dart';

void main() {
  final sampleOrder = Order(
    id: 'KC-9999',
    customerName: 'Test Customer',
    customerEmail: 'test@example.com',
    orderDate: DateTime(2026, 4, 1),
    status: OrderStatus.processing,
    shippingAddress: '123 Test St, Test City, TS 00000',
    items: const [
      OrderItem(productName: 'Test Product', sku: 'TP-001', quantity: 2, unitPrice: 10.00),
    ],
  );

  Widget buildTestWidget({bool isSelected = false, VoidCallback? onTap}) {
    return MaterialApp(
      theme: buildKcTheme(),
      home: Scaffold(
        body: SizedBox(
          height: 200,
          width: 400,
          child: OrderCard(order: sampleOrder, isSelected: isSelected, onTap: onTap),
        ),
      ),
    );
  }

  group('OrderCard', () {
    testWidgets('displays order ID', (tester) async {
      await tester.pumpWidget(buildTestWidget());
      expect(find.text('KC-9999'), findsOneWidget);
    });

    testWidgets('displays customer name', (tester) async {
      await tester.pumpWidget(buildTestWidget());
      expect(find.text('Test Customer'), findsOneWidget);
    });

    testWidgets('displays total', (tester) async {
      await tester.pumpWidget(buildTestWidget());
      expect(find.text('\$20.00'), findsOneWidget);
    });

    testWidgets('displays item count', (tester) async {
      await tester.pumpWidget(buildTestWidget());
      expect(find.text('2 items'), findsOneWidget);
    });

    testWidgets('displays status chip', (tester) async {
      await tester.pumpWidget(buildTestWidget());
      expect(find.text('Processing'), findsOneWidget);
    });

    testWidgets('displays date', (tester) async {
      await tester.pumpWidget(buildTestWidget());
      expect(find.text('2026-04-01'), findsOneWidget);
    });

    testWidgets('calls onTap when tapped', (tester) async {
      var tapped = false;
      await tester.pumpWidget(buildTestWidget(onTap: () => tapped = true));
      await tester.tap(find.text('KC-9999'));
      expect(tapped, true);
    });
  });
}
