// SPDX-FileCopyrightText: © 2025 Nøkken.io <nokken.io@proton.me>
// SPDX-License-Identifier: AGPL-3.0
//
// shared_widgets.dart
//
import 'package:flutter/material.dart';
import 'package:nokken/src/core/ui/theme/app_theme.dart';
import 'package:nokken/src/core/ui/theme/app_text_styles.dart';
import 'package:nokken/src/core/ui/theme/app_colors.dart';

/// SharedWidgets provides consistent UI components across the app
class SharedWidgets {
  //----------------------------------------------------------------------------
  // SPACING UTILITIES
  //----------------------------------------------------------------------------

  /// Creates a vertical spacer with customizable height
  static Widget verticalSpace([double height = AppTheme.spacing]) {
    return SizedBox(height: height);
  }

  /// Creates a horizontal spacer with customizable width
  static Widget horizontalSpace([double width = AppTheme.spacing]) {
    return SizedBox(width: width);
  }

  //----------------------------------------------------------------------------
  // TEXT AND INFORMATION DISPLAY
  //----------------------------------------------------------------------------

  /// Builds a section header with standardized styling
  static Widget buildSectionHeader(String title) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(16, 24, 16, 8),
      child: Text(
        title.toUpperCase(),
        style: AppTextStyles.labelMedium,
      ),
    );
  }

  /// Helper to build consistent info rows
  static Widget buildInfoRow(String label, String value) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          label,
          style: AppTextStyles.bodyMedium,
        ),
        Text(
          value,
          style: AppTextStyles.bodyMedium,
        ),
      ],
    );
  }

  //----------------------------------------------------------------------------
  // CARD COMPONENTS
  //----------------------------------------------------------------------------

  /// Creates a standardized card with primary-colored title bar and content
  static Widget basicCard({
    required BuildContext context,
    required String title,
    required List<Widget> children,
    Color? color,
  }) {
    return Card(
      margin: const EdgeInsets.only(bottom: 16.0),
      clipBehavior: Clip.antiAlias, // This ensures the bar fills the card width
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Title bar with primary color background
          Container(
            width: double.infinity,
            color: color ?? AppColors.primary.withAlpha(160),
            padding:
                const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
            child: Text(
              title,
              style: AppTextStyles.titleMedium.copyWith(
                color: AppColors.onPrimary,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),

          // Card content
          Padding(
            padding: AppTheme.standardCardPadding,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: children,
            ),
          ),
        ],
      ),
    );
  }
}
