"use strict";(self.webpackChunktainacan=self.webpackChunktainacan||[]).push([[468],{67510(e,t,a){a.d(t,{A:()=>l});var s=a(75552),i=a(8926);const l={mixins:[i.s,i.F],emits:["input"],data:function(){return{selected:"",options:[],label:"",searchQuery:"",searchOffset:0,searchNumber:12,totalFacets:0}},watch:{query:{handler:function(){this.updateSelectedValues()},deep:!0}},mounted:function(){this.updateSelectedValues()},methods:{onSelect:function(e){e&&(this.selected=e.value,this.label=e.label,this.$emit("input",{filter:"autocomplete",metadatum_id:this.metadatumId,collection_id:this.collectionId,value:this.selected}),this.updateSelectedValues())},search:_.debounce((function(e){var t=this;if(e!=this.searchQuery&&(this.searchQuery=e,this.options=[],this.searchOffset=0),e.length||(this.searchQuery=e,this.options=[],this.searchOffset=0),!(this.searchOffset>0&&this.options.length>=this.totalFacets))if(""!=this.searchQuery){null!=this.getOptionsValuesCancel&&this.getOptionsValuesCancel.cancel("Facet search Canceled.");var a="Tainacan\\Metadata_Types\\Relationship"===this.metadatumType?this.getValuesRelationship({search:this.searchQuery,isRepositoryLevel:this.isRepositoryLevel,valuesToIgnore:[],offset:this.searchOffset,number:this.searchNumber}):this.getValuesPlainText({metadatumId:this.metadatumId,search:this.searchQuery,isRepositoryLevel:this.isRepositoryLevel,valuesToIgnore:[],offset:this.searchOffset,number:this.searchNumber});a.request.then((function(e){t.totalFacets=e.headers["x-wp-total"],t.searchOffset+=t.searchNumber})).catch((function(e){(0,s.FZ)(e)?t.$console.log("Request canceled: "+e.message):t.$console.error(e)})),this.getOptionsValuesCancel=a.source}else this.label="",this.selected=""}),500),searchMore:_.debounce((function(){this.shouldAddOptions=!0,this.search(this.searchQuery)}),250),updateSelectedValues:function(){var e=this;if(!this.query||!this.query.metaquery||!Array.isArray(this.query.metaquery))return!1;var t=this.query.metaquery.findIndex((function(t){return t.key==e.metadatumId}));if(t>=0){var a=this.query.metaquery[t];if("Tainacan\\Metadata_Types\\Relationship"===this.metadatumType){var i="/items/"+a.value+"?fetch_only=title,thumbnail";s.UY.get(i).then((function(t){var a=t.data;e.label=a.title,e.selected=a.title})).catch((function(t){e.$console.log(t)}))}else this.label=a.value,this.selected=a.value}else this.label="",this.selected=""}}}},33539(e,t,a){a.d(t,{X:()=>h});var s=a(6934),i={class:"block"},l={class:"media"},n={key:0,class:"media-left"},o=["src"],c={class:"ellipsed-text"},r={key:0,class:"has-text-dark"};function h(e,t,a,h,u,d){var f=(0,s.g2)("b-autocomplete"),p=(0,s.gN)("a11y-autocomplete");return(0,s.uX)(),(0,s.CE)("div",i,[(0,s.bo)(((0,s.uX)(),(0,s.Wv)(f,{modelValue:u.selected,"onUpdate:modelValue":[t[0]||(t[0]=function(e){return u.selected=e}),t[1]||(t[1]=function(t){e.resetPage(),d.search(t)})],icon:"magnify",size:"is-small","aria-labelledby":"filter-label-id-"+e.filter.id,data:u.options,expanded:"",loading:e.isLoadingOptions,field:"label",clearable:"",placeholder:e.filter.placeholder?e.filter.placeholder:"Tainacan\\Metadata_Types\\Relationship"===e.metadatumType?e.$i18n.get("info_type_to_search_items"):e.$i18n.get("info_type_to_search_metadata"),"check-infinite-scroll":"",onSelect:d.onSelect,onInfiniteScroll:d.searchMore},(0,s.eX)({default:(0,s.k6)((function(e){return[(0,s.Lk)("div",l,[e.option.img?((0,s.uX)(),(0,s.CE)("div",n,[(0,s.Lk)("img",{width:"24",alt:"",src:e.option.img},null,8,o)])):(0,s.Q3)("",!0),(0,s.Lk)("div",{style:(0,s.Tr)({width:e.option.img?"":"100%"}),class:"media-content"},[(0,s.Lk)("span",c,(0,s.v_)(e.option.label),1),null!=e.option.total_items?((0,s.uX)(),(0,s.CE)("span",r,(0,s.v_)("("+e.option.total_items+")"),1)):(0,s.Q3)("",!0)],4)])]})),_:2},[e.isLoadingOptions?void 0:{name:"empty",fn:(0,s.k6)((function(){return[(0,s.eW)((0,s.v_)(e.$i18n.get("info_no_options_found")),1)]})),key:"0"}]),1032,["modelValue","aria-labelledby","data","loading","placeholder","onSelect","onInfiniteScroll"])),[[p]])])}},90468(e,t,a){a.r(t),a.d(t,{default:()=>l});var s=a(42630),i=a(40335);const l=(0,a(66262).A)(i.A,[["render",s.X]])},40335(e,t,a){a.d(t,{A:()=>s.A});var s=a(67510)},42630(e,t,a){a.d(t,{X:()=>s.X});var s=a(33539)}}]);