(()=>{"use strict";var e={};function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},t.apply(this,arguments)}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const r=window.wp.element,o=window.wp.data,n=window.wp.apiFetch;var s=e.n(n);const a=window.wp.url,i=window.wp.compose,p=window.wp.i18n;class m extends r.Component{constructor(){super(),this.state={terms:null,primaryTermId:0}}componentDidMount(){s()({path:(0,a.addQueryArgs)(`/wp/v2/${this.props.primaryTaxonomy.restBase}`,{_fields:"id,name",orderby:"count",order:"desc",per_page:-1})}).then((e=>{this.setState({terms:e})})),this.setState({primaryTermId:this.props.primaryTaxonomy.primary})}onSelectChange(e){const t={};t[`pcpricat_primary_term_${this.props.primaryTaxonomy.name}`]=parseInt(e.target.value,10),this.props.updateSPC(t),this.setState({primaryTermId:e.target.value})}render(){const{primaryTaxonomy:e,selectedTermsIds:t}=this.props,{title:o}=e;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)("h4",null,(0,p.sprintf)(
/* translators: %s expands to taxonomy title. */
(0,p.__)("Primary %s","soledad"),o)),(0,r.createElement)("select",{onChange:this.onSelectChange.bind(this)},(0,r.createElement)("option",{value:"-1"},(0,p.sprintf)(
/* translators: %s expands to taxonomy title. */
(0,p.__)("— Select Primary %s —","soledad"),o)),this.state.terms&&this.state.terms.map((e=>{if(t.includes(e.id))return this.state.primaryTermId===e.id?(0,r.createElement)("option",{value:e.id,selected:!0},e.name):(0,r.createElement)("option",{value:e.id},e.name)}))))}}const c=(0,i.compose)([(0,o.withSelect)(((e,t)=>{let{primaryTaxonomy:r}=t;const{getEditedPostAttribute:o}=e("core/editor");return{selectedTermsIds:o(r.restBase),meta:o("meta")}})),(0,o.withDispatch)((e=>{const{editPost:t}=e("core/editor");return{updateSPC(e){t({meta:e})}}}))])(m);class l extends r.Component{constructor(){super(),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){const{slug:e,TaxonomyComponent:t}=this.props,o=pcpricatData.taxonomies;return this.state.hasError?(0,r.createElement)(t,this.props):o.hasOwnProperty(e)?(0,r.createElement)(r.Fragment,null,(0,r.createElement)(t,this.props),(0,r.createElement)(c,{primaryTaxonomy:o[e]})):(0,r.createElement)(t,this.props)}}const d=l;function u(e){return o=>(0,r.createElement)(d,t({TaxonomyComponent:e},o))}"undefined"!=typeof wp&&void 0!==wp.blocks&&wp.hooks.addFilter("editor.PostTaxonomyType","soledad",u)})();