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

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

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

class _NotificationsSettingsScreenState
    extends State<NotificationsSettingsScreen> {
  bool messagesNotify = true;
  bool commentsNotify = true;
  bool followersNotify = true;
  bool mentionsNotify = false;
  bool systemNotify = true;

  @override
  Widget build(BuildContext context) {
    return BaseDetailScreen(
      title: 'Notifications',
      content: ListView(
        children: [
          _buildSectionHeader('Push Notifications'),
          _buildSwitchItem(
            icon: Icons.message_outlined,
            title: 'Messages',
            value: messagesNotify,
            onChanged: (value) {
              setState(() {
                messagesNotify = value;
              });
            },
          ),
          _buildSwitchItem(
            icon: Icons.comment_outlined,
            title: 'Comments',
            value: commentsNotify,
            onChanged: (value) {
              setState(() {
                commentsNotify = value;
              });
            },
          ),
          _buildSwitchItem(
            icon: Icons.person_add_outlined,
            title: 'New followers',
            value: followersNotify,
            onChanged: (value) {
              setState(() {
                followersNotify = value;
              });
            },
          ),
          _buildSwitchItem(
            icon: Icons.alternate_email,
            title: 'Mentions',
            value: mentionsNotify,
            onChanged: (value) {
              setState(() {
                mentionsNotify = value;
              });
            },
          ),
          _buildSwitchItem(
            icon: Icons.info_outline,
            title: 'System notifications',
            value: systemNotify,
            onChanged: (value) {
              setState(() {
                systemNotify = 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 _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),
          ),
        ],
      ),
    );
  }
}
