import 'package:flutter_test/flutter_test.dart';
import 'package:intl/intl.dart' as intl;

import 'package:superport_v2/features/inventory/outbound/presentation/models/outbound_record.dart';
import 'package:superport_v2/features/inventory/outbound/presentation/widgets/outbound_detail_view.dart';

import '../../../../../helpers/test_app.dart';

void main() {
  final currencyFormatter = intl.NumberFormat.currency(
    locale: 'ko_KR',
    symbol: '₩',
    decimalDigits: 0,
  );

  OutboundRecord buildRecord() {
    return OutboundRecord(
      id: 1,
      number: 'OUT-1',
      transactionNumber: 'OUT-1',
      transactionType: '출고',
      processedAt: DateTime(2024, 2, 10, 11),
      warehouse: '서울 1창고',
      status: '출고 완료',
      writer: '관리자',
      remark: '긴급 출고',
      items: [
        OutboundLineItem(
          id: 20,
          product: '출고 제품',
          manufacturer: '제조사',
          unit: 'EA',
          quantity: 5,
          price: 2000,
          remark: '양호',
        ),
      ],
      customers: [
        OutboundCustomer(id: 1, customerId: 7, code: 'CUS-01', name: '테스트 고객'),
      ],
    );
  }

  testWidgets('OutboundDetailView는 고객 배지와 라인 테이블을 표시한다', (tester) async {
    final record = buildRecord();

    await tester.pumpWidget(
      buildTestApp(
        OutboundDetailView(
          record: record,
          currencyFormatter: currencyFormatter,
          transitionsEnabled: true,
        ),
      ),
    );
    await tester.pumpAndSettle();

    expect(find.text('출고 고객사'), findsOneWidget);
    expect(find.text('테스트 고객 · CUS-01'), findsOneWidget);
    expect(find.text('라인 품목'), findsOneWidget);
    expect(find.text('출고 제품'), findsOneWidget);
    expect(find.text('제조사'), findsWidgets);
    expect(find.text('EA'), findsWidgets);
    expect(find.text('5'), findsWidgets);
    expect(find.text('₩2,000'), findsOneWidget);
    expect(find.text('양호'), findsOneWidget);
  });
}
