import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:health_app/widgets/backoffice_ui.dart';

void main() {
  testWidgets('backoffice surface provides the shared patient-style canvas', (
    tester,
  ) async {
    await tester.pumpWidget(
      const MaterialApp(home: BackofficeSurface(child: Text('内容'))),
    );

    expect(find.text('内容'), findsOneWidget);
    expect(find.byType(DecoratedBox), findsWidgets);
  });

  testWidgets('empty state shows its message and optional action', (
    tester,
  ) async {
    var tapped = false;
    await tester.pumpWidget(
      MaterialApp(
        home: BackofficeEmptyState(
          icon: Icons.people_outline,
          title: '暂无患者',
          description: '患者加入后会显示在这里',
          actionLabel: '刷新',
          onAction: () => tapped = true,
        ),
      ),
    );

    expect(find.text('暂无患者'), findsOneWidget);
    expect(find.text('患者加入后会显示在这里'), findsOneWidget);
    await tester.tap(find.text('刷新'));
    expect(tapped, isTrue);
  });

  testWidgets('error state exposes a retry action', (tester) async {
    var retried = false;
    await tester.pumpWidget(
      MaterialApp(home: BackofficeErrorState(onRetry: () => retried = true)),
    );

    expect(find.text('加载失败'), findsOneWidget);
    await tester.tap(find.text('重新加载'));
    expect(retried, isTrue);
  });

  testWidgets('inactive doctor banner explains the registration impact', (
    tester,
  ) async {
    await tester.pumpWidget(
      const MaterialApp(home: BackofficeInactiveDoctorBanner()),
    );

    expect(find.text('账号已停用'), findsOneWidget);
    expect(find.textContaining('新患者暂时无法选择您'), findsOneWidget);
  });
}
