import 'package:flutter/material.dart';

import '../../app/constant.dart';

// login
class CustomTextFieldLogin extends StatelessWidget {
  final String hintText;
  final String labelText;
  final bool isPassword;
  final bool obscureText;
  final bool isMaxLine;
  final void Function()? onToggle;
  final TextEditingController? ctrl;
  final void Function(String)? onChange;
  final void Function(String)? onSubmitted;
  final void Function()? onTap;
  final void Function()? onEditingComplete;
  final FocusNode? focusNode;
  final bool isPrefix;

  final bool isError;
  final bool isTextArea;
  final bool isReadOnly;

  final bool hasFocus;

  const CustomTextFieldLogin({
    Key? key,
    required this.hintText,
    required this.labelText,
    this.isPassword = false,
    this.isMaxLine = false,
    this.onToggle,
    this.obscureText = false,
    this.ctrl,
    this.onChange,
    this.onSubmitted,
    this.focusNode,
    this.isPrefix = false,
    this.isTextArea = false,
    this.isError = false,
    this.isReadOnly = false,
    this.hasFocus = false,
    this.onTap,
    this.onEditingComplete
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      autofocus: true,
      showCursor: (hasFocus) ? true : false,
      readOnly: isReadOnly,
      controller: ctrl,
      enableInteractiveSelection: false,
      style:
          Constant.titleH4Login(context: context).copyWith(color: Colors.white),
      obscureText: obscureText,
      onChanged: onChange,
      onSubmitted: onSubmitted,
      onTap: onTap,
      onEditingComplete: onEditingComplete,
      focusNode: focusNode,
      maxLines: (isTextArea) ? 4 : 1,
      cursorColor: Colors.white,
      decoration: InputDecoration(
        fillColor: (hasFocus) ? Color(0xffff6868) : Color(0xffd90504),
        filled: true,
        focusedBorder: OutlineInputBorder(
          borderSide:
              BorderSide(color: Constant.buttonLoginBackgroundColor, width: 2),
          borderRadius: BorderRadius.circular(30),
        ),
        enabledBorder: (isError == true)
            ? OutlineInputBorder(
                // ignore: prefer_const_constructors
                borderRadius: BorderRadius.all(Radius.circular(30)),
                borderSide: BorderSide(
                  color: Constant.textRedProblemMaketing,
                  width: 1,
                ),
              )
            : OutlineInputBorder(
                // ignore: prefer_const_constructors
                borderRadius: BorderRadius.all(Radius.circular(30)),
                borderSide: BorderSide(
                  color: Constant.buttonLoginBackgroundColor,
                  width: 2,
                ),
              ),
        // hintStyle: Constant.body1_400(context: context)
        //     .copyWith(color: Constant.textBlack),
        // labelStyle: Constant.body3_400(context: context),
        hintStyle:
            Constant.body3_400(context: context).copyWith(color: Colors.white),
        labelStyle: Constant.body3_400(context: context),
        // labelText: labelText,
        hintText: hintText,
        alignLabelWithHint: true,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(30),
        ),
        prefixIcon: isPrefix ? const Icon(Icons.search) : null,
        prefixStyle: isPrefix ? Constant.titleH4Login(context: context) : null,
        // suffixIcon: isPassword
        //     ? IconButton(
        //         alignment: Alignment.centerRight,
        //         onPressed: onToggle,
        //         icon: const Icon(Icons.remove_red_eye),
        //         iconSize: Constant.getActualYPhone(context: context, y: 24),
        //       )
        //     : null,
      ),
    );
  }
}

// selain login
class CustomTextField extends StatelessWidget {
  final String hintText;
  final String labelText;
  final bool isPassword;
  final bool obscureText;
  final bool isMaxLine;
  final void Function()? onToggle;
  final TextEditingController? ctrl;
  final void Function(String)? onChange;
  final void Function(String)? onSubmitted;
  final FocusNode? focusNode;
  final bool isPrefix;

  final bool isError;
  final bool isTextArea;
  final bool isReadOnly;
  final bool isNumber;

