import 'package:flutter/material.dart';

class LegalContentDialog extends StatelessWidget {
  final String title;
  final List<Widget> contentWidgets;

  const LegalContentDialog({
    super.key,
    required this.title,
    required this.contentWidgets,
  });

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      backgroundColor: Theme.of(context).scaffoldBackgroundColor, // Adjusted for better theme consistency
      surfaceTintColor: Colors.transparent, // Remove tint if not desired
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0), // Slightly larger radius
      ),
      titlePadding: const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 12.0), // Adjusted bottom padding
      contentPadding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0), // Adjusted to remove default content padding for ListView
      title: Text(
        title,
        style: Theme.of(context).textTheme.headlineSmall?.copyWith( // Using headlineSmall for a more prominent title
              fontWeight: FontWeight.bold,
              color: Theme.of(context).colorScheme.primary,
            ),
      ),
      content: Container(
        width: double.maxFinite,
        constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.6), // Max height for scrollability
        child: ListView(
          padding: const EdgeInsets.symmetric(horizontal: 24.0), // Padding for ListView items
          shrinkWrap: true,
          children: contentWidgets,
        ),
      ),
      actionsAlignment: MainAxisAlignment.center, // Center the action button
      actionsPadding: const EdgeInsets.only(bottom: 16.0, top: 8.0),
      actions: [
        TextButton(
          onPressed: () => Navigator.of(context).pop(),
          style: TextButton.styleFrom(
            backgroundColor: Theme.of(context).colorScheme.primary,
            foregroundColor: Theme.of(context).colorScheme.onPrimary,
            padding: const EdgeInsets.symmetric(horizontal: 32.0, vertical: 12.0),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(12.0),
            ),
          ),
          child: const Text('Tutup', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
        ),
      ],
    );
  }
}

// Helper widget for section titles
class SectionTitle extends StatelessWidget {
  final String text;
  const SectionTitle(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 20.0, bottom: 10.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            text,
            style: Theme.of(context).textTheme.titleMedium?.copyWith(
                  fontWeight: FontWeight.w600, //semibold
                  color: Theme.of(context).colorScheme.onSurfaceVariant,
                ),
          ),
          const SizedBox(height: 6.0),
          Divider(
            height: 1,
            thickness: 0.5,
            color: Theme.of(context).dividerColor.withOpacity(0.6),
          ),
        ],
      ),
    );
  }
}

// Helper widget for paragraph text
class ParagraphText extends StatelessWidget {
  final String text;
  final TextAlign textAlign;
  const ParagraphText(this.text, {super.key, this.textAlign = TextAlign.start});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 10.0),
      child: Text(
        text,
        textAlign: textAlign,
        style: Theme.of(context).textTheme.bodyMedium?.copyWith(
              height: 1.6, // Increased line spacing for readability
              color: Theme.of(context).colorScheme.onSurface.withOpacity(0.85), // Slightly more contrast
              fontSize: 15,
            ),
      ),
    );
  }
}

// Helper widget for list items
class ListItem extends StatelessWidget {
  final String text;
  const ListItem(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    final bodyMediumStyle = Theme.of(context).textTheme.bodyMedium;
    final bulletColor = Theme.of(context).colorScheme.primary;
    final textColor = Theme.of(context).colorScheme.onSurface.withOpacity(0.85);

    return Padding(
      padding: const EdgeInsets.only(left: 4.0, bottom: 8.0, right: 4.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 2.0, right: 8.0), // Adjust padding for alignment
            child: Icon(
              Icons.circle, // Using a small circle icon as a bullet
              size: 8,
              color: bulletColor,
            ),
          ),
          Expanded(
            child: Text(
              text,
              style: bodyMediumStyle?.copyWith(
                    height: 1.6,
                    color: textColor,
                    fontSize: 15,
                  ),
            ),
          ),
        ],
      ),
    );
  }
} 