(()=>{var e={942(e,t){var s;!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e="",t=0;t<arguments.length;t++){var s=arguments[t];s&&(e=a(e,r(s)))}return e}function r(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return o.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var s in e)n.call(e,s)&&e[s]&&(t=a(t,s));return t}function a(e,t){return t?e?e+" "+t:e+t:e}e.exports?(o.default=o,e.exports=o):void 0===(s=function(){return o}.apply(t,[]))||(e.exports=s)}()}},t={};function s(n){var o=t[n];if(void 0!==o)return o.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,s),r.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";s.r(n),s.d(n,{CheckboxField:()=>o,ColorField:()=>r,CustomSelectField:()=>d,DateField:()=>m,Field:()=>j,FieldContextProvider:()=>R,Fields:()=>b,FieldsContext:()=>B,HtmlField:()=>_,MeasureField:()=>C,MulticheckField:()=>w,NumberField:()=>S,ObjectSelectField:()=>T,RadioField:()=>M,RangeSliderField:()=>N,SelectField:()=>H,TextAreaField:()=>E,TextField:()=>I,TokenSelectField:()=>P,useFields:()=>z});const e=window.wp.components,t=window.ReactJSXRuntime,o=({value:s,onChange:n,label:o,...r})=>(0,t.jsx)(e.CheckboxControl,{...r,label:o,checked:s,onChange:n,__nextHasNoMarginBottom:!0}),r=({value:s="",onChange:n,...o})=>(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.ColorIndicator,{colorValue:s}),(0,t.jsx)(e.ColorPicker,{...o,color:s,onChangeComplete:e=>n(e?.hex??e)}),(0,t.jsx)(e.ColorPalette,{value:s,onChange:e=>{n(e??"")},colors:[{name:"red",color:"#f00"},{name:"white",color:"#fff"},{name:"blue",color:"#00f"}],clearable:!0})]}),a=window.wp.element,i=window.popupMaker.i18n,l=window.wp.compose,c=window.wp.htmlEntities,p=window.popupMaker.components,u=window.popupMaker.coreData,d=({label:e,value:s,onChange:n,entityType:o,multiple:r=!1,apiEndpoint:d="popup-maker/v2/object-search"})=>{const[m,g]=(0,a.useState)(""),[y,x]=(0,a.useState)({prefill:[],suggestions:[]}),[h,f]=(0,a.useState)(!1),v=(0,l.useDebounce)(e=>{g(e)},300);(0,a.useEffect)(()=>{(async()=>{f(!0);try{let e=`${d}?object_type=custom_entity&entity_type=${o}`;s&&(e+=`&include=${(Array.isArray(s)?s:[s]).join(",")}`),m&&(e+=`&s=${m}`);const t=(await(0,u.fetchFromWPApi)(e)).items.map(e=>({id:e.id,text:e.text}));let n=[];if(s){const e=Array.isArray(s)?s:[s];n=t.filter(t=>e.includes(t.id))}x({prefill:n,suggestions:t})}catch(e){x({prefill:[],suggestions:[]})}finally{f(!1)}})()},[s,m,o,d]);const j=e=>{const t=t=>t.find(t=>t.id===e);return t(y.suggestions)||t(y.prefill)},b=s?"string"==typeof s?[s]:s:[],_=e=>"object"==typeof e?e.value:e;return(0,t.jsx)("div",{className:"pum-custom-entity-select-field",children:(0,t.jsx)(p.SmartTokenControl,{label:e||(0,i.sprintf)(
// translators: %s: entity type.
// translators: %s: entity type.
(0,i.__)("%s(s)","popup-maker"),o.replace(/_/g," ").charAt(0).toUpperCase()+o.replace(/_/g," ").slice(1)),hideLabelFromVision:!0,multiple:r,placeholder:(0,i.sprintf)(
// translators: %s: entity type.
// translators: %s: entity type.
(0,i.__)("Select %s(s)","popup-maker"),o.replace(/_/g," ").toLowerCase()),tokenOnComma:!0,value:b,onInputChange:v,onChange:e=>{const t=e.map(e=>_(e)).filter(e=>null!==e&&""!==e);n(r?t:t[0]||"")},renderToken:e=>{const t=j(_(e));return t?(0,c.decodeEntities)(t.text):_(e)},renderSuggestion:e=>{const s=j(e);return s?(0,t.jsx)(t.Fragment,{children:(0,c.decodeEntities)(s.text)}):e},suggestions:y.suggestions.map(e=>e.id),messages:h?{noSuggestions:(0,i.__)("Searching…","popup-maker")}:void 0})})},m=({value:s,onChange:n,...o})=>(0,t.jsx)(t.Fragment,{children:(0,t.jsx)(e.BaseControl,{...o,hideLabelFromVision:!0,__nextHasNoMarginBottom:!0,children:(0,t.jsx)("input",{type:"date",value:s,onChange:e=>n(e.target.value)})})});var g=s(942),y=s.n(g);const x=window.popupMaker.utils,h=e=>"string"==typeof e?e.split(",").map(e=>({label:e,value:e})):Array.isArray(e)||"object"!=typeof e?e.map(e=>"string"==typeof e?{label:e,value:e}:e):Object.entries(e).map(([e,t])=>({label:t,value:e})),f=e=>{let s;switch(s=function(e){const t={...e};return!(!t||void 0===t?.std&&void 0===t?.user_roles&&(void 0===t?.type||"userselect"!==t?.type)&&void 0===t?.taxonomy&&void 0===t?.post_type)}(e)?(e=>{const s={type:"select2"!==e.type?e.type:"select",default:e.std,id:e.id??e.name??"",...(0,x.pick)(e,"id","name","label","value","required","dependencies")},n=[];switch(void 0!==e.classes&&("string"==typeof e.classes?n.push(...e.classes.split(" ")):Array.isArray(e.classes)&&n.push(...e.classes)),void 0!==e.class&&n.push(e.class),s.className=y()(n),e.dynamic_desc?s.help=(0,t.jsx)(t.Fragment,{children:e.dynamic_desc}):e.desc&&(s.help=e.desc),s.type){case"checkbox":case"hidden":case"html":case"license_key":return s;case"color":return{...s,default:e.value??""};case"customselect":return{...s,entityType:s.entityType??"custom"};case"text":case"email":case"tel":case"password":default:return{...s,...s.type===e.type&&{size:e?.size,placeholder:e?.placeholder}};case"radio":case"multicheck":return{...s,options:[],...s.type===e.type&&{options:e.options??[]}};case"select":case"multiselect":return s.type!==e.type&&"select2"!==e.type||(s.options=h(e.options??[]),s.searchable="select2"===e.type,s.multiple="multiselect"===s.type||e.multiple),{options:[],...s};case"tokenselect":return{value:[],options:{},...s};case"number":case"rangeslider":return{...s,...s.type===e.type&&{size:e?.size,placeholder:e?.placeholder,min:e?.min,max:e?.max,step:e?.step}};case"measure":return{...s,units:{},...s.type===e.type&&{size:e?.size,placeholder:e?.placeholder,min:e?.min,max:e?.max,step:e?.step,units:e?.units??{}}};case"objectselect":case"postselect":case"taxonomyselect":case"userselect":return s.type="objectselect",s.multiple=e?.multiple??!1,s.placeholder=e?.placeholder??"","postselect"===e.type?{...s,entityKind:"postType",entityType:e?.post_type??"post"}:"taxonomyselect"===e.type?{...s,entityKind:"taxonomy",entityType:e?.taxonomy??"category"}:"userselect"===e.type?{...s,entityKind:"user",entityType:"user"}:{...s,entityKind:"postType",entityType:"post"};case"textarea":return{...s,...s.type===e.type&&{allowHtml:e?.allow_html}}}})(e):e,s.type){case"html":return{...s,content:s.content??""};case"checkbox":case"color":case"radio":case"rangeslider":case"number":default:case"email":case"tel":case"hidden":case"text":case"password":case"license_key":case"measure":case"textarea":return{...s};case"customselect":return{...s,entityType:s.entityType??"custom"};case"multicheck":case"select":return{...s,options:s.options??[]};case"multiselect":return{...s,options:s.options??[],multiple:!0};case"objectselect":case"postselect":case"taxonomyselect":case"userselect":return{...s,entityKind:s.entityKind??""};case"tokenselect":return{...s,value:s.value??[],options:s.options??[]}}},v=e=>{const{type:s}=e;switch(s){case"checkbox":return(0,t.jsx)(o,{...e});case"color":return(0,t.jsx)(r,{...e});case"customselect":return(0,t.jsx)(d,{...e});case"date":return(0,t.jsx)(m,{...e});case"measure":return(0,t.jsx)(C,{...e});case"multicheck":return(0,t.jsx)(w,{...e});case"select":case"multiselect":return(0,t.jsx)(H,{...e});case"objectselect":case"postselect":case"taxonomyselect":case"userselect":return(0,t.jsx)(T,{...e});case"radio":return(0,t.jsx)(M,{...e});case"rangeslider":return(0,t.jsx)(N,{...e});case"number":return(0,t.jsx)(S,{...e});case"email":case"tel":case"hidden":case"text":case"password":return(0,t.jsx)(I,{...e});case"textarea":return(0,t.jsx)(E,{...e});case"tokenselect":return(0,t.jsx)(P,{...e});case"html":return(0,t.jsx)(_,{...e})}return(0,t.jsx)(t.Fragment,{children:(0,i.sprintf)(/* translators: 1. type of field not found. */ /* translators: 1. type of field not found. */
(0,i.__)("Field type `%s` not found","popup-maker"),s)})},j=e=>{const{type:s,className:n,onChange:o}=e;return(0,t.jsx)("div",{className:y()(["pum-field",`pum-field--${s}`,n]),children:(0,t.jsx)(v,{onChange:o,...f(e)})})},b=e=>{const{fields:s}=e;return(0,t.jsx)(t.Fragment,{children:s.map((e,s)=>(0,t.jsx)(j,{...e},s))})},_=({content:e})=>(0,t.jsx)("div",{dangerouslySetInnerHTML:{__html:e??""}}),C=({value:s,onChange:n,units:o,...r})=>{const i=s?parseInt(s):"",[l,c]=(0,a.useState)({number:i,unit:s?.replace(`${i}`,"")??""});(0,a.useEffect)(()=>{n(`${l.number}${l.unit}`)},[l,n]);const p=Object.entries(o).map(([e,t])=>({value:e,label:t}));return(0,t.jsx)(e.__experimentalUnitControl,{...r,value:s,onChange:(e="0")=>c({...l,number:e}),disableUnits:0===p.length,units:p,onUnitChange:(e="")=>c({...l,unit:e}),__nextHasNoMarginBottom:!0})},w=({value:s,onChange:n,...o})=>{const r=s??[],a=h(o.options),i=s??[],l=()=>(0,t.jsx)(t.Fragment,{children:a.map(({label:s,value:o})=>{const a=r.indexOf(o)>=0;return(0,t.jsx)(e.CheckboxControl,{label:s,checked:a,onChange:()=>n(a?i.filter(e=>o!==e):[...i,o]),__nextHasNoMarginBottom:!0},o)})});return(0,t.jsx)(l,{})},S=({value:s,onChange:n,...o})=>(0,t.jsx)(e.__experimentalNumberControl,{...o,value:s,onChange:(e="0")=>n(parseInt(e,10)),__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),k=window.wp.data,F=window.wp.coreData,T=({label:e,value:s,onChange:n,entityKind:o="postType",entityType:r="post",multiple:d=!1})=>{const[m,g]=(0,a.useState)(""),[y,x]=(0,a.useState)(!1),[h,f]=(0,a.useState)({prefill:[],suggestions:[]}),v=(0,l.useDebounce)(e=>{g(e)},300),j=(0,k.useSelect)(e=>{if(y)return h.prefill;if(!s)return[];const t=e(F.store).getEntityRecords(o,r,{context:"view",include:s,per_page:-1});return null!==t||y||"postType"!==o||x(!0),t||[]},[s,o,r,y,h.prefill]),b=(0,k.useSelect)(e=>{if(y)return h.suggestions;if("user"===o)return e(F.store).getUsers({context:"view",search:m,per_page:-1});const t=e(F.store).getEntityRecords(o,r,{context:"view",search:m,per_page:-1});return null!==t||y||"postType"!==o||x(!0),t},[m,o,r,y,h.suggestions]),_=(0,k.useSelect)(e=>!y&&("user"===o?e("core/data").isResolving("core","getUsers",[o,r,{context:"view",search:m,per_page:-1}]):e("core/data").isResolving("core","getEntityRecords",[o,r,{context:"view",search:m,per_page:-1}])),[m,o,r,y,h.suggestions]);(0,a.useEffect)(()=>{y&&(async()=>{try{let e=`popup-maker/v2/object-search?object_type=post_type&object_key=${r}`;s&&(e+=`&include=${(Array.isArray(s)?s:[s]).join(",")}`),m&&(e+=`&s=${m}`);const t=await(0,u.fetchFromWPApi)(e),n=t.items.map(e=>({id:e.id,title:{rendered:e.text}}));let o=[];if(s){const e=Array.isArray(s)?s:[s];o=n.filter(t=>e.includes(t.id))}f({prefill:o,suggestions:n})}catch(e){f({prefill:[],suggestions:[]})}})()},[y,s,m,r]);const C=e=>{const t=t=>t?t.find(t=>t.id.toString()===e.toString()):null;return t(b)||t(j)},w=s?"number"==typeof s||"string"==typeof s?[s]:s:[],S=e=>"object"==typeof e?e.value:e;return(0,t.jsx)("div",{className:"pum-object-search-field",children:(0,t.jsx)(p.SmartTokenControl,{label:e||(0,i.sprintf)(
// translators: %s: entity type.
// translators: %s: entity type.
(0,i.__)("%s(s)","popup-maker"),r.replace(/_/g," ").charAt(0).toUpperCase()+r.replace(/_/g," ").slice(1)),hideLabelFromVision:!0,multiple:d,placeholder:(0,i.sprintf)(
// translators: %s: entity type.
// translators: %s: entity type.
(0,i.__)("Select %s(s)","popup-maker"),r.replace(/_/g," ").toLowerCase()),tokenOnComma:!0,value:w.map(e=>e.toString()),onInputChange:v,onChange:e=>{n(e.map(e=>parseInt(S(e),10)).filter(e=>!isNaN(e)))},renderToken:e=>{const t=C(S(e));return t?"postType"===o?(0,c.decodeEntities)(t.title?.rendered||""):t.name||"":S(e)},renderSuggestion:e=>{const s=C(e);return s?(0,t.jsx)(t.Fragment,{children:"postType"===o?(0,c.decodeEntities)((s.title?.rendered??s.title?.raw)||""):s.name||""}):e},suggestions:b?b.map(e=>e?.id.toString()??!1):[],messages:_?{noSuggestions:(0,i.__)("Searching…","popup-maker")}:void 0})})},M=({value:s,onChange:n,...o})=>{const r=o.options;return(0,t.jsx)(e.RadioControl,{...o,selected:s?.toString(),options:r,onChange:n,__nextHasNoMarginBottom:!0})},N=({value:s,onChange:n,initialPosition:o=0,...r})=>{const{step:a}=r;return(0,t.jsx)(e.RangeControl,{value:s??o,onChange:(e=0)=>n(e),withInputField:!0,__nextHasNoMarginBottom:!0,type:a?"stepper":void 0})},A=e=>Object.entries(e).reduce((e,[t,s])=>!0===e?e:"string"==typeof t&&!(parseInt(t)>=0)&&"object"==typeof s,!1),O=({options:e})=>(0,t.jsx)(t.Fragment,{children:h(e).map(({label:e,value:s})=>(0,t.jsx)("option",{value:s,children:e},s))}),$=({optGroups:e})=>(0,t.jsx)(t.Fragment,{children:Object.entries(e).map(([e,s])=>(0,t.jsx)("optgroup",{label:e,children:(0,t.jsx)(O,{options:s})},e))}),H=({value:s,onChange:n,...o})=>{const{multiple:r=!1}=o,a=o.options??{};return(0,t.jsx)(e.SelectControl,{...o,multiple:r,value:r&&"string"==typeof s?s.split(","):s,onChange:n,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,children:A(a)?(0,t.jsx)($,{optGroups:a}):(0,t.jsx)(O,{options:a})})},E=({value:s,onChange:n,rows:o=5,...r})=>(0,t.jsx)(e.TextareaControl,{...r,value:s??"",onChange:n,rows:o,__nextHasNoMarginBottom:!0}),I=({type:s,value:n,onChange:o,...r})=>(0,t.jsx)(e.TextControl,{...r,type:"hidden"!==s?s:void 0,value:n??"",onChange:o,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),P=({label:e,value:s,onChange:n,multiple:o=!1,placeholder:r=(0,i.__)("Search","popup-maker"),options:l={}})=>{const[c,u]=(0,a.useState)(""),d=s?"number"==typeof s||"string"==typeof s?[s]:s:[],m=Object.keys(l).filter(e=>!c||"string"==typeof l[e]&&l[e].toLowerCase().includes(c.toLowerCase())),g=e=>{const t="object"==typeof e?e.value:e;return(l[t]??null)||t};return(0,t.jsx)("div",{className:"pum-token-select-field",children:(0,t.jsx)(p.SmartTokenControl,{label:e,hideLabelFromVision:!0,multiple:o,placeholder:r,value:d.map(e=>e.toString()),onInputChange:u,onChange:e=>n(e),renderToken:g,renderSuggestion:g,suggestions:m})})},V=window.wp.hooks,B=(0,a.createContext)({context:"",fields:[],values:{},setValues:()=>{}}),R=({context:e,fields:s,values:n,setValues:o,children:r})=>(0,t.jsx)(B.Provider,{value:{context:e,fields:s,values:n,setValues:o},children:r}),z=()=>{const{context:e,fields:t=[],values:s,setValues:n}=(0,a.useContext)(B),o=t=>{const n=(0,V.applyFilters)(`${e}.fieldIsVisible`,void 0,t,s);return void 0===n||n};return{context:e,fields:t,values:s,setValues:n,getFields:(s={visible:!0})=>{const n=(t??[]).filter(e=>!(s?.tab&&e.tab!==s.tab||s?.section&&e.section!==s.section||s?.panel&&e.panel!==s.panel||s?.visible&&!o(e.id))).sort((e,t)=>e.priority-t.priority).map(t=>{const s=(0,V.applyFilters)(`${e}.renderField`,t.component,t.id,t);return{...t,component:s}});return(0,V.applyFilters)(`${e}.getFields`,n,s)},updateField:(e,t)=>{n({...s,[e]:t})},fieldIsVisible:o}}})(),(window.popupMaker=window.popupMaker||{}).fields=n})();