// SPDX-FileCopyrightText: © 2025 Nøkken.io <nokken.io@proton.me>
// SPDX-License-Identifier: AGPL-3.0
//
// add_edit_medication_type.dart
//
import 'package:flutter/material.dart';
import 'package:nokken/src/core/ui/widgets/shared_widgets.dart';
import 'package:nokken/src/core/ui/widgets/dropdown_widgets.dart';
import 'package:nokken/src/core/ui/theme/app_theme.dart';
import 'package:nokken/src/core/utils/get_icons_colors.dart';
import 'package:nokken/src/features/medication_tracker/models/medication.dart';

class MedicationTypeSection extends StatelessWidget {
  final MedicationType medicationType;
  final ValueChanged<MedicationType> onTypeChanged;

  const MedicationTypeSection({
    super.key,
    required this.medicationType,
    required this.onTypeChanged,
  });

  @override
  Widget build(BuildContext context) {
    return SharedWidgets.basicCard(
      context: context,
      title: 'Medication Type',
      children: [
        DropdownWidgets.customDropdownButtonFormField<MedicationType>(
          value: medicationType,
          decoration: AppTheme.defaultTextFieldDecoration.copyWith(),
          items: MedicationType.values.map((type) {
            String displayName;
            String description;

            switch (type) {
              case MedicationType.oral:
                displayName = 'Oral';
                description =
                    'taken by mouth in the form of tablets, capsules, or drops';
                break;
              case MedicationType.injection:
                displayName = 'Injection';
                description =
                    'administered via needle into the bloodstream, muscle, or under the skin';
                break;
              case MedicationType.topical:
                displayName = 'Topical';
                description =
                    'applied directly to the skin as a cream, gel, or spray';
                break;
              case MedicationType.patch:
                displayName = 'Patch';
                description =
                    'adhesive patch that delivers medication through the skin over time';
                break;
            }

            return DropdownWidgets.dropdownItemWithDescription<MedicationType>(
              value: type,
              description: description,
              child: Row(
                children: [
                  GetIconsColors.getMedicationIconWithColor(type),
                  SharedWidgets.horizontalSpace(12),
                  Text(displayName),
                ],
              ),
            );
          }).toList(),
          onChanged: (value) {
            if (value != null) {
              onTypeChanged(value);
            }
          },
        ),
      ],
    );
  }
}
