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

import 'package:superport_v2/features/inventory/inbound/presentation/models/inbound_record.dart';
import 'package:superport_v2/features/inventory/inbound/presentation/widgets/inbound_detail_view.dart';

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

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

  InboundRecord buildRecord() {
    return InboundRecord(
      id: 1,
      number: 'IN-1',
      transactionNumber: 'IN-1',
      transactionType: '입고',
      processedAt: DateTime(2024, 1, 1, 9),
      warehouse: '서울 1창고',
      status: '완료',
      writer: '홍길동',
      remark: '비고',
      items: [
        InboundLineItem(
          id: 10,
          product: '테스트 제품',
          manufacturer: '테스트 제조사',
          unit: 'EA',
          quantity: 3,
          price: 1000,
          remark: '정상',
        ),
      ],
    );
  }

  testWidgets('InboundDetailView는 라인 품목과 경고 배지를 렌더링한다', (tester) async {
    final record = buildRecord();

    await tester.pumpWidget(
      buildTestApp(
        InboundDetailView(
          record: record,
          currencyFormatter: currencyFormatter,
          transitionsEnabled: false,
        ),
      ),
    );
    await tester.pumpAndSettle();

    expect(find.text('재고 상태 전이가 비활성화된 상태입니다.'), findsOneWidget);
    expect(find.text('라인 품목'), findsOneWidget);
    expect(find.text('테스트 제품'), findsOneWidget);
    expect(find.text('테스트 제조사'), findsOneWidget);
    expect(find.text('EA'), findsOneWidget);
    expect(find.text('3'), findsWidgets);
    expect(find.text('₩1,000'), findsOneWidget);
    expect(find.text('정상'), findsOneWidget);
  });
}