  const CustomTextField(
      {Key? key,
      required this.hintText,
      required this.labelText,
      this.isPassword = false,
      this.isMaxLine = false,
      this.onToggle,
      this.obscureText = false,
      this.ctrl,
      this.onChange,
      this.onSubmitted,
      this.focusNode,
      this.isPrefix = false,
      this.isTextArea = false,
      this.isError = false,
      this.isReadOnly = false,
      this.isNumber = false
      })
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      readOnly: isReadOnly,
      controller: ctrl,
      style: Constant.titleH4Login(context: context),
      obscureText: obscureText,
      onChanged: onChange,
      onSubmitted: onSubmitted,
      focusNode: focusNode,
      maxLines: (isTextArea) ? 4 : 1,
      keyboardType: (isNumber) ? TextInputType.number : TextInputType.text,
      decoration: InputDecoration(
        // focusedBorder: OutlineInputBorder(
        //   borderSide: BorderSide(color: Constant.textGrey, width: 1),
        //   borderRadius: BorderRadius.circular(8.0),
        // ),
        enabledBorder: (isError == true)
            ? OutlineInputBorder(
                // ignore: prefer_const_constructors
                borderRadius: BorderRadius.all(Radius.circular(8)),
                borderSide: BorderSide(
                  color: Constant.textRedProblemMaketing,
                  width: 1,
                ),
              )
            : null,
        // hintStyle: Constant.body1_400(context: context)
        //     .copyWith(color: Constant.textBlack),
        // labelStyle: Constant.body3_400(context: context),
        hintStyle: Constant.body3_400(context: context),
        labelStyle: Constant.body3_400(context: context),
        labelText: labelText,
        hintText: hintText,
        alignLabelWithHint: true,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
        ),
        prefixIcon: isPrefix ? const Icon(Icons.search) : null,
        prefixStyle: isPrefix ? Constant.titleH4Login(context: context) : null,
        // suffixIcon: isPassword
        //     ? IconButton(
        //         alignment: Alignment.centerRight,
        //         onPressed: onToggle,
        //         icon: const Icon(Icons.remove_red_eye),
        //         iconSize: Constant.getActualYPhone(context: context, y: 24),
        //       )
        //     : null,
      ),
    );
  }
}

// untuk inputan selain login
class CustomTextFieldV2 extends StatelessWidget {
  final String hintText;
  final String labelText;
  final bool isPassword;
  final bool obscureText;
  final bool isMaxLine;
  final void Function()? onToggle;
  final TextEditingController? ctrl;
  final void Function(String)? onChange;
  final void Function(String)? onSubmitted;
  final FocusNode? focusNode;
  final bool isPrefix;
  final InkWell? suffixIcon;

  final bool isError;
  final bool isTextArea;

  const CustomTextFieldV2(
      {Key? key,
      required this.hintText,
      required this.labelText,
      this.isPassword = false,
      this.isMaxLine = false,
      this.onToggle,
      this.obscureText = false,
      this.ctrl,
      this.onChange,
      this.onSubmitted,
      this.focusNode,
      this.isPrefix = false,
      this.isTextArea = false,
      this.isError = false,
      this.suffixIcon})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: ctrl,
      style: Constant.titleH4Login(context: context),
      obscureText: obscureText,
      onChanged: onChange,
      onSubmitted: onSubmitted,
      focusNode: focusNode,
      maxLines: (isTextArea) ? 4 : 1,
      decoration: InputDecoration(
          // focusedBorder: OutlineInputBorder(
          //   borderSide: BorderSide(color: Constant.textGrey, width: 1),
          //   borderRadius: BorderRadius.circular(8.0),
          // ),
          enabledBorder: (isError == true)
              ? OutlineInputBorder(
                  // ignore: prefer_const_constructors
                  borderRadius: BorderRadius.all(Radius.circular(8)),
                  borderSide: BorderSide(
                    color: Constant.textRedProblemMaketing,
                    width: 1,
                  ),
                )
              : null,
          hintStyle: Constant.body3_400(context: context),
          labelStyle: Constant.body3_400(context: context),
          labelText: labelText,
          hintText: hintText,
          alignLabelWithHint: true,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(8),
          ),
          prefixIcon: isPrefix ? const Icon(Icons.search) : null,
          prefixStyle:
              isPrefix ? Constant.titleH4Login(context: context) : null,
          suffixIcon: suffixIcon
          // suffixIcon: isPassword
          //     ? IconButton(
          //         alignment: Alignment.centerRight,
          //         onPressed: onToggle,
          //         icon: const Icon(Icons.remove_red_eye),
          //         iconSize: Constant.getActualYPhone(context: context, y: 24),
          //       )
          //     : null,
          ),
    );
  }
}
