import 'package:flutter/material.dart';
import 'package:sigap/src/utils/constants/colors.dart';
import 'package:sigap/src/utils/constants/sizes.dart';

class VerificationSummary extends StatelessWidget {
  final Map<String, dynamic> summaryData;
  final bool isOfficer;

  const VerificationSummary({
    super.key,
    required this.summaryData,
    required this.isOfficer,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.grey.withOpacity(0.05),
        borderRadius: BorderRadius.circular(TSizes.borderRadiusMd),
        border: Border.all(color: Colors.grey.withOpacity(0.2)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Header
          Container(
            padding: const EdgeInsets.all(TSizes.md),
            decoration: BoxDecoration(
              color: TColors.primary.withOpacity(0.1),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(TSizes.borderRadiusMd),
                topRight: Radius.circular(TSizes.borderRadiusMd),
              ),
            ),
            child: Row(
              children: [
                Icon(
                  Icons.summarize,
                  color: TColors.primary,
                  size: TSizes.iconMd,
                ),
                const SizedBox(width: TSizes.sm),
                Text(
                  'Registration Summary',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: TColors.primary,
                    fontSize: TSizes.fontSizeMd,
                  ),
                ),
              ],
            ),
          ),

          // Basic Info Section
          _buildSectionHeader(context, 'Basic Information'),
          _buildInfoItem('Email', summaryData['email'] ?? '-'),
          _buildInfoItem('Phone', summaryData['phone'] ?? '-'),
          _buildInfoItem('Role', summaryData['role'] ?? '-'),

          // ID Card Section
          _buildSectionHeader(
            context,
            '${isOfficer ? 'KTA' : 'KTP'} Verification',
          ),
          _buildInfoItem(
            '${isOfficer ? 'KTA' : 'KTP'} Verified',
            (summaryData['idCardValid'] ?? false) ? 'Yes' : 'No',
          ),
          if (!isOfficer) _buildInfoItem('NIK', summaryData['nik'] ?? '-'),
          _buildInfoItem('Full Name', summaryData['fullName'] ?? '-'),
          if (!isOfficer)
            _buildInfoItem(
              'Place of Birth',
              summaryData['placeOfBirth'] ?? '-',
            ),
          _buildInfoItem('Birth Date', summaryData['birthDate'] ?? '-'),
          _buildInfoItem('Gender', summaryData['gender'] ?? '-'),
          if (!isOfficer)
            _buildInfoItem('Address', summaryData['address'] ?? '-'),

          // Selfie Verification Section
          _buildSectionHeader(context, 'Selfie Verification'),
          _buildInfoItem(
            'Liveness Check',
            (summaryData['livenessCheckPassed'] ?? false)
                ? 'Passed'
                : 'Not Verified',
          ),
          _buildInfoItem(
            'Face Match with ID Card',
            (summaryData['faceMatchResult'] ?? false)
                ? 'Matched (${((summaryData['faceMatchConfidence'] ?? 0.0) * 100).toStringAsFixed(1)}% confidence)'
                : 'Not Matched',
          ),
        ],
      ),
    );
  }

  Widget _buildSectionHeader(BuildContext context, String title) {
    return Container(
      padding: const EdgeInsets.symmetric(
        horizontal: TSizes.md,
        vertical: TSizes.sm,
      ),
      color: Colors.grey.withOpacity(0.1),
      child: Text(
        title,
        style: Theme.of(
          context,
        ).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.bold),
      ),
    );
  }

  Widget _buildInfoItem(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: TSizes.md,
        vertical: TSizes.sm,
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            flex: 2,
            child: Text(
              label,
              style: TextStyle(
                color: TColors.textSecondary,
                fontSize: TSizes.fontSizeSm,
              ),
            ),
          ),
          const SizedBox(width: TSizes.sm),
          Expanded(
            flex: 3,
            child: Text(
              value,
              style: TextStyle(
                fontWeight: FontWeight.w500,
                fontSize: TSizes.fontSizeSm,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
