import{d as G,e as B,l as d,m as w,v as V,n as y,F as P,T as $,q as I,x as v,u as s,y as b,z as N,a as z}from"./index.CPcBO1Os.js";import{F as L}from"./index.IU6dhWj-.js";import{S as k,s as q}from"./index.Dhyc5KML.js";import{_ as S,s as W,j as X,l as x,d as H,n as J}from"./index.TkDYtvUB.js";import{o as E}from"./omit.ddwJ_9WE.js";import{I as K}from"./index.DX3sx_CG.js";import{B as U}from"./index.B1jVoQr7.js";const i=()=>null;i.isSelectOption=!0;i.displayName="AAutoCompleteOption";const g=()=>null;g.isSelectOptGroup=!0;g.displayName="AAutoCompleteOptGroup";function Q(t){var r,o;return((r=t==null?void 0:t.type)===null||r===void 0?void 0:r.isSelectOption)||((o=t==null?void 0:t.type)===null||o===void 0?void 0:o.isSelectOptGroup)}const Y=()=>S(S({},E(q(),["loading","mode","optionLabelProp","labelInValue"])),{dataSource:Array,dropdownMenuStyle:{type:Object,default:void 0},dropdownMatchSelectWidth:{type:[Number,Boolean],default:!0},prefixCls:String,showSearch:{type:Boolean,default:void 0},transitionName:String,choiceTransitionName:{type:String,default:"zoom"},autofocus:{type:Boolean,default:void 0},backfill:{type:Boolean,default:void 0},filterOption:{type:[Boolean,Function],default:!1},defaultActiveFirstOption:{type:Boolean,default:!0},status:String}),A=G({compatConfig:{MODE:3},name:"AAutoComplete",inheritAttrs:!1,props:Y(),slots:Object,setup(t,r){let{slots:o,attrs:p,expose:f}=r;W(!t.dropdownClassName);const u=B(),_=()=>{var e;const a=J((e=o.default)===null||e===void 0?void 0:e.call(o));return a.length?a[0]:void 0};f({focus:()=>{var e;(e=u.value)===null||e===void 0||e.focus()},blur:()=>{var e;(e=u.value)===null||e===void 0||e.blur()}});const{prefixCls:m}=X("select",t);return()=>{var e,a,C;const{size:F,dataSource:D,notFoundContent:M=(e=o.notFoundContent)===null||e===void 0?void 0:e.call(o)}=t;let O;const{class:j}=p,R={[j]:!!j,["".concat(m.value,"-lg")]:F==="large",["".concat(m.value,"-sm")]:F==="small",["".concat(m.value,"-show-search")]:!0,["".concat(m.value,"-auto-complete")]:!0};if(t.options===void 0){const h=((a=o.dataSource)===null||a===void 0?void 0:a.call(o))||((C=o.options)===null||C===void 0?void 0:C.call(o))||[];h.length&&Q(h[0])?O=h:O=D?D.map(n=>{if(x(n))return n;switch(typeof n){case"string":return d(i,{key:n,value:n},{default:()=>[n]});case"object":return d(i,{key:n.value,value:n.value},{default:()=>[n.text]});default:throw new Error("AutoComplete[dataSource] only supports type `string[] | Object[]`.")}}):[]}const T=E(S(S(S({},t),p),{mode:k.SECRET_COMBOBOX_MODE_DO_NOT_USE,getInputElement:_,notFoundContent:M,class:R,popupClassName:t.popupClassName||t.dropdownClassName,ref:u}),["dataSource","loading"]);return d(k,T,H({default:()=>[O]},E(o,["default","dataSource","options"])))}}}),Z=S(A,{Option:i,OptGroup:g,install(t){return t.component(A.name,A),t.component(i.displayName,i),t.component(g.displayName,g),t}}),ee={key:0,class:"additional-data-sources-inputs"},ue=G({__name:"UrlDataSourcesField",props:{name:{},dataSources:{},enableDataSources:{type:Boolean}},setup(t){const{Item:r}=L,{Option:o}=k,{__:p}=window.wp.i18n,f=B([]),u=B(!1),_=async l=>{if(!l){f.value=[];return}u.value=!0;try{const c=await z(l);f.value=c}catch(c){console.error("Error searching posts:",c)}finally{u.value=!1}};return(l,c)=>l.enableDataSources?(y(),w("div",ee,[(y(!0),w(P,null,$(l.dataSources,(m,e)=>(y(),I(s(r),{key:e,class:"data-source-input",name:[l.name,e]},{default:v(()=>[d(s(Z),{value:l.dataSources[e],"onUpdate:value":a=>l.dataSources[e]=a,options:f.value,loading:u.value,style:{width:"100%"},onSearch:_},{dataSource:v(()=>[(y(!0),w(P,null,$(f.value,a=>(y(),I(s(o),{key:a.value,value:a.value},{default:v(()=>[b(N(a.label),1)]),_:2},1032,["value"]))),128))]),default:v(()=>[d(s(K),{size:"large",placeholder:s(p)("Enter page URL or select a post/page","storeagent-ai-for-woocommerce")},null,8,["placeholder"])]),_:2},1032,["value","onUpdate:value","options","loading"]),d(s(U),{type:"text",danger:"",onClick:a=>l.dataSources.splice(e,1)},{default:v(()=>[b(N(s(p)("Remove","storeagent-ai-for-woocommerce")),1)]),_:2},1032,["onClick"])]),_:2},1032,["name"]))),128)),d(s(U),{type:"dashed",block:"",onClick:c[0]||(c[0]=m=>l.dataSources.push(""))},{default:v(()=>[b(N(s(p)("Add Data Source","storeagent-ai-for-woocommerce")),1)]),_:1})])):V("",!0)}});export{ue as _};
