import React, { useEffect, useState, useCallback } from "react";
import useDebounce from "../../../hooks/useDebounce";
import { TextInput } from "../../../components/input";
import { Icon } from "../../../components/icon";
var SearchInput = function SearchInput(_ref) {
  var defaultValue = _ref.value,
    setSearchTerm = _ref.setSearchTerm,
    setSearchView = _ref.setSearchView,
    controlled = _ref.controlled;
  var _useState = useState(defaultValue),
    value = _useState[0],
    setValue = _useState[1];
  useDebounce(function () {
    setSearchTerm(value);
    if (value.length < 3) return;
    setSearchView();
  }, 300, [value]);
  var onChange = useCallback(function (e) {
    return setValue(e.target.value);
  }, []);
  useEffect(function () {
    if (!controlled) return;
    setValue(defaultValue);
  }, [defaultValue]);
  return /*#__PURE__*/React.createElement(TextInput, {
    value: value,
    onChange: onChange,
    placeholder: "Search Netdata\u2019s docs & community",
    autoFocus: true,
    iconLeft: /*#__PURE__*/React.createElement(Icon, {
      name: "search_s",
      size: "small",
      color: value ? "text" : "border"
    })
  });
};
export default SearchInput;