import{h}from"@stencil/core";import{CloseIcon,PrevIcon,NextIcon,SearchIcon}from"./icons";export class PrestoSearchBarUi{constructor(){this.value=void 0,this.placeholder=void 0,this.hasNavigation=void 0,this.focused=void 0,this.placeholderWidth=void 0}handleSearch(e){e.preventDefault(),this.value=e.target.value}handleFocus(){this.focused=!0}handleBlur(){this.value||(this.focused=!1)}componentDidLoad(){this.handlePlaceholderSize()}handlePlaceholderSize(){setTimeout((()=>{this.placeholderWidth=this.placeholderElement.offsetWidth}),50)}handleValueChange(){this.search.emit(this.value)}watchPropHandler(e){this.focusChange.emit(e)}handleClick(){this.focused=!0,setTimeout((()=>{this.input.focus()}),50)}handleClear(e){return e.preventDefault(),e.stopImmediatePropagation(),this.value="",this.focused=!1,!1}handleNext(e){e.stopImmediatePropagation(),e.preventDefault(),this.nextNav.emit()}handlePrevious(e){e.stopImmediatePropagation(),e.preventDefault(),this.previousNav.emit()}render(){return h("div",{class:{"search-bar":!0,"search-bar--is-active":this.focused||!!this.value,"search-bar--has-navigation":this.hasNavigation},onClick:()=>this.handleClick()},h("span",{class:"search-bar__search-icon search-bar__icon"},h(SearchIcon,null)),h("div",{class:"search-bar__placeholder",ref:e=>this.placeholderElement=e,"aria-hidden":!0},this.placeholder),h("input",{type:"text",value:this.value,placeholder:this.placeholder,ref:e=>this.input=e,style:{width:(this.placeholderWidth||0)+"px"},onInput:e=>this.handleSearch(e),onFocus:()=>this.handleFocus(),onBlur:()=>this.handleBlur()}),h("span",{class:"search-bar__controls"},h("span",{class:"search-bar__control-prev",onClick:e=>this.handlePrevious(e)},h(PrevIcon,null)),h("span",{class:"search-bar__control-next",onClick:e=>this.handleNext(e)},h(NextIcon,null)),h("div",{class:"search-bar__control-clear",onClick:e=>this.handleClear(e)},h(CloseIcon,null))))}static get is(){return"presto-search-bar-ui"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["presto-search-bar-ui.scss"]}}static get styleUrls(){return{$:["presto-search-bar-ui.css"]}}static get properties(){return{value:{type:"string",mutable:!0,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The value for the search."},attribute:"value",reflect:!1},placeholder:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The placeholder."},attribute:"placeholder",reflect:!1},hasNavigation:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Has results"},attribute:"has-navigation",reflect:!1}}}static get states(){return{focused:{},placeholderWidth:{}}}static get events(){return[{method:"previousNav",name:"previousNav",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:"Previous is navigated."},complexType:{original:"void",resolved:"void",references:{}}},{method:"nextNav",name:"nextNav",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:"Next is navigated"},complexType:{original:"void",resolved:"void",references:{}}},{method:"search",name:"search",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:"Search is performed"},complexType:{original:"string",resolved:"string",references:{}}},{method:"focusChange",name:"focusChange",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:"Search is performed"},complexType:{original:"boolean",resolved:"boolean",references:{}}}]}static get watchers(){return[{propName:"placeholder",methodName:"handlePlaceholderSize"},{propName:"value",methodName:"handleValueChange"},{propName:"focused",methodName:"watchPropHandler"}]}}