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

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

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

class _PrivacySettingsScreenState extends State<PrivacySettingsScreen> {
  bool showActivityStatus = true;
  bool allowComments = false;
  bool shareUsageData = true;
  bool allowPersonalizedAds = false;

  @override
  Widget build(BuildContext context) {
    return BaseDetailScreen(
      title: 'Privacy Settings',
      content: ListView(
        children: [
          _buildSectionHeader('Profile Visibility'),
          _buildNavigationItem(
            icon: Icons.visibility_outlined,
            title: 'Who can see my profile?',
            onTap: () {},
          ),
          _buildSwitchItem(
            icon: Icons.access_time_outlined,
            title: 'Show activity status',
            value: showActivityStatus,
            onChanged: (value) {
              setState(() {
                showActivityStatus = value;
              });
            },
          ),

          _buildSectionHeader('Interactions'),
          _buildNavigationItem(
            icon: Icons.chat_bubble_outline,
            title: 'Who can message me?',
            onTap: () {},
          ),
          _buildSwitchItem(
            icon: Icons.comment_outlined,
            title: 'Allow comments',
            value: allowComments,
            onChanged: (value) {
              setState(() {
                allowComments = value;
              });
            },
          ),

          _buildSectionHeader('Data Sharing'),
          _buildSwitchItem(
            icon: Icons.analytics_outlined,
            title: 'Share usage data',
            value: shareUsageData,
            onChanged: (value) {
              setState(() {
                shareUsageData = value;
              });
            },
          ),
          _buildSwitchItem(
            icon: Icons.ads_click_outlined,
            title: 'Allow personalized ads',
            value: allowPersonalizedAds,
            onChanged: (value) {
              setState(() {
                allowPersonalizedAds = 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 _buildNavigationItem({
    required IconData icon,
    required String title,
    required VoidCallback onTap,
  }) {
    final theme = Theme.of(context);

    return InkWell(
      onTap: onTap,
      child: 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)),
            Icon(Icons.chevron_right, color: theme.hintColor),
          ],
        ),
      ),
    );
  }

  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),
          ),
        ],
      ),
    );
  }
}
