import { TextField } from "@mui/material";

function Field({
  type,
  name,
  error,
  title,
  props,
  value,
  multiline,
  handleChange,
  isPlaceHolder,
}) {
  return (
    <TextField
      {...props}
      size="small"
      defaultValue={value || ""}
      type={type || "text"}
      multiline={!!multiline}
      rows={!!multiline ? 4 : 1}
      label={!isPlaceHolder ? title : ""}
      placeholder={isPlaceHolder && title}
      className="!w-full !mx-auto !bg-[#FFF]"
      onChange={(e) => {
        handleChange?.(name || "", e.target.value);
      }}
      sx={{
        "& .MuiFormLabel-root": {
          top: "-4px !important",
        },
        "& .MuiInputBase-input": { padding: "12.5px 14px" },
        "& .MuiInputBase-root": { borderRadius: "6px !important" },
        "& .MuiOutlinedInput-notchedOutline": {
          border: error
            ? "1px solid red !important"
            : "1px solid #E9ECEF !important",
        },
        ".Mui-focused": {
          "& .MuiOutlinedInput-notchedOutline": {
            border: "1px solid #5559CE !important",
            transition: "0.5s all",
          },
        },
        "& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button":
          {
            display: "none",
          },
      }}
    />
  );
}

export default Field;
