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_detail_panel.dart';

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

  Widget buildTestWidget(Order order) {
    return MaterialApp(
      theme: buildKcTheme(),
      home: Scaffold(
        body: SingleChildScrollView(child: OrderDetailPanel(order: order)),
      ),
    );
  }

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

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

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

    testWidgets('displays customer email', (tester) async {
      await tester.pumpWidget(buildTestWidget(sampleOrder));
      expect(find.text('test@example.com'), findsOneWidget);
    });

    testWidgets('displays shipping address', (tester) async {
      await tester.pumpWidget(buildTestWidget(sampleOrder));
      expect(find.text('123 Test St, Test City, TS 00000'), findsOneWidget);
    });

    testWidgets('displays line item product names', (tester) async {
      await tester.pumpWidget(buildTestWidget(sampleOrder));
      expect(find.text('Test Product'), findsOneWidget);
      expect(find.text('Another Product'), findsOneWidget);
    });

    testWidgets('displays line item SKUs', (tester) async {
      await tester.pumpWidget(buildTestWidget(sampleOrder));
      expect(find.text('SKU: TP-001'), findsOneWidget);
      expect(find.text('SKU: AP-002'), findsOneWidget);
    });

    testWidgets('displays order total', (tester) async {
      await tester.pumpWidget(buildTestWidget(sampleOrder));
      // 2 * 10.00 + 1 * 15.50 = 35.50
      expect(find.text('\$35.50'), findsOneWidget);
    });
  });
}
