import Router from 'next/router' import { useState, useEffect } from 'react' export default (props:{ defaultValue?:string, on?:(string)=>void, mainpage?:boolean, title?:string, lbtntext?:string, onplus?:()=>void, lefticon?:any, lefticondisable?:boolean, placeholder?:string, onbtnl?:()=>void,onlefticon?:()=>void, }) => { var [clicked, setClicked] = useState(false) useEffect(() => { if (!props.defaultValue && !Router.query.s && (document.getElementById("searchinput") as HTMLInputElement).value) { (document.getElementById("searchinput") as HTMLInputElement).value = "" } }) var onsearch = (txt) => { if (props.on) { props.on(txt) } else { if (props.mainpage) { Router.push(global.root + "/" + txt) } else { if (txt == "") { delete Router.query.s Router.push({ pathname: Router.pathname, query: Router.query }) } else { Router.query.s = txt Router.push({ pathname: Router.pathname, query: Router.query }) } } } } return
{props.title} {props.lbtntext ? <> { props.onbtnl?.() }}>{props.lbtntext}
: null}   {props.onplus ? <> new icon { props.onplus?.() }} /> : null} {props.lefticon ? <> search option's icon { props.onlefticon?.() }} /> : null}
{ if ((document.getElementById("searchinput") as HTMLInputElement).value?.length > 0) { if (props.mainpage) { Router.push(global.root) } else { delete Router.query.s Router.push({ pathname: Router.pathname, query: Router.query }) } } }}> search close's icon { }} /> { if (!clicked) { e.target.select(); e.preventDefault(); setClicked(true) } }} placeholder={props.placeholder} type='text' defaultValue={props.defaultValue} onBlur={() => { setClicked(false) }} spellCheck={false} onKeyDown={(event) => { // console.log(event) if (event.key == "Enter" || event.key == "NumpadEnter") { onsearch(event.target.value) } }} />
 go for search { onsearch((document.getElementById("searchinput") as HTMLInputElement).value) }} />
}