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

import 'package:superport_v2/features/inventory/rental/presentation/models/rental_record.dart';
import 'package:superport_v2/features/inventory/rental/presentation/widgets/rental_detail_view.dart';

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

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

  RentalRecord buildRecord() {
    return RentalRecord(
      id: 1,
      number: 'RENT-1',
      transactionNumber: 'RENT-1',
      transactionType: '대여',
      rentalType: '대여',
      processedAt: DateTime(2024, 3, 5, 15),
      warehouse: '부산 창고',
      status: '반납 대기',
      writer: '김운영',
      remark: '대여 비고',
      returnDueDate: DateTime(2024, 3, 20),
      items: [
        RentalLineItem(
          id: 30,
          product: '대여 품목',
          manufacturer: '렌탈 제조사',
          unit: 'EA',
          quantity: 2,
          price: 5000,
          remark: '',
        ),
      ],
      customers: [
        RentalCustomer(id: 2, customerId: 9, code: 'RC-09', name: '렌탈 고객'),
      ],
    );
  }

  testWidgets('RentalDetailView는 고객 배지와 라인 테이블을 렌더링한다', (tester) async {
    final record = buildRecord();

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

    expect(find.text('재고 상태 전이가 비활성화된 상태입니다.'), findsOneWidget);
    expect(find.text('연결 고객사'), findsOneWidget);
    expect(find.text('렌탈 고객 · RC-09'), findsOneWidget);
    expect(find.text('라인 품목'), findsOneWidget);
    expect(find.text('대여 품목'), findsOneWidget);
    expect(find.text('렌탈 제조사'), findsOneWidget);
    expect(find.text('EA'), findsOneWidget);
    expect(find.text('2'), findsWidgets);
    expect(find.text('₩5,000'), findsOneWidget);
  });
}
