import React from "react";
import PropTypes from "prop-types";
import { TextField } from "../../../../../../TextFields/TextField/TextField";
import { ReactComponent as CloseBlack } from "../../../../../../../assets/images/svg/close-black.svg";
import { ClearText } from "./SearchField.styled";

const SearchField = (props) => {
  const handleClear = () => {
    props.onChange("");
  };
  return (
    <TextField
      placeholder={props.placeholder}
      italicPlaceholder
      value={props.value}
      onChange={props.onChange}
      textsize={"12px"}
      font={"Open Sans"}
      fullWidth
      height={"40px"}
      containerStyle={{ marginTop: "6px" }}
      InputProps={{
        endAdornment:
          props.value.length > 0 ? (
            <ClearText onClick={handleClear}>
              <CloseBlack />
            </ClearText>
          ) : (
            <React.Fragment />
          ),
      }}
    />
  );
};

SearchField.propTypes = {
  value: PropTypes.string,
  placeholder: PropTypes.string,
  onChange: PropTypes.func,
};

export default SearchField;
