import 'package:flutter/material.dart';

import '../model/currency.dart';

class CurrencyPicker extends StatelessWidget {
  final void Function(Currency?) onChanged;
  final Currency? initialValue;

  const CurrencyPicker({
    super.key,
    required this.onChanged,
    required this.initialValue,
  });

  @override
  Widget build(BuildContext context) {
    return DropdownButtonFormField<Currency>(
        alignment: AlignmentDirectional.centerEnd,
        validator: (value) {
          if (value == null) {
            return "Měna musí být vybrána";
          }
          return null;
        },
        value: initialValue,
        items: Currency.values.map((cur) {
          return DropdownMenuItem<Currency>(
            value: cur,
            child: Text(cur.symbol),
          );
        }).toList(),
        onChanged: onChanged);
  }
}
