import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class TemplateForm extends StatefulWidget {
  final Key? fieldKey;
  final String? hintText;
  final String? labelText;
  final String? helperText;
  final String? titleText;
  final String? titleText2;
  var color;
  var colorTitle2;
  var initialValue;
  final double? fontSize;
  final double? formHeight;
  final FormFieldSetter<String>? onSaved;
  final FormFieldSetter<String>? onChange;
  final FormFieldValidator<String>? validator;
  final TextEditingController? controller;
  final TextCapitalization textCapitalization;
  var formatter;
  final bool enabled;
  final bool adaValidasi;
  final bool keyboardNumber;
  final bool numberOnly;
  final double bottomMargin;
  final double? radius;
  final int maxLine;
  final int minLine;
  var contentPadding;
  var prefixIcon;
  var buttonEnd;
  TemplateForm(
      {this.fieldKey,
      this.hintText,
      this.helperText,
      this.labelText,
      this.onSaved,
      this.onChange,
      this.validator,
      this.controller,
      this.enabled = true,
      this.adaValidasi = false,
      this.keyboardNumber = false,
      this.numberOnly = false,
      this.titleText,
      this.titleText2 = '',
      this.textCapitalization = TextCapitalization.words,
      this.bottomMargin = 12.0,
      this.maxLine = 1,
      this.initialValue,
      this.prefixIcon,
      this.color = Colors.white,
      this.colorTitle2 = Colors.white,
      this.fontSize = 14,
      this.radius = 16,
      this.formHeight = 48,
      this.minLine = 1,
      this.formatter,
      this.buttonEnd,
      this.contentPadding = const EdgeInsets.fromLTRB(20.0, 0, 20.0, 0)});
  @override
  _TemplateFormState createState() => _TemplateFormState();
}

