import 'package:flutter/material.dart';
import '../../../../core/constants/ui_constants.dart';

class SystemParameterSection extends StatelessWidget {
  final String title;
  final String? subtitle;
  final IconData icon;
  final List<Widget> children;
  final bool isExpanded;
  final VoidCallback? onToggle;
  final Color? iconColor;

  const SystemParameterSection({
    super.key,
    required this.title,
    this.subtitle,
    required this.icon,
    required this.children,
    this.isExpanded = true,
    this.onToggle,
    this.iconColor,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final colorScheme = theme.colorScheme;

    return Container(
      margin: const EdgeInsets.only(bottom: UIConstants.spacing16),
      decoration: BoxDecoration(
        color: colorScheme.surface,
        borderRadius: BorderRadius.circular(UIConstants.radius16),
        boxShadow: [
          BoxShadow(
            color: colorScheme.shadow.withOpacity(0.08),
            blurRadius: 8,
            offset: const Offset(0, 2),
          ),
        ],
        border: Border.all(
          color: colorScheme.outline.withOpacity(0.1),
          width: 1,
        ),
      ),
      child: Column(
        children: [
          // Section Header
          InkWell(
            onTap: onToggle,
            borderRadius: const BorderRadius.vertical(
              top: Radius.circular(UIConstants.radius16),
            ),
            child: Container(
              padding: const EdgeInsets.all(UIConstants.spacing20),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [
                    colorScheme.primaryContainer.withOpacity(0.3),
                    colorScheme.secondaryContainer.withOpacity(0.1),
                  ],
                ),
                borderRadius: const BorderRadius.vertical(
                  top: Radius.circular(UIConstants.radius16),
                ),
              ),
              child: Row(
                children: [
                  // Icon
                  Container(
                    padding: const EdgeInsets.all(UIConstants.spacing12),
                    decoration: BoxDecoration(
                      color: iconColor?.withOpacity(0.1) ??
                          colorScheme.primary.withOpacity(0.1),
                      borderRadius: BorderRadius.circular(UIConstants.radius12),
                    ),
                    child: Icon(
                      icon,
                      color: iconColor ?? colorScheme.primary,
                      size: UIConstants.iconSizeMedium,
                    ),
                  ),

                  const SizedBox(width: UIConstants.spacing16),

                  // Title and Subtitle
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          title,
                          style: theme.textTheme.titleLarge?.copyWith(
                            color: colorScheme.onSurface,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        if (subtitle != null) ...[
                          const SizedBox(height: UIConstants.spacing4),
                          Text(
                            subtitle!,
                            style: theme.textTheme.bodyMedium?.copyWith(
                              color: colorScheme.onSurfaceVariant,
                            ),
                          ),
                        ],
                      ],
                    ),
                  ),

                  // Expand/Collapse Icon
                  if (onToggle != null)
                    AnimatedRotation(
                      turns: isExpanded ? 0.5 : 0,
                      duration: UIConstants.durationFast,
                      child: Icon(
                        Icons.keyboard_arrow_down,
                        color: colorScheme.onSurfaceVariant,
                        size: UIConstants.iconSizeMedium,
                      ),
                    ),
                ],
              ),
            ),
          ),

          // Section Content
          AnimatedContainer(
            duration: UIConstants.durationFast,
            curve: UIConstants.curveNormal,
            height: isExpanded ? null : 0,
            child: isExpanded
                ? Container(
                    padding: const EdgeInsets.all(UIConstants.spacing20),
                    child: Column(
                      children: children,
                    ),
                  )
                : const SizedBox.shrink(),
          ),
        ],
      ),
    );
  }
}
