import 'package:ambito/src/widgets/form/form_widget_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

import '../../packages/ambito_theme/ambito_theme.dart';

abstract class FormWidgetField {
  Widget get(AmbitoTheme theme) {
    return FormBuilderTextField(name: '');
  }
}

class FormWidget extends StatelessWidget {
  FormWidget({super.key, required this.type, required this.fields});

  final _formKey = GlobalKey<FormBuilderState>();

  final FormWidgetType type;
  final List<FormWidgetField> fields;

  @override
  Widget build(BuildContext context) {
    final AmbitoTheme theme = getTheme(context);

    return SizedBox(
        child: FormBuilder(
      key: _formKey,
      child: (type == FormWidgetType.vertical)
          ? Column(
              children: fields
                  .map((element) => _getElementVertical(element, theme))
                  .toList(),
            )
          : Row(
              children: fields.map((element) => element.get(theme)).toList(),
            ),
    ));
  }

  Widget _getElementVertical(FormWidgetField element, AmbitoTheme theme) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 16),
      child: element.get(theme),
    );
  }
}