class _TemplateFormState extends State<TemplateForm> {
  String? _validate(String? value) {
    if (value!.isEmpty) return 'Please fill this form.';
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: widget.bottomMargin),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          widget.titleText != ''&&widget.titleText!=null
              ? Padding(
                  padding: const EdgeInsets.only(bottom: 8, left: 11),
                  child: widget.titleText2!=null?Row(
                    children: [
                      Text(
                        widget.titleText!,
                        style: TextStyle(
                            // color: widget.color,
                            color: Colors.grey,
                            fontWeight: FontWeight.w500,
                            fontSize: widget.fontSize),
                      ),
                      SizedBox(width: 4,),
                      Text(
                        widget.titleText2!,
                        style: TextStyle(
                            color: widget.colorTitle2,
                            fontWeight: FontWeight.bold,
                            fontSize: widget.fontSize),
                      )
                    ],
                  ):Text(
                    widget.titleText!,
                    style: TextStyle(
                        color: widget.color,
                        fontWeight: FontWeight.bold,
                        fontSize: widget.fontSize),
                  ),
                )
              : Container(),
          Container(
            padding: EdgeInsets.only(right: 6),
            height: widget.formHeight,
            decoration: widget.buttonEnd != null
                ? BoxDecoration(
                    border: Border.all(color: widget.color, width: 0.8),
                    borderRadius:
                        BorderRadius.all(Radius.circular(widget.radius!)))
                : null,
            child: Row(
              children: [
                Expanded(
                  child: TextFormField(
                    minLines: widget.minLine,
                    initialValue: widget.initialValue,
                    cursorColor: widget.color,
                    maxLines: widget.maxLine,
                    controller: widget.controller,
                    keyboardType: widget.keyboardNumber
                        ? TextInputType.number
                        : TextInputType.text,
                    inputFormatters: widget.numberOnly
                        ? <TextInputFormatter>[
                            FilteringTextInputFormatter.digitsOnly,
                          ]
                        : widget.formatter != null
                            ? [
                                widget.formatter,
                              ]
                            : null,
                    key: widget.fieldKey,
                    enabled: widget.enabled,
                    style: TextStyle(
                        fontSize: widget.fontSize, color: widget.color),
                    decoration: InputDecoration(
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(widget.radius!),
                          borderSide: BorderSide(
                            color: widget.buttonEnd == null
                                ? widget.color
                                : Colors.transparent,
                            width: 0.8,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(widget.radius!),
                          borderSide: BorderSide(
                            color: widget.buttonEnd == null
                                ? widget.color
                                : Colors.transparent,
                            width: 1,
                          ),
                        ),
                        disabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(widget.radius!),
                          borderSide: BorderSide(
                            color: widget.buttonEnd == null
                                ? Colors.grey
                                : Colors.transparent,
                            width: 0.8,
                          ),
                        ),
                        hintStyle: TextStyle(
                            color: widget.enabled
                                ? widget.color
                                : Colors.grey[600]),
                        labelStyle: TextStyle(color: widget.color),
                        fillColor: Colors.transparent,
                        filled: true,
                        prefixIcon: widget.prefixIcon,
                        contentPadding: widget.contentPadding,
                        hintText: widget.hintText,
                        labelText: widget.labelText),
                    validator: widget.adaValidasi == true ? _validate : null,
                    onSaved: widget.onSaved,
                    onChanged: widget.onChange,
                  ),
                ),
                widget.buttonEnd ?? Container()
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class TemplateFormKeterangan extends StatefulWidget {
  final Key? fieldKey;
  final String? hintText;
  final String? labelText;
  final String? helperText;
  final String? titleText;
  var color;
  var initialValue;
  final double fontSize;
  final double formHeight;
  final FormFieldSetter<String>? onSaved;
  final FormFieldValidator<String>? validator;
  final TextEditingController? controller;
  final TextCapitalization textCapitalization;
  var formatter;
  final bool enabled;
  final bool adaValidasi;
  final bool keyboardNumber;
  final bool numberOnly;
  final double bottomMargin;
  final double radius;
  final int maxLine;
  final int minLine;
  var prefixIcon;
  var buttonEnd;
  TemplateFormKeterangan(
      {this.fieldKey,
      this.hintText,
      this.helperText,
      this.labelText,
      this.onSaved,
      this.validator,
      this.controller,
      this.enabled = true,
      this.adaValidasi = false,
      this.keyboardNumber = false,
      this.numberOnly = false,
      this.titleText,
      this.textCapitalization = TextCapitalization.words,
      this.bottomMargin = 12.0,
      this.maxLine = 1,
      this.initialValue,
      this.prefixIcon,
      this.color = Colors.white,
      this.fontSize = 14,
      this.radius = 16,
      this.formHeight = 48,
      this.minLine = 1,
      this.formatter,
      this.buttonEnd});
  @override
  _TemplateFormKeteranganState createState() => _TemplateFormKeteranganState();
}

class _TemplateFormKeteranganState extends State<TemplateFormKeterangan> {
  String? _validate(String? value) {
    if (value!.isEmpty) return 'Please fill this form.';
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: widget.bottomMargin),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          widget.titleText != null
              ? Padding(
                  padding: const EdgeInsets.only(bottom: 8),
                  child: Text(
                    widget.titleText!,
                    style: TextStyle(
                        color: widget.color,
                        fontWeight: FontWeight.bold,
                        fontSize: widget.fontSize),
                  ),
                )
              : Container(),
          Container(
            padding: EdgeInsets.only(right: 6),
            height: widget.formHeight,
            decoration: widget.buttonEnd != null
                ? BoxDecoration(
                    border: Border.all(color: widget.color, width: 0.8),
                    borderRadius:
                        BorderRadius.all(Radius.circular(widget.radius)))
                : null,
            child: Row(
              children: [
                Expanded(
                  child: TextFormField(
                    minLines: widget.minLine,
                    initialValue: widget.initialValue,
                    cursorColor: widget.color,
                    maxLines: widget.maxLine,
                    controller: widget.controller,
                    keyboardType: TextInputType.multiline,
                    inputFormatters: widget.numberOnly
                        ? <TextInputFormatter>[
                            FilteringTextInputFormatter.digitsOnly,
                          ]
                        : widget.formatter != null
                            ? [
                                widget.formatter,
                              ]
                            : null,
                    key: widget.fieldKey,
                    enabled: widget.enabled,
                    style: TextStyle(
                        fontSize: widget.fontSize, color: widget.color),
                    decoration: InputDecoration(
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(widget.radius),
                          borderSide: BorderSide(
                            color: widget.buttonEnd == null
                                ? widget.color
                                : Colors.transparent,
                            width: 0.8,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(widget.radius),
                          borderSide: BorderSide(
                            color: widget.buttonEnd == null
                                ? widget.color
                                : Colors.transparent,
                            width: 1,
                          ),
                        ),
                        disabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(widget.radius),
                          borderSide: BorderSide(
                            color: widget.buttonEnd == null
                                ? Colors.grey
                                : Colors.transparent,
                            width: 0.8,
                          ),
                        ),
                        hintStyle: TextStyle(
                            color: widget.enabled
                                ? widget.color
                                : Colors.grey[600]),
                        labelStyle: TextStyle(color: widget.color),
                        fillColor: Colors.transparent,
                        filled: true,
                        prefixIcon: widget.prefixIcon,
                        contentPadding: EdgeInsets.all(10),
                        hintText: widget.hintText,
                        labelText: widget.labelText),
                    validator: widget.adaValidasi == true ? _validate : null,
                    onSaved: widget.onSaved,
                  ),
                ),
                widget.buttonEnd ?? Container()
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class TemplateFormFilterKanban extends StatefulWidget {
  final Key? fieldKey;
  final String? hintText;
  final String? labelText;
  final String? helperText;
  final String? titleText;
  final String? titleText2;
  var color;
  var colorTitle2;
  var initialValue;
  final double? fontSize;
  final double? formHeight;
  final FormFieldSetter<String>? onSaved;
  final FormFieldSetter<String>? onChange;
  final FormFieldValidator<String>? validator;
  final TextEditingController? controller;
  final TextCapitalization textCapitalization;
  var formatter;
  final bool enabled;
  final bool adaValidasi;
  final bool keyboardNumber;
  final bool numberOnly;
  final double bottomMargin;
  final double? radius;
  final int maxLine;
  final int minLine;
  var contentPadding;
  var prefixIcon;
  var buttonEnd;
  TemplateFormFilterKanban(
      {this.fieldKey,
        this.hintText,
        this.helperText,
        this.labelText,
        this.onSaved,
        this.onChange,
        this.validator,
        this.controller,
        this.enabled = true,
        this.adaValidasi = false,
        this.keyboardNumber = false,
        this.numberOnly = false,
        this.titleText,
        this.titleText2 = '',
        this.textCapitalization = TextCapitalization.words,
        this.bottomMargin = 12.0,
        this.maxLine = 1,
        this.initialValue,
        this.prefixIcon,
        this.color = Colors.white,
        this.colorTitle2 = Colors.white,
        this.fontSize = 14,
        this.radius = 16,
        this.formHeight = 48,
        this.minLine = 1,
        this.formatter,
        this.buttonEnd,
        this.contentPadding = const EdgeInsets.fromLTRB(7.0, 0, 20.0, 0)});
  @override
  _TemplateFormFilterKanbanState createState() => _TemplateFormFilterKanbanState();
}

class _TemplateFormFilterKanbanState extends State<TemplateFormFilterKanban> {
  String? _validate(String? value) {
    if (value!.isEmpty) return 'Please fill this form.';
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: widget.bottomMargin),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          // widget.titleText != ''&&widget.titleText!=null
          //     ? Padding(
          //   padding: const EdgeInsets.only(bottom: 8, left: 11),
          //   child: widget.titleText2!=null?Row(
          //     children: [
          //       Text(
          //         widget.titleText!,
          //         style: TextStyle(
          //           // color: widget.color,
          //             color: Colors.grey,
          //             fontWeight: FontWeight.w500,
          //             fontSize: widget.fontSize),
          //       ),
          //       SizedBox(width: 4,),
          //       Text(
          //         widget.titleText2!,
          //         style: TextStyle(
          //             color: widget.colorTitle2,
          //             fontWeight: FontWeight.bold,
          //             fontSize: widget.fontSize),
          //       )
          //     ],
          //   ):Text(
          //     widget.titleText!,
          //     style: TextStyle(
          //         color: widget.color,
          //         fontWeight: FontWeight.bold,
          //         fontSize: widget.fontSize),
          //   ),
          // )
          //     : Container(),
          Container(
            padding: EdgeInsets.only(right: 6),
            height: widget.formHeight,
            // decoration: widget.buttonEnd != null
            //     ? BoxDecoration(
            //     border: Border.all(color: widget.color, width: 0.8),
            //     borderRadius:
            //     BorderRadius.all(Radius.circular(widget.radius!)))
            //     : null,
            child: Row(
              children: [
                Expanded(
                  child: TextFormField(
                    minLines: widget.minLine,
                    initialValue: widget.initialValue,
                    cursorColor: widget.color,
                    maxLines: widget.maxLine,
                    controller: widget.controller,
                    keyboardType: widget.keyboardNumber
                        ? TextInputType.number
                        : TextInputType.text,
                    inputFormatters: widget.numberOnly
                        ? <TextInputFormatter>[
                      FilteringTextInputFormatter.digitsOnly,
                    ]
                        : widget.formatter != null
                        ? [
                      widget.formatter,
                    ]
                        : null,
                    key: widget.fieldKey,
                    enabled: widget.enabled,
                    style: TextStyle(
                        fontSize: widget.fontSize, color: widget.color),
                    decoration: InputDecoration(
                      // label: Text("Hahahaha"),
                        // enabledBorder: OutlineInputBorder(
                        //   borderRadius: BorderRadius.circular(widget.radius!),
                        //   borderSide: BorderSide(
                        //     color: widget.buttonEnd == null
                        //         ? widget.color
                        //         : Colors.transparent,
                        //     width: 0.8,
                        //   ),
                        // ),
                        // focusedBorder: OutlineInputBorder(
                        //   borderRadius: BorderRadius.circular(widget.radius!),
                        //   borderSide: BorderSide(
                        //     color: widget.buttonEnd == null
                        //         ? widget.color
                        //         : Colors.transparent,
                        //     width: 1,
                        //   ),
                        // ),
                        // disabledBorder: OutlineInputBorder(
                        //   borderRadius: BorderRadius.circular(widget.radius!),
                        //   borderSide: BorderSide(
                        //     color: widget.buttonEnd == null
                        //         ? Colors.grey
                        //         : Colors.transparent,
                        //     width: 0.8,
                        //   ),
                        // ),
                        hintStyle: TextStyle(
                            color: widget.enabled
                                ? widget.color
                                : Colors.grey[600]),
                        labelStyle: TextStyle(color: widget.color),
                        fillColor: Colors.transparent,
                        filled: true,
                        prefixIcon: widget.prefixIcon,
                        contentPadding: widget.contentPadding,
                        hintText: widget.hintText,
                        labelText: "widget.labelText"),
                    validator: widget.adaValidasi == true ? _validate : null,
                    onSaved: widget.onSaved,
                    onChanged: widget.onChange,
                  ),
                ),
                widget.buttonEnd ?? Container()
              ],
            ),
          ),
        ],
      ),
    );
  }
}
