import 'package:flutter/material.dart';

import 'package:pshared/models/auto_refresh_mode.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class QuoteAutoRefreshSection extends StatelessWidget {
  final AutoRefreshMode autoRefreshMode;
  final bool canRefresh;
  final ValueChanged<AutoRefreshMode> onModeChanged;

  const QuoteAutoRefreshSection({
    super.key,
    required this.autoRefreshMode,
    required this.canRefresh,
    required this.onModeChanged,
  });

  static const double _autoRefreshSpacing = 8;

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

    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                autoRefreshMode == AutoRefreshMode.on
                    ? loc.quoteAutoRefreshEnabled
                    : loc.quoteAutoRefreshDisabled,
                style: theme.textTheme.bodyMedium,
              ),
              const SizedBox(height: 2),
              Text(
                loc.quoteAutoRefreshHint,
                style: theme.textTheme.bodySmall?.copyWith(
                  color: theme.textTheme.bodySmall?.color?.withValues(alpha: 0.7),
                ),
              ),
            ],
          ),
        ),
        const SizedBox(width: _autoRefreshSpacing),
        Switch.adaptive(
          activeTrackColor: theme.colorScheme.primary,
          value: autoRefreshMode == AutoRefreshMode.on,
          onChanged: canRefresh
              ? (value) => onModeChanged(
                    value ? AutoRefreshMode.on : AutoRefreshMode.off,
                  )
              : null,
        ),
      ],
    );
  }
}
