import 'package:flutter/material.dart';
import 'package:sigap/src/features/personalization/presentasion/pages/settings/widgets/base_detail_screen.dart';

class EmailSettingsScreen extends StatefulWidget {
  const EmailSettingsScreen({super.key});

  @override
  _EmailSettingsScreenState createState() => _EmailSettingsScreenState();
}

class _EmailSettingsScreenState extends State<EmailSettingsScreen> {
  String currentEmail = "anitarose@example.com";
  bool receiveNewsletter = true;
  bool receivePromotions = false;

  @override
  Widget build(BuildContext context) {
    return BaseDetailScreen(
      title: 'Email Settings',
      content: ListView(
        children: [
          _buildSectionHeader('Email Address'),
          _buildEmailItem(),

          _buildSectionHeader('Email Preferences'),
          _buildSwitchItem(
            icon: Icons.newspaper_outlined,
            title: 'Receive newsletter',
            value: receiveNewsletter,
            onChanged: (value) {
              setState(() {
                receiveNewsletter = value;
              });
            },
          ),
          _buildSwitchItem(
            icon: Icons.local_offer_outlined,
            title: 'Receive promotions',
            value: receivePromotions,
            onChanged: (value) {
              setState(() {
                receivePromotions = value;
              });
            },
          ),
        ],
      ),
    );
  }

  Widget _buildSectionHeader(String title) {
    final theme = Theme.of(context);

    return Container(
      padding: const EdgeInsets.fromLTRB(20, 30, 20, 10),
      child: Text(
        title,
        style: theme.textTheme.titleMedium?.copyWith(
          fontWeight: FontWeight.w600,
        ),
      ),
    );
  }

  Widget _buildEmailItem() {
    final theme = Theme.of(context);

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
      child: Row(
        children: [
          Icon(Icons.email_outlined, size: 24, color: theme.iconTheme.color),
          const SizedBox(width: 15),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('Primary Email', style: theme.textTheme.bodyLarge),
                const SizedBox(height: 4),
                Text(
                  currentEmail,
                  style: theme.textTheme.bodyMedium?.copyWith(
                    color: theme.hintColor,
                  ),
                ),
              ],
            ),
          ),
          TextButton(
            onPressed: () {},
            style: TextButton.styleFrom(foregroundColor: theme.primaryColor),
            child: const Text('Change'),
          ),
        ],
      ),
    );
  }

  Widget _buildSwitchItem({
    required IconData icon,
    required String title,
    required bool value,
    required ValueChanged<bool> onChanged,
  }) {
    final theme = Theme.of(context);

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
      child: Row(
        children: [
          Icon(icon, size: 24, color: theme.iconTheme.color),
          const SizedBox(width: 15),
          Expanded(child: Text(title, style: theme.textTheme.bodyLarge)),
          Switch(
            value: value,
            onChanged: onChanged,
            activeColor: theme.primaryColor,
            activeTrackColor: theme.primaryColor.withOpacity(0.4),
          ),
        ],
      ),
    );
  }
}
