import React, { useState } from "react";
import { Input ,notification} from "antd";

const { Search } = Input;
export default ({history,searchUrl}) => {
  const [openSearch, setOpenSearch] = useState(false);

  function onGlobalSearch(value) {
    history.push('/search?value=' + value);
    // window.location.href = `search?value=` + value;
    // history.push({
    //   pathname:'/search',
    //   state:value
    // })
  }
  return (
    <React.Fragment>
      {
        openSearch ?
          <div
            onBlur={() => {
              setTimeout(() => {
                setOpenSearch(false)
              }, 500)
            }}
          >
            <Search placeholder="请输入搜索关键字"
              className={`search-input mr20`}
              onSearch={onGlobalSearch}
              autoFocus={true}
              style={{width:'260px'}}
            />
          </div>
          :
          <a href={`${searchUrl}?value=`}><i className="iconfont icon-sousuo font-18 ml15 mr15 color-white" /></a>
      }
    </React.Fragment>
  )
};
