| Server IP : www.new.bangkokfinder.com / Your IP : 162.158.106.112 Web Server : nginx/1.20.1 System : Linux new 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64 User : bangkokfinder ( 1000) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/bangkokfinder/www/wp-content/plugins/generateblocks-pro/dist/ |
Upload File : |
(()=>{var e={2694:(e,t,n)=>{"use strict";var r=n(6925);function s(){}function o(){}o.resetWarningCache=s,e.exports=function(){function e(e,t,n,s,o,a){if(a!==r){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:s};return n.PropTypes=n,n}},5556:(e,t,n)=>{e.exports=n(2694)()},6925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},21020:(e,t,n)=>{"use strict";var r=n(51609),s=Symbol.for("react.element"),o=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};t.jsx=function(e,t,n){var r,c={},l=null,u=null;for(r in void 0!==n&&(l=""+n),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,r)&&!i.hasOwnProperty(r)&&(c[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===c[r]&&(c[r]=t[r]);return{$$typeof:s,type:e,key:l,ref:u,props:c,_owner:a.current}}},22799:(e,t)=>{"use strict";Symbol.for("react.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.provider"),Symbol.for("react.context"),Symbol.for("react.server_context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.suspense_list"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.offscreen");Symbol.for("react.module.reference")},44363:(e,t,n)=>{"use strict";n(22799)},51609:e=>{"use strict";e.exports=window.React},74848:(e,t,n)=>{"use strict";e.exports=n(21020)}},t={};function n(r){var s=t[r];if(void 0!==s)return s.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=n(51609),t=n.n(e);const r=window.wp.element,s=window.wp.components,o=window.wp.i18n;var a=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},i="undefined"==typeof window||"Deno"in globalThis;function c(){}function l(e){return"number"==typeof e&&e>=0&&e!==1/0}function u(e,t){return Math.max(e+(t||0)-Date.now(),0)}function d(e,t){return"function"==typeof e?e(t):e}function p(e,t){return"function"==typeof e?e(t):e}function h(e,t){const{type:n="all",exact:r,fetchStatus:s,predicate:o,queryKey:a,stale:i}=e;if(a)if(r){if(t.queryHash!==m(a,t.options))return!1}else if(!b(t.queryKey,a))return!1;if("all"!==n){const e=t.isActive();if("active"===n&&!e)return!1;if("inactive"===n&&e)return!1}return!("boolean"==typeof i&&t.isStale()!==i||s&&s!==t.state.fetchStatus||o&&!o(t))}function g(e,t){const{exact:n,status:r,predicate:s,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(n){if(f(t.options.mutationKey)!==f(o))return!1}else if(!b(t.options.mutationKey,o))return!1}return!(r&&t.state.status!==r||s&&!s(t))}function m(e,t){return(t?.queryKeyHashFn||f)(e)}function f(e){return JSON.stringify(e,((e,t)=>w(t)?Object.keys(t).sort().reduce(((e,n)=>(e[n]=t[n],e)),{}):t))}function b(e,t){return e===t||typeof e==typeof t&&!(!e||!t||"object"!=typeof e||"object"!=typeof t)&&Object.keys(t).every((n=>b(e[n],t[n])))}function y(e,t){if(e===t)return e;const n=_(e)&&_(t);if(n||w(e)&&w(t)){const r=n?e:Object.keys(e),s=r.length,o=n?t:Object.keys(t),a=o.length,i=n?[]:{};let c=0;for(let s=0;s<a;s++){const a=n?s:o[s];(!n&&r.includes(a)||n)&&void 0===e[a]&&void 0===t[a]?(i[a]=void 0,c++):(i[a]=y(e[a],t[a]),i[a]===e[a]&&void 0!==e[a]&&c++)}return s===a&&c===s?e:i}return t}function v(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function _(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function w(e){if(!E(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!!E(n)&&!!n.hasOwnProperty("isPrototypeOf")&&Object.getPrototypeOf(e)===Object.prototype}function E(e){return"[object Object]"===Object.prototype.toString.call(e)}function k(e,t,n){return"function"==typeof n.structuralSharing?n.structuralSharing(e,t):!1!==n.structuralSharing?y(e,t):t}function C(e,t,n=0){const r=[...e,t];return n&&r.length>n?r.slice(1):r}function S(e,t,n=0){const r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var I=Symbol();function x(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:e.queryFn&&e.queryFn!==I?e.queryFn:()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`))}function O(e,t){return"function"==typeof e?e(...t):!!e}var N=new class extends a{#e;#t;#n;constructor(){super(),this.#n=e=>{if(!i&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e((e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()}))}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){const e=this.isFocused();this.listeners.forEach((t=>{t(e)}))}isFocused(){return"boolean"==typeof this.#e?this.#e:"hidden"!==globalThis.document?.visibilityState}},R=e=>setTimeout(e,0),T=function(){let e=[],t=0,n=e=>{e()},r=e=>{e()},s=R;const o=r=>{t?e.push(r):s((()=>{n(r)}))};return{batch:o=>{let a;t++;try{a=o()}finally{t--,t||(()=>{const t=e;e=[],t.length&&s((()=>{r((()=>{t.forEach((e=>{n(e)}))}))}))})()}return a},batchCalls:e=>(...t)=>{o((()=>{e(...t)}))},schedule:o,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{s=e}}}(),D=new class extends a{#r=!0;#t;#n;constructor(){super(),this.#n=e=>{if(!i&&window.addEventListener){const t=()=>e(!0),n=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#r!==e&&(this.#r=e,this.listeners.forEach((t=>{t(e)})))}isOnline(){return this.#r}};function P(){let e,t;const n=new Promise(((n,r)=>{e=n,t=r}));function r(e){Object.assign(n,e),delete n.resolve,delete n.reject}return n.status="pending",n.catch((()=>{})),n.resolve=t=>{r({status:"fulfilled",value:t}),e(t)},n.reject=e=>{r({status:"rejected",reason:e}),t(e)},n}function M(e){return Math.min(1e3*2**e,3e4)}function A(e){return"online"!==(e??"online")||D.isOnline()}var F=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function $(e){return e instanceof F}function q(e){let t,n=!1,r=0,s=!1;const o=P(),a=()=>N.isFocused()&&("always"===e.networkMode||D.isOnline())&&e.canRun(),c=()=>A(e.networkMode)&&e.canRun(),l=n=>{s||(s=!0,e.onSuccess?.(n),t?.(),o.resolve(n))},u=n=>{s||(s=!0,e.onError?.(n),t?.(),o.reject(n))},d=()=>new Promise((n=>{t=e=>{(s||a())&&n(e)},e.onPause?.()})).then((()=>{t=void 0,s||e.onContinue?.()})),p=()=>{if(s)return;let t;const o=0===r?e.initialPromise:void 0;try{t=o??e.fn()}catch(e){t=Promise.reject(e)}Promise.resolve(t).then(l).catch((t=>{if(s)return;const o=e.retry??(i?0:3),c=e.retryDelay??M,l="function"==typeof c?c(r,t):c,h=!0===o||"number"==typeof o&&r<o||"function"==typeof o&&o(r,t);var g;!n&&h?(r++,e.onFail?.(r,t),(g=l,new Promise((e=>{setTimeout(e,g)}))).then((()=>a()?void 0:d())).then((()=>{n?u(t):p()}))):u(t)}))};return{promise:o,cancel:t=>{s||(u(new F(t)),e.abort?.())},continue:()=>(t?.(),o),cancelRetry:()=>{n=!0},continueRetry:()=>{n=!1},canStart:c,start:()=>(c()?p():d().then(p),o)}}var B=class{#s;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),l(this.gcTime)&&(this.#s=setTimeout((()=>{this.optionalRemove()}),this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(i?1/0:3e5))}clearGcTimeout(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}},L=class extends B{#o;#a;#i;#c;#l;#u;#d;constructor(e){super(),this.#d=!1,this.#u=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#c=e.client,this.#i=this.#c.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#o=function(e){const t="function"==typeof e.initialData?e.initialData():e.initialData,n=void 0!==t,r=n?"function"==typeof e.initialDataUpdatedAt?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}(this.options),this.state=e.state??this.#o,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#l?.promise}setOptions(e){this.options={...this.#u,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){this.observers.length||"idle"!==this.state.fetchStatus||this.#i.remove(this)}setData(e,t){const n=k(this.state.data,e,this.options);return this.#p({data:n,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e,t){this.#p({type:"setState",state:e,setStateOptions:t})}cancel(e){const t=this.#l?.promise;return this.#l?.cancel(e),t?t.then(c).catch(c):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#o)}isActive(){return this.observers.some((e=>!1!==p(e.options.enabled,this)))}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===I||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStale(){return!!this.state.isInvalidated||(this.getObserversCount()>0?this.observers.some((e=>e.getCurrentResult().isStale)):void 0===this.state.data)}isStaleByTime(e=0){return this.state.isInvalidated||void 0===this.state.data||!u(this.state.dataUpdatedAt,e)}onFocus(){const e=this.observers.find((e=>e.shouldFetchOnWindowFocus()));e?.refetch({cancelRefetch:!1}),this.#l?.continue()}onOnline(){const e=this.observers.find((e=>e.shouldFetchOnReconnect()));e?.refetch({cancelRefetch:!1}),this.#l?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#i.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter((t=>t!==e)),this.observers.length||(this.#l&&(this.#d?this.#l.cancel({revert:!0}):this.#l.cancelRetry()),this.scheduleGc()),this.#i.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#p({type:"invalidate"})}fetch(e,t){if("idle"!==this.state.fetchStatus)if(void 0!==this.state.data&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#l)return this.#l.continueRetry(),this.#l.promise;if(e&&this.setOptions(e),!this.options.queryFn){const e=this.observers.find((e=>e.options.queryFn));e&&this.setOptions(e.options)}const n=new AbortController,r=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#d=!0,n.signal)})},s={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#c,state:this.state,fetchFn:()=>{const e=x(this.options,t),n={client:this.#c,queryKey:this.queryKey,meta:this.meta};return r(n),this.#d=!1,this.options.persister?this.options.persister(e,n,this):e(n)}};r(s),this.options.behavior?.onFetch(s,this),this.#a=this.state,"idle"!==this.state.fetchStatus&&this.state.fetchMeta===s.fetchOptions?.meta||this.#p({type:"fetch",meta:s.fetchOptions?.meta});const o=e=>{$(e)&&e.silent||this.#p({type:"error",error:e}),$(e)||(this.#i.config.onError?.(e,this),this.#i.config.onSettled?.(this.state.data,e,this)),this.scheduleGc()};return this.#l=q({initialPromise:t?.initialPromise,fn:s.fetchFn,abort:n.abort.bind(n),onSuccess:e=>{if(void 0!==e){try{this.setData(e)}catch(e){return void o(e)}this.#i.config.onSuccess?.(e,this),this.#i.config.onSettled?.(e,this.state.error,this),this.scheduleGc()}else o(new Error(`${this.queryHash} data is undefined`))},onError:o,onFail:(e,t)=>{this.#p({type:"failed",failureCount:e,error:t})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:s.options.retry,retryDelay:s.options.retryDelay,networkMode:s.options.networkMode,canRun:()=>!0}),this.#l.start()}#p(e){this.state=(t=>{switch(e.type){case"failed":return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...t,fetchStatus:"paused"};case"continue":return{...t,fetchStatus:"fetching"};case"fetch":return{...t,...V(t.data,this.options),fetchMeta:e.meta??null};case"success":return{...t,data:e.data,dataUpdateCount:t.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const n=e.error;return $(n)&&n.revert&&this.#a?{...this.#a,fetchStatus:"idle"}:{...t,error:n,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error"};case"invalidate":return{...t,isInvalidated:!0};case"setState":return{...t,...e.state}}})(this.state),T.batch((()=>{this.observers.forEach((e=>{e.onQueryUpdate()})),this.#i.notify({query:this,type:"updated",action:e})}))}};function V(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:A(t.networkMode)?"fetching":"paused",...void 0===e&&{error:null,status:"pending"}}}var Q=class extends a{constructor(e,t){super(),this.options=t,this.#c=e,this.#h=null,this.#g=P(),this.options.experimental_prefetchInRender||this.#g.reject(new Error("experimental_prefetchInRender feature flag is not enabled")),this.bindMethods(),this.setOptions(t)}#c;#m=void 0;#f=void 0;#b=void 0;#y;#v;#g;#h;#_;#w;#E;#k;#C;#S;#I=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#m.addObserver(this),j(this.#m,this.options)?this.#x():this.updateResult(),this.#O())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return z(this.#m,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return z(this.#m,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#N(),this.#R(),this.#m.removeObserver(this)}setOptions(e){const t=this.options,n=this.#m;if(this.options=this.#c.defaultQueryOptions(e),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled&&"function"!=typeof this.options.enabled&&"boolean"!=typeof p(this.options.enabled,this.#m))throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#T(),this.#m.setOptions(this.options),t._defaulted&&!v(this.options,t)&&this.#c.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#m,observer:this});const r=this.hasListeners();r&&H(this.#m,n,this.options,t)&&this.#x(),this.updateResult(),!r||this.#m===n&&p(this.options.enabled,this.#m)===p(t.enabled,this.#m)&&d(this.options.staleTime,this.#m)===d(t.staleTime,this.#m)||this.#D();const s=this.#P();!r||this.#m===n&&p(this.options.enabled,this.#m)===p(t.enabled,this.#m)&&s===this.#S||this.#M(s)}getOptimisticResult(e){const t=this.#c.getQueryCache().build(this.#c,e),n=this.createResult(t,e);return r=n,!v(this.getCurrentResult(),r)&&(this.#b=n,this.#v=this.options,this.#y=this.#m.state),n;var r}getCurrentResult(){return this.#b}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#I.add(e)}getCurrentQuery(){return this.#m}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){const t=this.#c.defaultQueryOptions(e),n=this.#c.getQueryCache().build(this.#c,t);return n.fetch().then((()=>this.createResult(n,t)))}fetch(e){return this.#x({...e,cancelRefetch:e.cancelRefetch??!0}).then((()=>(this.updateResult(),this.#b)))}#x(e){this.#T();let t=this.#m.fetch(this.options,e);return e?.throwOnError||(t=t.catch(c)),t}#D(){this.#N();const e=d(this.options.staleTime,this.#m);if(i||this.#b.isStale||!l(e))return;const t=u(this.#b.dataUpdatedAt,e)+1;this.#k=setTimeout((()=>{this.#b.isStale||this.updateResult()}),t)}#P(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#m):this.options.refetchInterval)??!1}#M(e){this.#R(),this.#S=e,!i&&!1!==p(this.options.enabled,this.#m)&&l(this.#S)&&0!==this.#S&&(this.#C=setInterval((()=>{(this.options.refetchIntervalInBackground||N.isFocused())&&this.#x()}),this.#S))}#O(){this.#D(),this.#M(this.#P())}#N(){this.#k&&(clearTimeout(this.#k),this.#k=void 0)}#R(){this.#C&&(clearInterval(this.#C),this.#C=void 0)}createResult(e,t){const n=this.#m,r=this.options,s=this.#b,o=this.#y,a=this.#v,i=e!==n?e.state:this.#f,{state:c}=e;let l,u={...c},d=!1;if(t._optimisticResults){const s=this.hasListeners(),o=!s&&j(e,t),a=s&&H(e,n,t,r);(o||a)&&(u={...u,...V(c.data,e.options)}),"isRestoring"===t._optimisticResults&&(u.fetchStatus="idle")}let{error:p,errorUpdatedAt:h,status:g}=u;l=u.data;let m=!1;if(void 0!==t.placeholderData&&void 0===l&&"pending"===g){let e;s?.isPlaceholderData&&t.placeholderData===a?.placeholderData?(e=s.data,m=!0):e="function"==typeof t.placeholderData?t.placeholderData(this.#E?.state.data,this.#E):t.placeholderData,void 0!==e&&(g="success",l=k(s?.data,e,t),d=!0)}if(t.select&&void 0!==l&&!m)if(s&&l===o?.data&&t.select===this.#_)l=this.#w;else try{this.#_=t.select,l=t.select(l),l=k(s?.data,l,t),this.#w=l,this.#h=null}catch(e){this.#h=e}this.#h&&(p=this.#h,l=this.#w,h=Date.now(),g="error");const f="fetching"===u.fetchStatus,b="pending"===g,y="error"===g,v=b&&f,_=void 0!==l,w={status:g,fetchStatus:u.fetchStatus,isPending:b,isSuccess:"success"===g,isError:y,isInitialLoading:v,isLoading:v,data:l,dataUpdatedAt:u.dataUpdatedAt,error:p,errorUpdatedAt:h,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>i.dataUpdateCount||u.errorUpdateCount>i.errorUpdateCount,isFetching:f,isRefetching:f&&!b,isLoadingError:y&&!_,isPaused:"paused"===u.fetchStatus,isPlaceholderData:d,isRefetchError:y&&_,isStale:K(e,t),refetch:this.refetch,promise:this.#g};if(this.options.experimental_prefetchInRender){const t=e=>{"error"===w.status?e.reject(w.error):void 0!==w.data&&e.resolve(w.data)},r=()=>{const e=this.#g=w.promise=P();t(e)},s=this.#g;switch(s.status){case"pending":e.queryHash===n.queryHash&&t(s);break;case"fulfilled":"error"!==w.status&&w.data===s.value||r();break;case"rejected":"error"===w.status&&w.error===s.reason||r()}}return w}updateResult(){const e=this.#b,t=this.createResult(this.#m,this.options);this.#y=this.#m.state,this.#v=this.options,void 0!==this.#y.data&&(this.#E=this.#m),v(t,e)||(this.#b=t,this.#A({listeners:(()=>{if(!e)return!0;const{notifyOnChangeProps:t}=this.options,n="function"==typeof t?t():t;if("all"===n||!n&&!this.#I.size)return!0;const r=new Set(n??this.#I);return this.options.throwOnError&&r.add("error"),Object.keys(this.#b).some((t=>{const n=t;return this.#b[n]!==e[n]&&r.has(n)}))})()}))}#T(){const e=this.#c.getQueryCache().build(this.#c,this.options);if(e===this.#m)return;const t=this.#m;this.#m=e,this.#f=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#O()}#A(e){T.batch((()=>{e.listeners&&this.listeners.forEach((e=>{e(this.#b)})),this.#c.getQueryCache().notify({query:this.#m,type:"observerResultsUpdated"})}))}};function j(e,t){return function(e,t){return!1!==p(t.enabled,e)&&void 0===e.state.data&&!("error"===e.state.status&&!1===t.retryOnMount)}(e,t)||void 0!==e.state.data&&z(e,t,t.refetchOnMount)}function z(e,t,n){if(!1!==p(t.enabled,e)){const r="function"==typeof n?n(e):n;return"always"===r||!1!==r&&K(e,t)}return!1}function H(e,t,n,r){return(e!==t||!1===p(r.enabled,e))&&(!n.suspense||"error"!==e.state.status)&&K(e,n)}function K(e,t){return!1!==p(t.enabled,e)&&e.isStaleByTime(d(t.staleTime,e))}var U=n(74848),W=e.createContext(void 0),G=t=>{const n=e.useContext(W);if(t)return t;if(!n)throw new Error("No QueryClient set, use QueryClientProvider to set one");return n},Y=({client:t,children:n})=>(e.useEffect((()=>(t.mount(),()=>{t.unmount()})),[t]),(0,U.jsx)(W.Provider,{value:t,children:n}));var J=e.createContext(function(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}()),Z=e.createContext(!1),X=(Z.Provider,(e,t,n)=>t.fetchOptimistic(e).catch((()=>{n.clearReset()})));function ee(t,n){return function(t,n,r){const s=G(r),o=e.useContext(Z),a=e.useContext(J),l=s.defaultQueryOptions(t);s.getDefaultOptions().queries?._experimental_beforeQuery?.(l),l._optimisticResults=o?"isRestoring":"optimistic",(e=>{const t=e.staleTime;e.suspense&&(e.staleTime="function"==typeof t?(...e)=>Math.max(t(...e),1e3):Math.max(t??1e3,1e3),"number"==typeof e.gcTime&&(e.gcTime=Math.max(e.gcTime,1e3)))})(l),((e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))})(l,a),(t=>{e.useEffect((()=>{t.clearReset()}),[t])})(a);const u=!s.getQueryCache().get(l.queryHash),[d]=e.useState((()=>new n(s,l))),p=d.getOptimisticResult(l),h=!o&&!1!==t.subscribed;if(e.useSyncExternalStore(e.useCallback((e=>{const t=h?d.subscribe(T.batchCalls(e)):c;return d.updateResult(),t}),[d,h]),(()=>d.getCurrentResult()),(()=>d.getCurrentResult())),e.useEffect((()=>{d.setOptions(l)}),[l,d]),((e,t)=>e?.suspense&&t.isPending)(l,p))throw X(l,d,a);if((({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:s})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(s&&void 0===e.data||O(n,[e.error,r])))({result:p,errorResetBoundary:a,throwOnError:l.throwOnError,query:s.getQueryCache().get(l.queryHash),suspense:l.suspense}))throw p.error;if(s.getDefaultOptions().queries?._experimental_afterQuery?.(l,p),l.experimental_prefetchInRender&&!i&&((e,t)=>e.isLoading&&e.isFetching&&!t)(p,o)){const e=u?X(l,d,a):s.getQueryCache().get(l.queryHash)?.promise;e?.catch(c).finally((()=>{d.updateResult()}))}return l.notifyOnChangeProps?p:d.trackResult(p)}(t,Q,n)}var te=class extends B{#F;#$;#l;constructor(e){super(),this.mutationId=e.mutationId,this.#$=e.mutationCache,this.#F=[],this.state=e.state||{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0},this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#F.includes(e)||(this.#F.push(e),this.clearGcTimeout(),this.#$.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#F=this.#F.filter((t=>t!==e)),this.scheduleGc(),this.#$.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#F.length||("pending"===this.state.status?this.scheduleGc():this.#$.remove(this))}continue(){return this.#l?.continue()??this.execute(this.state.variables)}async execute(e){const t=()=>{this.#p({type:"continue"})};this.#l=q({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(e,t)=>{this.#p({type:"failed",failureCount:e,error:t})},onPause:()=>{this.#p({type:"pause"})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#$.canRun(this)});const n="pending"===this.state.status,r=!this.#l.canStart();try{if(n)t();else{this.#p({type:"pending",variables:e,isPaused:r}),await(this.#$.config.onMutate?.(e,this));const t=await(this.options.onMutate?.(e));t!==this.state.context&&this.#p({type:"pending",context:t,variables:e,isPaused:r})}const s=await this.#l.start();return await(this.#$.config.onSuccess?.(s,e,this.state.context,this)),await(this.options.onSuccess?.(s,e,this.state.context)),await(this.#$.config.onSettled?.(s,null,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(s,null,e,this.state.context)),this.#p({type:"success",data:s}),s}catch(t){try{throw await(this.#$.config.onError?.(t,e,this.state.context,this)),await(this.options.onError?.(t,e,this.state.context)),await(this.#$.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(void 0,t,e,this.state.context)),t}finally{this.#p({type:"error",error:t})}}finally{this.#$.runNext(this)}}#p(e){this.state=(t=>{switch(e.type){case"failed":return{...t,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...t,isPaused:!0};case"continue":return{...t,isPaused:!1};case"pending":return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}})(this.state),T.batch((()=>{this.#F.forEach((t=>{t.onMutationUpdate(e)})),this.#$.notify({mutation:this,type:"updated",action:e})}))}},ne=class extends a{#c;#b=void 0;#q;#B;constructor(e,t){super(),this.#c=e,this.setOptions(t),this.bindMethods(),this.#L()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){const t=this.options;this.options=this.#c.defaultMutationOptions(e),v(this.options,t)||this.#c.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#q,observer:this}),t?.mutationKey&&this.options.mutationKey&&f(t.mutationKey)!==f(this.options.mutationKey)?this.reset():"pending"===this.#q?.state.status&&this.#q.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#q?.removeObserver(this)}onMutationUpdate(e){this.#L(),this.#A(e)}getCurrentResult(){return this.#b}reset(){this.#q?.removeObserver(this),this.#q=void 0,this.#L(),this.#A()}mutate(e,t){return this.#B=t,this.#q?.removeObserver(this),this.#q=this.#c.getMutationCache().build(this.#c,this.options),this.#q.addObserver(this),this.#q.execute(e)}#L(){const e=this.#q?.state??{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0};this.#b={...e,isPending:"pending"===e.status,isSuccess:"success"===e.status,isError:"error"===e.status,isIdle:"idle"===e.status,mutate:this.mutate,reset:this.reset}}#A(e){T.batch((()=>{if(this.#B&&this.hasListeners()){const t=this.#b.variables,n=this.#b.context;"success"===e?.type?(this.#B.onSuccess?.(e.data,t,n),this.#B.onSettled?.(e.data,null,t,n)):"error"===e?.type&&(this.#B.onError?.(e.error,t,n),this.#B.onSettled?.(void 0,e.error,t,n))}this.listeners.forEach((e=>{e(this.#b)}))}))}};function re(t,n){const r=G(n),[s]=e.useState((()=>new ne(r,t)));e.useEffect((()=>{s.setOptions(t)}),[s,t]);const o=e.useSyncExternalStore(e.useCallback((e=>s.subscribe(T.batchCalls(e))),[s]),(()=>s.getCurrentResult()),(()=>s.getCurrentResult())),a=e.useCallback(((e,t)=>{s.mutate(e,t).catch(c)}),[s]);if(o.error&&O(s.options.throwOnError,[o.error]))throw o.error;return{...o,mutate:a,mutateAsync:o.mutate}}const se=window.wp.apiFetch;var oe=n.n(se),ae=class extends a{constructor(e={}){super(),this.config=e,this.#V=new Map}#V;build(e,t,n){const r=t.queryKey,s=t.queryHash??m(r,t);let o=this.get(s);return o||(o=new L({client:e,queryKey:r,queryHash:s,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(o)),o}add(e){this.#V.has(e.queryHash)||(this.#V.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const t=this.#V.get(e.queryHash);t&&(e.destroy(),t===e&&this.#V.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){T.batch((()=>{this.getAll().forEach((e=>{this.remove(e)}))}))}get(e){return this.#V.get(e)}getAll(){return[...this.#V.values()]}find(e){const t={exact:!0,...e};return this.getAll().find((e=>h(t,e)))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter((t=>h(e,t))):t}notify(e){T.batch((()=>{this.listeners.forEach((t=>{t(e)}))}))}onFocus(){T.batch((()=>{this.getAll().forEach((e=>{e.onFocus()}))}))}onOnline(){T.batch((()=>{this.getAll().forEach((e=>{e.onOnline()}))}))}},ie=class extends a{constructor(e={}){super(),this.config=e,this.#Q=new Set,this.#j=new Map,this.#z=0}#Q;#j;#z;build(e,t,n){const r=new te({mutationCache:this,mutationId:++this.#z,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#Q.add(e);const t=ce(e);if("string"==typeof t){const n=this.#j.get(t);n?n.push(e):this.#j.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#Q.delete(e)){const t=ce(e);if("string"==typeof t){const n=this.#j.get(t);if(n)if(n.length>1){const t=n.indexOf(e);-1!==t&&n.splice(t,1)}else n[0]===e&&this.#j.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){const t=ce(e);if("string"==typeof t){const n=this.#j.get(t),r=n?.find((e=>"pending"===e.state.status));return!r||r===e}return!0}runNext(e){const t=ce(e);if("string"==typeof t){const n=this.#j.get(t)?.find((t=>t!==e&&t.state.isPaused));return n?.continue()??Promise.resolve()}return Promise.resolve()}clear(){T.batch((()=>{this.#Q.forEach((e=>{this.notify({type:"removed",mutation:e})})),this.#Q.clear(),this.#j.clear()}))}getAll(){return Array.from(this.#Q)}find(e){const t={exact:!0,...e};return this.getAll().find((e=>g(t,e)))}findAll(e={}){return this.getAll().filter((t=>g(e,t)))}notify(e){T.batch((()=>{this.listeners.forEach((t=>{t(e)}))}))}resumePausedMutations(){const e=this.getAll().filter((e=>e.state.isPaused));return T.batch((()=>Promise.all(e.map((e=>e.continue().catch(c))))))}};function ce(e){return e.options.scope?.id}function le(e){return{onFetch:(t,n)=>{const r=t.options,s=t.fetchOptions?.meta?.fetchMore?.direction,o=t.state.data?.pages||[],a=t.state.data?.pageParams||[];let i={pages:[],pageParams:[]},c=0;const l=async()=>{let n=!1;const l=x(t.options,t.fetchOptions),u=async(e,r,s)=>{if(n)return Promise.reject();if(null==r&&e.pages.length)return Promise.resolve(e);const o={client:t.client,queryKey:t.queryKey,pageParam:r,direction:s?"backward":"forward",meta:t.options.meta};var a;a=o,Object.defineProperty(a,"signal",{enumerable:!0,get:()=>(t.signal.aborted?n=!0:t.signal.addEventListener("abort",(()=>{n=!0})),t.signal)});const i=await l(o),{maxPages:c}=t.options,u=s?S:C;return{pages:u(e.pages,i,c),pageParams:u(e.pageParams,r,c)}};if(s&&o.length){const e="backward"===s,t={pages:o,pageParams:a},n=(e?de:ue)(r,t);i=await u(t,n,e)}else{const t=e??o.length;do{const e=0===c?a[0]??r.initialPageParam:ue(r,i);if(c>0&&null==e)break;i=await u(i,e),c++}while(c<t)}return i};t.options.persister?t.fetchFn=()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):t.fetchFn=l}}}function ue(e,{pages:t,pageParams:n}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function de(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var pe=class{#H;#$;#u;#K;#U;#W;#G;#Y;constructor(e={}){this.#H=e.queryCache||new ae,this.#$=e.mutationCache||new ie,this.#u=e.defaultOptions||{},this.#K=new Map,this.#U=new Map,this.#W=0}mount(){this.#W++,1===this.#W&&(this.#G=N.subscribe((async e=>{e&&(await this.resumePausedMutations(),this.#H.onFocus())})),this.#Y=D.subscribe((async e=>{e&&(await this.resumePausedMutations(),this.#H.onOnline())})))}unmount(){this.#W--,0===this.#W&&(this.#G?.(),this.#G=void 0,this.#Y?.(),this.#Y=void 0)}isFetching(e){return this.#H.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#$.findAll({...e,status:"pending"}).length}getQueryData(e){const t=this.defaultQueryOptions({queryKey:e});return this.#H.get(t.queryHash)?.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=this.#H.build(this,t),r=n.state.data;return void 0===r?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(d(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#H.findAll(e).map((({queryKey:e,state:t})=>[e,t.data]))}setQueryData(e,t,n){const r=this.defaultQueryOptions({queryKey:e}),s=this.#H.get(r.queryHash),o=s?.state.data,a=function(e,t){return"function"==typeof e?e(t):e}(t,o);if(void 0!==a)return this.#H.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return T.batch((()=>this.#H.findAll(e).map((({queryKey:e})=>[e,this.setQueryData(e,t,n)]))))}getQueryState(e){const t=this.defaultQueryOptions({queryKey:e});return this.#H.get(t.queryHash)?.state}removeQueries(e){const t=this.#H;T.batch((()=>{t.findAll(e).forEach((e=>{t.remove(e)}))}))}resetQueries(e,t){const n=this.#H;return T.batch((()=>(n.findAll(e).forEach((e=>{e.reset()})),this.refetchQueries({type:"active",...e},t))))}cancelQueries(e,t={}){const n={revert:!0,...t},r=T.batch((()=>this.#H.findAll(e).map((e=>e.cancel(n)))));return Promise.all(r).then(c).catch(c)}invalidateQueries(e,t={}){return T.batch((()=>(this.#H.findAll(e).forEach((e=>{e.invalidate()})),"none"===e?.refetchType?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??"active"},t))))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},r=T.batch((()=>this.#H.findAll(e).filter((e=>!e.isDisabled())).map((e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(c)),"paused"===e.state.fetchStatus?Promise.resolve():t}))));return Promise.all(r).then(c)}fetchQuery(e){const t=this.defaultQueryOptions(e);void 0===t.retry&&(t.retry=!1);const n=this.#H.build(this,t);return n.isStaleByTime(d(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(c).catch(c)}fetchInfiniteQuery(e){return e.behavior=le(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(c).catch(c)}ensureInfiniteQueryData(e){return e.behavior=le(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return D.isOnline()?this.#$.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#H}getMutationCache(){return this.#$}getDefaultOptions(){return this.#u}setDefaultOptions(e){this.#u=e}setQueryDefaults(e,t){this.#K.set(f(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#K.values()],n={};return t.forEach((t=>{b(e,t.queryKey)&&Object.assign(n,t.defaultOptions)})),n}setMutationDefaults(e,t){this.#U.set(f(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#U.values()],n={};return t.forEach((t=>{b(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)})),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...this.#u.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=m(t.queryKey,t)),void 0===t.refetchOnReconnect&&(t.refetchOnReconnect="always"!==t.networkMode),void 0===t.throwOnError&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===I&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#u.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#H.clear(),this.#$.clear()}};let he=null;function ge(){return he||(he=new pe({defaultOptions:{queries:{staleTime:3e5,cacheTime:6e5,retry:1,refetchOnWindowFocus:!0}}})),he}function me(){const e=ge();if(e.invalidateQueries({queryKey:["conditions"]}),e.invalidateQueries({queryKey:["condition"]}),window.dispatchEvent(new CustomEvent("gb-invalidate-conditions")),window.parent&&window.parent!==window)try{window.parent.postMessage({type:"gb_invalidate_conditions"},"*")}catch(e){}}function fe(){const e=ee({queryKey:["condition-metadata","types"],queryFn:async()=>{const e=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/get_condition_types"});if(e.success)return e.response;throw new Error("Failed to fetch condition types")},staleTime:6e5}),t=(0,r.useCallback)((async e=>{if(!e)return[];const t=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/get_condition_rules?type=${e}`});if(t.success)return t.response;throw new Error("Failed to fetch condition rules")}),[]),n=(0,r.useCallback)((async(e,t)=>{if(!e||!t)return[];const n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/get_condition_operators?type=${e}&rule=${t}`});if(n.success)return n.response;throw new Error("Failed to fetch condition operators")}),[]);return{conditionTypes:e.data||{},loading:e.isLoading,error:e.error,getRulesForType:t,getOperatorsForType:n}}"undefined"!=typeof window&&(window.addEventListener("gb-invalidate-conditions",(()=>{ge().invalidateQueries({queryKey:["conditions"]})})),window.addEventListener("message",(e=>{"gb_invalidate_conditions"===e.data?.type&&ge().invalidateQueries({queryKey:["conditions"]})})),window.addEventListener("gb-overlay-saved-global",(e=>{const t=ge();t.invalidateQueries({queryKey:["overlays"]}),e.detail?.overlayId&&t.invalidateQueries({queryKey:["overlay",e.detail.overlayId]})})));const be=window.wp.primitives,ye=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})),ve=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M14.5 13.8c-1.1 0-2.1.7-2.4 1.8H4V17h8.1c.3 1 1.3 1.8 2.4 1.8s2.1-.7 2.4-1.8H20v-1.5h-3.1c-.3-1-1.3-1.7-2.4-1.7zM11.9 7c-.3-1-1.3-1.8-2.4-1.8S7.4 6 7.1 7H4v1.5h3.1c.3 1 1.3 1.8 2.4 1.8s2.1-.7 2.4-1.8H20V7h-8.1z"})),_e=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"})),we=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M20.2 8v11c0 .7-.6 1.2-1.2 1.2H6v1.5h13c1.5 0 2.7-1.2 2.7-2.8V8zM18 16.4V4.6c0-.9-.7-1.6-1.6-1.6H4.6C3.7 3 3 3.7 3 4.6v11.8c0 .9.7 1.6 1.6 1.6h11.8c.9 0 1.6-.7 1.6-1.6zm-13.5 0V4.6c0-.1.1-.1.1-.1h11.8c.1 0 .1.1.1.1v11.8c0 .1-.1.1-.1.1H4.6l-.1-.1z"})),Ee=(0,r.createElement)(be.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(be.Path,{d:"M19 6.2h-5.9l-.6-1.1c-.3-.7-1-1.1-1.8-1.1H5c-1.1 0-2 .9-2 2v11.8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8.2c0-1.1-.9-2-2-2zm.5 11.6c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V6c0-.3.2-.5.5-.5h5.8c.2 0 .4.1.4.3l1 2H19c.3 0 .5.2.5.5v9.5zM8 12.8h8v-1.5H8v1.5zm0 3h8v-1.5H8v1.5z"})),ke=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),Ce=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M20 5h-5.7c0-1.3-1-2.3-2.3-2.3S9.7 3.7 9.7 5H4v2h1.5v.3l1.7 11.1c.1 1 1 1.7 2 1.7h5.7c1 0 1.8-.7 2-1.7l1.7-11.1V7H20V5zm-3.2 2l-1.7 11.1c0 .1-.1.2-.3.2H9.1c-.1 0-.3-.1-.3-.2L7.2 7h9.6z"})),Se=window.wp.htmlEntities,Ie=window.gbp.components;function xe({condition:t,onClose:n}){const{conditionTypes:a,getRulesForType:i,getOperatorsForType:c}=fe(),{loadObjectTitles:l}=function(){const e=ge();return{loadObjectTitles:(0,r.useCallback)((async t=>{if(!t||0===t.length)return{};const n=[],r={};if(t.forEach((t=>{const s=["object-title",t.type,t.id],o=e.getQueryData(s);o?r[`${t.type}-${t.id}`]=o:n.push(t)})),0===n.length)return r;const s=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/batch_object_titles",method:"POST",data:{requests:n}});return s.success&&s.response?(Object.entries(s.response).forEach((([t,n])=>{const[r,s]=t.split("-");e.setQueryData(["object-title",r,s],n)})),{...r,...s.response}):r}),[e])}}(),[u,d]=(0,r.useState)({}),[p,h]=(0,r.useState)({}),[g,m]=(0,r.useState)({}),[f,b]=(0,r.useState)(!0);(0,r.useEffect)((()=>{(async()=>{try{b(!0);const e=t.gbConditions||{groups:[]},n=new Set,r={},s={};e.groups?.forEach((e=>{e.conditions?.forEach((e=>{e.type&&n.add(e.type)}))}));for(const e of n)try{const t=await i(e);r[e]=t;const n=await c(e);s[e]=n}catch(t){console.error(`Error loading data for type ${e}:`,t)}h(r),m(s),await y(e)}catch(e){console.error("Error loading condition data:",e)}finally{b(!1)}})()}),[t,i,c,l]);const y=async e=>{const t=[];if(e.groups?.forEach((e=>{e.conditions?.forEach((e=>{if(!e.rule||!e.value)return;const n=v(e.value);0!==n.length&&(e.rule.startsWith("post:")||e.rule.startsWith("taxonomy:")||e.rule.startsWith("post_terms:")||"child_of"===e.rule||"parent_of"===e.rule||"date_time"===e.type&&"day_of_week"===e.rule)&&n.forEach((n=>{n&&t.push({type:e.type,rule:e.rule,value:n})}))}))})),t.length>0){const e=t.map((e=>{let t;return t=e.rule.startsWith("post:")?"post":e.rule.startsWith("taxonomy:")||e.rule.startsWith("post_terms:")?"term":"author_id"===e.rule?"user":e.type,{type:t,id:e.value}})),n=await l(e);d(n)}},v=e=>{if(!e)return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch(e){}return[e]},_=t.gbConditions||{groups:[]},w=_.groups&&0<_.groups.length;return(0,e.createElement)(s.Modal,{title:t.title?.rendered||t.title||(0,o.__)("Untitled Condition","generateblocks-pro"),onRequestClose:n,className:"gb-modal-condition-details",size:"medium"},(0,e.createElement)("div",{className:"gb-modal-details-content"},f?(0,e.createElement)("div",{className:"gb-modal-loading"},(0,e.createElement)(s.Spinner,null),(0,e.createElement)("p",null,(0,o.__)("Loading condition details…","generateblocks-pro"))):(0,e.createElement)("div",{className:"gb-modal-details-body"},w?(0,e.createElement)(e.Fragment,null,1<_.groups.length&&(0,e.createElement)("div",{className:"gb-modal-main-logic"},(0,e.createElement)("strong",null,(0,o.__)("Overall Logic:","generateblocks-pro"))," ","AND"===_.logic?(0,o.__)("ALL condition groups must match","generateblocks-pro"):(0,o.__)("ANY condition group can match","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-modal-condition-groups"},_.groups.map(((t,n)=>(0,e.createElement)("div",{key:n,className:"gb-modal-condition-group"},(0,e.createElement)("div",{className:"gb-modal-group-header"},(0,e.createElement)("h4",null,1<_.groups.length?`${(0,o.__)("Group","generateblocks-pro")} ${n+1}`:(0,o.__)("Conditions","generateblocks-pro")),1<t.conditions.length&&(0,e.createElement)("span",{className:"gb-modal-group-logic-badge"},"AND"===t.logic?(0,o.__)("ALL must match","generateblocks-pro"):(0,o.__)("ANY can match","generateblocks-pro"))),(0,e.createElement)("div",{className:"gb-modal-condition-list"},t.conditions.filter((e=>e.type&&e.rule&&e.operator)).map(((t,n)=>{return(0,e.createElement)("div",{key:n,className:"gb-modal-condition-item"},(0,e.createElement)("div",{className:"gb-modal-condition-summary"},(0,e.createElement)("span",{className:"gb-modal-condition-type-badge"},(i=t.type,a[i]?.label||i)),(0,e.createElement)("span",{className:"gb-modal-condition-rule-badge"},((e,t)=>p[e]?.[t]||t)(t.type,t.rule)),(0,e.createElement)("span",{className:"gb-modal-condition-operator-badge"},((e,t)=>g[e]?.[t]||t)(t.type,t.operator))),(!(!(r=t).value||!r.value.trim())||(s=r.operator,!["exists","not_exists"].includes(s)))&&(0,e.createElement)("div",{className:"gb-modal-condition-value"},(0,e.createElement)("strong",null,(0,o.__)("Value:","generateblocks-pro"))," ",(t=>{if(!t.value)return(0,o.__)("(no value)","generateblocks-pro");if("date_time"===t.type&&"day_of_week"===t.rule){const e=v(t.value);return 0===e.length?(0,o.__)("(no days selected)","generateblocks-pro"):e.map((e=>e)).join(", ")}if(t.value.includes("|")){const n=t.value.split("|",2);return(0,e.createElement)("div",{className:"gb-modal-custom-field-value"},(0,e.createElement)("div",null,(0,e.createElement)("strong",null,(0,o.__)("Field:","generateblocks-pro"))," ",n[0]),n[1]&&(0,e.createElement)("div",null,(0,e.createElement)("strong",null,(0,o.__)("Value:","generateblocks-pro"))," ",n[1]))}if(t.value.includes(",")&&"between"===t.operator){const n=t.value.split(",").map((e=>e.trim()));return(0,e.createElement)("div",{className:"gb-modal-date-range-value"},(0,e.createElement)("div",null,(0,e.createElement)("strong",null,(0,o.__)("From:","generateblocks-pro"))," ",n[0]),(0,e.createElement)("div",null,(0,e.createElement)("strong",null,(0,o.__)("To:","generateblocks-pro"))," ",n[1]||(0,o.__)("(not set)","generateblocks-pro")))}const n=v(t.value);if(0===n.length)return t.value;const r=n.map((e=>{let n;return n=t.rule.startsWith("post:")?"post":t.rule.startsWith("taxonomy:")||t.rule.startsWith("post_terms:")?"term":"author_id"===t.rule?"user":t.type,u[`${n}-${e}`]||e}));return 1===r.length?r[0]:r.join(", ")})(t)));var r,s,i})))))))):(0,e.createElement)("div",{className:"gb-modal-no-conditions"},(0,e.createElement)("p",null,(0,o.__)("This condition has no rules configured.","generateblocks-pro"))))))}const Oe=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})),Ne=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"}));function Re({condition:t,onClose:n}){const[a,i]=(0,r.useState)(null),[c,l]=(0,r.useState)(!0),[u,d]=(0,r.useState)(null),p=async()=>{try{l(!0),d(null);const e=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/${t.id}/usage`});e.success?i(e.response):d(e.response||(0,o.__)("Failed to load usage data","generateblocks-pro"))}catch(e){console.error("Error loading usage data:",e),d((0,o.__)("Error loading usage data. Please try again.","generateblocks-pro"))}finally{l(!1)}};(0,r.useEffect)((()=>{p()}),[t.id]);const h=a&&a.usage&&0<Object.keys(a.usage).length;return(0,e.createElement)(s.Modal,{title:t.title?.rendered||t.title||(0,o.__)("Untitled Condition","generateblocks-pro"),onRequestClose:n,className:"gb-modal-condition-usage",size:"medium"},(0,e.createElement)("div",{className:"gb-modal-usage-content"},c&&(0,e.createElement)("div",{className:"gb-modal-loading"},(0,e.createElement)(s.Spinner,null),(0,e.createElement)("p",null,(0,o.__)("Searching for usage…","generateblocks-pro"))),!c&&u&&(0,e.createElement)("div",{className:"gb-modal-error"},(0,e.createElement)("p",{style:{color:"#d63638"}},u),(0,e.createElement)(s.Button,{variant:"secondary",onClick:p},(0,o.__)("Try Again","generateblocks-pro"))),!c&&!u&&(0,e.createElement)("div",{className:"gb-modal-usage-body"},!h&&(0,e.createElement)("div",{className:"gb-modal-no-usage"},(0,e.createElement)("p",{style:{fontSize:"16px",textAlign:"center",color:"#666"}},(0,o.__)("This condition is not currently being used anywhere on your site.","generateblocks-pro")),(0,e.createElement)("p",{style:{fontSize:"14px",textAlign:"center",color:"#999"}},(0,o.__)("You can safely delete it, or keep it for future use.","generateblocks-pro"))),h&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"gb-modal-usage-summary"},(0,e.createElement)("p",{style:{fontSize:"14px",color:"#666",margin:"0"}},(0,o.__)("Found usage in","generateblocks-pro")," ",(0,e.createElement)("strong",null,a.total)," ",1===a.total?(0,o.__)("location","generateblocks-pro"):(0,o.__)("locations","generateblocks-pro"))),(0,e.createElement)("div",{className:"gb-modal-usage-sections"},Object.entries(a.usage).map((([t,n])=>(0,e.createElement)("div",{key:t,className:"gb-modal-usage-section"},(0,e.createElement)("h4",{className:"gb-modal-usage-section-title"},n.label,(0,e.createElement)("span",{className:"gb-modal-usage-count"},"(",n.total,")")),(0,e.createElement)("div",{className:"gb-modal-usage-items"},n.items.map((t=>(0,e.createElement)("div",{key:`${t.type}-${t.id}`,className:"gb-modal-usage-item"},(0,e.createElement)("div",{className:"gb-modal-usage-item-main"},(0,e.createElement)("div",{className:"gb-modal-usage-item-title"},(0,e.createElement)("strong",null,t.title),(t=>{const n={publish:(0,o.__)("Published","generateblocks-pro"),draft:(0,o.__)("Draft","generateblocks-pro"),private:(0,o.__)("Private","generateblocks-pro")},r={publish:{bg:"#d1fae5",color:"#065f46",border:"#a7f3d0"},draft:{bg:"#fef3c7",color:"#92400e",border:"#fcd34d"},private:{bg:"#e0e7ff",color:"#3730a3",border:"#c7d2fe"}},s=r[t]||r.draft;return(0,e.createElement)("span",{style:{background:s.bg,color:s.color,border:`1px solid ${s.border}`,padding:"2px 6px",borderRadius:"4px",fontSize:"11px",fontWeight:"500",textTransform:"uppercase"}},n[t]||t)})(t.status)),(0,e.createElement)("div",{className:"gb-modal-usage-item-meta"},(0,e.createElement)("span",{className:"gb-modal-usage-item-type"},t.type_label),(0,e.createElement)("span",{className:"gb-modal-usage-item-usage-type"},(e=>({overlay_display_condition:(0,o.__)("Overlay Panel Display Condition","generateblocks-pro"),block_conditions:(0,o.__)("Block Conditions","generateblocks-pro"),menu_item_conditions:(0,o.__)("Menu Item Conditions","generateblocks-pro")}[e]||e))(t.usage_type),t.block_count>1&&"block_conditions"===t.usage_type&&(0,e.createElement)("span",{style:{marginLeft:"5px",opacity:.7}},"(",t.block_count," ",(0,o.__)("blocks","generateblocks-pro"),")")))),(0,e.createElement)("div",{className:"gb-modal-usage-item-actions"},t.edit_url&&(0,e.createElement)(s.Button,{variant:"secondary",size:"compact",icon:Oe,href:t.edit_url,target:"_blank",iconSize:"14"},(0,o.__)("Edit","generateblocks-pro")),t.view_url&&(0,e.createElement)(s.Button,{variant:"tertiary",size:"compact",icon:Ne,href:t.view_url,target:"_blank",iconSize:"14"},(0,o.__)("View","generateblocks-pro")))))))))))))))}function Te({conditions:t,onEditCondition:n,refreshKey:a}){const i=re({mutationFn:async e=>{const t=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/${e}`,method:"DELETE"});if(t.success)return t.response;throw new Error("Failed to delete condition")},onSuccess:()=>{me()}}),c=re({mutationFn:async({id:e,status:t})=>{const n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/${e}`,method:"PUT",data:{status:t}});if(n.success)return n.response;throw new Error("Failed to update condition status")},onSuccess:()=>{me()}}),l=re({mutationFn:async e=>{const t=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/${e}`});if(!t?.success)throw new Error("Failed to fetch condition for duplication");const n=t.response;let r=n.title;"object"==typeof r&&r?.rendered&&(r=r.rendered);let s=n.gblocks_condition_cat||n.category||[];Array.isArray(s)||(s=s?[s]:[]);let o=[];if(s.length>0){const e=await oe()({path:"/wp/v2/condition-categories?include="+s.join(",")});e&&Array.isArray(e)&&(o=e.map((e=>e.slug)))}const a=n.gbConditions||n.conditions||{logic:"OR",groups:[]},i=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/conditions/",method:"POST",data:{title:r+" (Copy)",conditions:a,category:o,status:n.status||"publish"}});if(i.success)return i.response;throw new Error("Failed to duplicate condition")},onSuccess:()=>{me(),ge().invalidateQueries({queryKey:["condition-categories"]})}}),[u,d]=(0,r.useState)(null),[p,h]=(0,r.useState)(null),[g,m]=(0,r.useState)(null),[f,b]=(0,r.useState)([]),y=ge();(0,r.useEffect)((()=>{(async()=>{try{const e=await oe()({path:"/wp/v2/condition-categories"});e&&b(e)}catch(e){}})()}),[a]);const v=(0,r.useMemo)((()=>[{id:"name",header:(0,o.__)("Name","generateblocks-pro"),accessorKey:"title.rendered",cell:t=>{const r=t.row.original,a="draft"===r.status;return(0,e.createElement)("div",{style:{display:"flex",alignItems:"center",gap:"8px"}},(0,e.createElement)(s.Button,{variant:"link",onClick:()=>n(r)},t.getValue()),a&&(0,e.createElement)("span",{style:{color:"#999",fontSize:"0.9em"}},"(",(0,o.__)("draft","generateblocks-pro"),")"))}},{id:"category",header:(0,o.__)("Category","generateblocks-pro"),cell:t=>{const n=t.row.original,r=n.gblocks_condition_cat?.[0];if(!r)return(0,e.createElement)("span",{className:"gb-condition-category gb-condition-category--uncategorized"},(0,o.__)("Uncategorized","generateblocks-pro"));const s=f.find((e=>e.id===r)),a=s?(0,Se.decodeEntities)(s.name):`ID: ${r}`;return(0,e.createElement)("span",{className:"gb-condition-category"},a)}},{id:"conditions_count",header:(0,o.__)("Conditions","generateblocks-pro"),cell:t=>{const n=t.row.original,r=n.gbConditions||{groups:[]},a=r.groups?.reduce(((e,t)=>e+(t.conditions?.filter((e=>e.type&&e.rule&&e.operator)).length||0)),0)||0;return 0===a?(0,e.createElement)(e.Fragment,null,(0,o.__)("No conditions","generateblocks-pro")):(0,e.createElement)(s.Button,{variant:"link",iconSize:"14",onClick:()=>h(n),className:"gb-conditions-details-button"},a," ",1===a?(0,o.__)("condition","generateblocks-pro"):(0,o.__)("conditions","generateblocks-pro"))}},{id:"actions",header:null,cell:t=>{const{status:r,id:a}=t.row.original;return(0,e.createElement)(s.DropdownMenu,{icon:ye,label:(0,o.__)("More options","generateblocks-pro"),className:"gb-cloud-public-keys__dropdown",popoverProps:{placement:"left"}},(({onClose:i})=>(0,e.createElement)(e.Fragment,null,(0,e.createElement)(s.MenuGroup,null,(0,e.createElement)(s.MenuItem,{onClick:()=>{n(t.row.original),i()},icon:ve},(0,o.__)("Edit Condition","generateblocks-pro")),(0,e.createElement)(s.MenuItem,{onClick:()=>{m(t.row.original),i()},icon:_e},(0,o.__)("Check Usage","generateblocks-pro")),(0,e.createElement)(s.MenuItem,{onClick:()=>{l.mutateAsync(a).then((e=>{y.invalidateQueries({queryKey:["conditions"]}),e&&n(e)})),i()},icon:we},(0,o.__)("Duplicate","generateblocks-pro")),(0,e.createElement)(s.MenuItem,{onClick:()=>{const e="publish"===r?"draft":"publish";c.mutateAsync({id:a,status:e}).then((()=>{y.invalidateQueries({queryKey:["conditions"]})})),i()},icon:"publish"===r?Ee:ke},"publish"===r?(0,o.__)("Set as Draft","generateblocks-pro"):(0,o.__)("Publish","generateblocks-pro")),(0,e.createElement)(s.MenuItem,{isDestructive:!0,onClick:()=>{d(a),i()},icon:Ce},(0,o.__)("Delete Condition","generateblocks-pro"))))))}}]),[n,f]);return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"gb-dashboard-table-wrapper"},t.length?(0,e.createElement)(Ie.Table,{className:"gb-dashboard-table table-view-list",columns:v,data:t,"aria-labelledby":"conditions-table-header"}):(0,e.createElement)("p",{style:{marginTop:"0"}},(0,o.__)("No conditions found.","generateblocks-pro"))),!!u&&(0,e.createElement)(s.Modal,{title:(0,o.__)("Confirm","generateblocks-pro"),isDismissible:!1,onRequestClose:()=>null,style:{maxWidth:"300px"}},(0,e.createElement)("div",{style:{marginBottom:"1em"}},(0,o.__)("This will permanently delete this condition. You cannot undo this action.","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"primary",onClick:async()=>{await i.mutateAsync(u),y.invalidateQueries({queryKey:["conditions"]}),d(null)}},(0,o.__)("OK","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"tertiary",onClick:()=>d(null)},(0,o.__)("Cancel","generateblocks-pro"))),p&&(0,e.createElement)(xe,{condition:p,onClose:()=>h(null)}),g&&(0,e.createElement)(Re,{condition:g,onClose:()=>m(null)}))}const De=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M18 11.2h-5.2V6h-1.6v5.2H6v1.6h5.2V18h1.6v-5.2H18z"})),Pe=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M18.5 15v3.5H13V6.7l4.5 4.1 1-1.1-6.2-5.8-5.8 5.8 1 1.1 4-4v11.7h-6V15H4v5h16v-5z"})),Me=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M18 11.3l-1-1.1-4 4V3h-1.5v11.3L7 10.2l-1 1.1 6.2 5.8 5.8-5.8zm.5 3.7v3.5h-13V15H4v5h16v-5h-1.5z"}));function Ae({conditions:t,onConditionsImport:n}){const[a,i]=(0,r.useState)(!1),[c,l]=(0,r.useState)(""),[u,d]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),g=()=>{if(!t.groups||0===t.groups.length)return"";const e={logic:t.logic,groups:t.groups.map((e=>({logic:e.logic,conditions:e.conditions.filter((e=>e.type&&e.rule&&e.operator)).map((e=>({type:e.type,rule:e.rule,operator:e.operator,value:e.value||""})))}))).filter((e=>0<e.conditions.length))};return JSON.stringify(e,null,2)},m=t.groups&&0<t.groups.length;return(0,e.createElement)("div",{className:"gb-conditions-preview"},u?(0,e.createElement)("div",{className:"gb-import-section"},(0,e.createElement)(s.TextareaControl,{label:(0,o.__)("Import Conditions (JSON format)","generateblocks-pro"),value:c,onChange:l,rows:8,placeholder:(0,o.__)("Paste exported conditions here…","generateblocks-pro")}),(0,e.createElement)(s.Button,{variant:"primary",onClick:()=>{if(c.trim())try{const e=JSON.parse(c);if(!e.groups||!Array.isArray(e.groups))throw new Error("Invalid format: missing groups array");e.groups.forEach(((e,t)=>{if(!e.logic||!["AND","OR"].includes(e.logic))throw new Error(`Invalid logic operator in group ${t+1}`);if(!e.conditions||!Array.isArray(e.conditions))throw new Error(`Invalid conditions in group ${t+1}`);e.conditions.forEach(((e,n)=>{if(!e.type||!e.rule||!e.operator)throw new Error(`Incomplete condition ${n+1} in group ${t+1}`)}))}));const t={logic:e.logic||"OR",groups:e.groups};n(t),l(""),d(!1),alert((0,o.__)("Conditions imported successfully!","generateblocks-pro"))}catch(e){alert((0,o.__)("Import failed: ","generateblocks-pro")+e.message)}else alert((0,o.__)("Please enter conditions to import.","generateblocks-pro"))},disabled:!c.trim()},(0,o.__)("Import Conditions","generateblocks-pro"))):(0,e.createElement)(e.Fragment,null,a&&m&&(0,e.createElement)("div",{className:"gb-preview-text"},(0,e.createElement)("pre",{className:"gb-export-format"},g()||(0,o.__)("No conditions to export","generateblocks-pro")))),(0,e.createElement)("div",{className:"gb-preview-footer"},m&&(0,e.createElement)(s.ToggleControl,{label:(0,o.__)("Show JSON Format","generateblocks-pro"),checked:a,onChange:i,help:(0,o.__)("View the raw JSON format for advanced users","generateblocks-pro")}),(0,e.createElement)("div",{className:"gb-preview-actions"},m&&a&&(0,e.createElement)(s.Button,{variant:"secondary",size:"compact",icon:we,onClick:async()=>{const e=g();try{await navigator.clipboard.writeText(e),h(!0),setTimeout((()=>h(!1)),2e3)}catch(t){const n=document.createElement("textarea");n.value=e,document.body.appendChild(n),n.focus(),n.select(),document.execCommand("copy"),document.body.removeChild(n),h(!0),setTimeout((()=>h(!1)),2e3)}},className:"gb-copy-button"},p?(0,o.__)("Copied!","generateblocks-pro"):(0,o.__)("Copy JSON","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"secondary",size:"compact",icon:u?Pe:Me,onClick:()=>d(!u)},u?(0,o.__)("Cancel Import","generateblocks-pro"):(0,o.__)("Import","generateblocks-pro")))))}function Fe({isOpen:t,onClose:n,onCreateCategory:a}){const[i,c]=(0,r.useState)(""),[l,u]=(0,r.useState)(!1),d=async()=>{if(i.trim()){u(!0);try{const e=i.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-");await a({name:i.trim(),slug:e}),c(""),n()}catch(e){}finally{u(!1)}}},p=()=>{c(""),n()};return t?(0,e.createElement)(s.Modal,{title:(0,o.__)("Create New Category","generateblocks-pro"),onRequestClose:p,className:"gb-create-category-modal"},(0,e.createElement)("div",{className:"gb-modal-content"},(0,e.createElement)(s.TextControl,{label:(0,o.__)("Category Name","generateblocks-pro"),value:i,onChange:c,placeholder:(0,o.__)("Enter category name…","generateblocks-pro"),disabled:l,onKeyDown:e=>{"Enter"===e.key&&d()}}),(0,e.createElement)("div",{className:"gb-modal-actions",style:{display:"flex",gap:"5px",justifyContent:"space-between"}},(0,e.createElement)(s.Button,{variant:"secondary",onClick:p,disabled:l},(0,o.__)("Cancel","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"primary",onClick:d,disabled:!i.trim()||l,isBusy:l},(0,o.__)("Create Category","generateblocks-pro"))))):null}const $e=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"})),qe=(0,r.createElement)(be.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(be.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V7h15v12zM9 10H7v2h2v-2zm0 4H7v2h2v-2zm4-4h-2v2h2v-2zm4 0h-2v2h2v-2zm-4 4h-2v2h2v-2zm4 0h-2v2h2v-2z"}));function Be({currentDate:t,onChange:n,placeholder:a=(0,o.__)("Select date and time","generateblocks-pro")}){const[i,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(t),d=()=>{u(t),c(!1)};return(0,e.createElement)("div",{className:"gb-datetime-popover-wrapper"},(0,e.createElement)(s.Button,{variant:"secondary",icon:qe,onClick:()=>{u(t),c(!0)},className:"gb-datetime-trigger",__next40pxDefaultSize:!0},(p=t)?p.toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}):a),i&&(0,e.createElement)(s.Popover,{position:"bottom left",onClose:d,className:"gb-datetime-popover"},(0,e.createElement)("div",{className:"gb-datetime-popover-content"},(0,e.createElement)(s.DateTimePicker,{currentDate:l,onChange:u,is12Hour:!0}),(0,e.createElement)("div",{className:"gb-datetime-popover-actions"},t&&(0,e.createElement)(s.Button,{variant:"link",onClick:()=>{u(null),n(null),c(!1)},isDestructive:!0},(0,o.__)("Clear","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-datetime-popover-main-actions"},(0,e.createElement)(s.Button,{variant:"tertiary",onClick:d},(0,o.__)("Cancel","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"primary",onClick:()=>{n(l),c(!1)}},(0,o.__)("Apply","generateblocks-pro")))))));var p}function Le({currentTime:t,onChange:n,placeholder:a=(0,o.__)("Select time","generateblocks-pro")}){const[i,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(t||""),[d,p]=(0,r.useState)(null),h=()=>!(!l||!/^\d{2}:\d{2}$/.test(l))||!(d&&!d.validity.valid)&&(!l&&!t||!(!l&&t)||!!d&&d.validity.valid),g=()=>{c(!1)};return(0,e.createElement)("div",{className:"gb-datetime-popover-wrapper"},(0,e.createElement)(s.Button,{variant:"secondary",icon:qe,onClick:()=>{u(t||""),c(!0)},className:"gb-datetime-trigger",__next40pxDefaultSize:!0},(e=>{if(!e)return a;const[t,n]=e.split(":").map(Number);if(isNaN(t)||isNaN(n))return e;const r=new Date;return r.setHours(t,n,0,0),r.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit",hour12:!0})})(t)),i&&(0,e.createElement)(s.Popover,{position:"bottom left",onClose:g,className:"gb-datetime-popover gb-time-only-popover"},(0,e.createElement)("div",{className:"gb-datetime-popover-content"},(0,e.createElement)("div",{className:"gb-time-input-wrapper"},(0,e.createElement)("label",{htmlFor:"gb-time-input",className:"gb-time-input-label"},(0,o.__)("Time","generateblocks-pro")),(0,e.createElement)("input",{id:"gb-time-input",type:"time",value:l,onChange:e=>u(e.target.value),className:"gb-time-input",ref:p}),(0,e.createElement)("small",{className:"gb-time-input-help"},(0,o.__)("Enter time in HH:MM format","generateblocks-pro"))),(0,e.createElement)("div",{className:"gb-datetime-popover-actions"},t&&(0,e.createElement)(s.Button,{variant:"link",onClick:()=>{u(""),n(""),c(!1)},isDestructive:!0},(0,o.__)("Clear","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-datetime-popover-main-actions"},(0,e.createElement)(s.Button,{variant:"tertiary",onClick:g},(0,o.__)("Cancel","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"primary",onClick:()=>{h()&&(n(l),c(!1))},disabled:!h()},(0,o.__)("Apply","generateblocks-pro")))))))}function Ve(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function Qe(){return Qe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Qe.apply(null,arguments)}var je=n(5556),ze=n.n(je);n(44363);const He=e=>"object"==typeof e&&null!=e&&1===e.nodeType,Ke=(e,t)=>(!t||"hidden"!==e)&&"visible"!==e&&"clip"!==e,Ue=(e,t)=>{if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){const n=getComputedStyle(e,null);return Ke(n.overflowY,t)||Ke(n.overflowX,t)||(e=>{const t=(e=>{if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch(e){return null}})(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)})(e)}return!1},We=(e,t,n,r,s,o,a,i)=>o<e&&a>t||o>e&&a<t?0:o<=e&&i<=n||a>=t&&i>=n?o-e-r:a>t&&i<n||o<e&&i>n?a-t+s:0,Ge=e=>{const t=e.parentElement;return null==t?e.getRootNode().host||null:t};var Ye=function(){return Ye=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},Ye.apply(this,arguments)};Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var Je=0;function Ze(){}function Xe(e,t,n){return e===t||t instanceof n.Node&&e.contains&&e.contains(t)}function et(e,t){var n;function r(){n&&clearTimeout(n)}function s(){for(var s=arguments.length,o=new Array(s),a=0;a<s;a++)o[a]=arguments[a];r(),n=setTimeout((function(){n=null,e.apply(void 0,o)}),t)}return s.cancel=r,s}function tt(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];return t.some((function(t){return t&&t.apply(void 0,[e].concat(r)),e.preventDownshiftDefault||e.hasOwnProperty("nativeEvent")&&e.nativeEvent.preventDownshiftDefault}))}}function nt(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){t.forEach((function(t){"function"==typeof t?t(e):t&&(t.current=e)}))}}function rt(e,t){return e&&t?Object.keys(e).reduce((function(n,r){return n[r]=st(t,r)?t[r]:e[r],n}),{}):e}function st(e,t){return void 0!==e[t]}function ot(e,t,n,r,s){void 0===s&&(s=!1);var o=n.length;if(0===o)return-1;var a=o-1;("number"!=typeof e||e<0||e>a)&&(e=t>0?-1:a+1);var i=e+t;i<0?i=s?a:0:i>a&&(i=s?0:a);var c=at(i,t<0,n,r,s);return-1===c?e>=o?-1:e:c}function at(e,t,n,r,s){void 0===s&&(s=!1);var o=n.length;if(t){for(var a=e;a>=0;a--)if(!r(n[a],a))return a}else for(var i=e;i<o;i++)if(!r(n[i],i))return i;return s?at(t?o-1:0,t,n,r):-1}function it(e,t,n,r){return void 0===r&&(r=!0),n&&t.some((function(t){return t&&(Xe(t,e,n)||r&&Xe(t,n.document.activeElement,n))}))}var ct=et((function(e){lt(e).textContent=""}),500);function lt(e){var t=e.getElementById("a11y-status-message");return t||((t=e.createElement("div")).setAttribute("id","a11y-status-message"),t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-relevant","additions text"),Object.assign(t.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),e.body.appendChild(t),t)}var ut={highlightedIndex:-1,isOpen:!1,selectedItem:null,inputValue:""};var dt=et((function(e,t){!function(e,t){e&&t&&(lt(t).textContent=e,ct(t))}(e,t)}),200),pt="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?e.useLayoutEffect:e.useEffect,ht="useId"in t()?function(n){var r=n.id,s=n.labelId,o=n.menuId,a=n.getItemId,i=n.toggleButtonId,c=n.inputId,l="downshift-"+t().useId();return r||(r=l),(0,e.useRef)({labelId:s||r+"-label",menuId:o||r+"-menu",getItemId:a||function(e){return r+"-item-"+e},toggleButtonId:i||r+"-toggle-button",inputId:c||r+"-input"}).current}:function(t){var n=t.id,r=void 0===n?"downshift-"+String(Je++):n,s=t.labelId,o=t.menuId,a=t.getItemId,i=t.toggleButtonId,c=t.inputId;return(0,e.useRef)({labelId:s||r+"-label",menuId:o||r+"-menu",getItemId:a||function(e){return r+"-item-"+e},toggleButtonId:i||r+"-toggle-button",inputId:c||r+"-input"}).current};function gt(e){return""+e.slice(0,1).toUpperCase()+e.slice(1)}function mt(t){var n=(0,e.useRef)(t);return n.current=t,n}function ft(t,n,r,s){var o=(0,e.useRef)(),a=(0,e.useRef)(),i=(0,e.useCallback)((function(e,n){a.current=n,e=rt(e,n.props);var r=t(e,n);return n.props.stateReducer(e,Qe({},n,{changes:r}))}),[t]),c=(0,e.useReducer)(i,n,r),l=c[0],u=c[1],d=mt(n),p=(0,e.useCallback)((function(e){return u(Qe({props:d.current},e))}),[d]),h=a.current;return(0,e.useEffect)((function(){var e=rt(o.current,null==h?void 0:h.props);h&&o.current&&!s(e,l)&&function(e,t,n){var r=e.props,s=e.type,o={};Object.keys(t).forEach((function(r){!function(e,t,n,r){var s=t.props,o=t.type,a="on"+gt(e)+"Change";s[a]&&void 0!==r[e]&&r[e]!==n[e]&&s[a](Qe({type:o},r))}(r,e,t,n),n[r]!==t[r]&&(o[r]=n[r])})),r.onStateChange&&Object.keys(o).length&&r.onStateChange(Qe({type:s},o))}(h,e,l),o.current=l}),[l,h,s]),[l,p]}var bt={itemToString:function(e){return e?String(e):""},itemToKey:function(e){return e},stateReducer:function(e,t){return t.changes},scrollIntoView:function(e,t){if(e){var n=((e,t)=>{var n,r,s,o;if("undefined"==typeof document)return[];const{scrollMode:a,block:i,inline:c,boundary:l,skipOverflowHiddenElements:u}=t,d="function"==typeof l?l:e=>e!==l;if(!He(e))throw new TypeError("Invalid target");const p=document.scrollingElement||document.documentElement,h=[];let g=e;for(;He(g)&&d(g);){if(g=Ge(g),g===p){h.push(g);break}null!=g&&g===document.body&&Ue(g)&&!Ue(document.documentElement)||null!=g&&Ue(g,u)&&h.push(g)}const m=null!=(r=null==(n=window.visualViewport)?void 0:n.width)?r:innerWidth,f=null!=(o=null==(s=window.visualViewport)?void 0:s.height)?o:innerHeight,{scrollX:b,scrollY:y}=window,{height:v,width:_,top:w,right:E,bottom:k,left:C}=e.getBoundingClientRect(),{top:S,right:I,bottom:x,left:O}=(e=>{const t=window.getComputedStyle(e);return{top:parseFloat(t.scrollMarginTop)||0,right:parseFloat(t.scrollMarginRight)||0,bottom:parseFloat(t.scrollMarginBottom)||0,left:parseFloat(t.scrollMarginLeft)||0}})(e);let N="start"===i||"nearest"===i?w-S:"end"===i?k+x:w+v/2-S+x,R="center"===c?C+_/2-O+I:"end"===c?E+I:C-O;const T=[];for(let e=0;e<h.length;e++){const t=h[e],{height:n,width:r,top:s,right:o,bottom:l,left:u}=t.getBoundingClientRect();if("if-needed"===a&&w>=0&&C>=0&&k<=f&&E<=m&&(t===p&&!Ue(t)||w>=s&&k<=l&&C>=u&&E<=o))return T;const d=getComputedStyle(t),g=parseInt(d.borderLeftWidth,10),S=parseInt(d.borderTopWidth,10),I=parseInt(d.borderRightWidth,10),x=parseInt(d.borderBottomWidth,10);let O=0,D=0;const P="offsetWidth"in t?t.offsetWidth-t.clientWidth-g-I:0,M="offsetHeight"in t?t.offsetHeight-t.clientHeight-S-x:0,A="offsetWidth"in t?0===t.offsetWidth?0:r/t.offsetWidth:0,F="offsetHeight"in t?0===t.offsetHeight?0:n/t.offsetHeight:0;if(p===t)O="start"===i?N:"end"===i?N-f:"nearest"===i?We(y,y+f,f,S,x,y+N,y+N+v,v):N-f/2,D="start"===c?R:"center"===c?R-m/2:"end"===c?R-m:We(b,b+m,m,g,I,b+R,b+R+_,_),O=Math.max(0,O+y),D=Math.max(0,D+b);else{O="start"===i?N-s-S:"end"===i?N-l+x+M:"nearest"===i?We(s,l,n,S,x+M,N,N+v,v):N-(s+n/2)+M/2,D="start"===c?R-u-g:"center"===c?R-(u+r/2)+P/2:"end"===c?R-o+I+P:We(u,o,r,g,I+P,R,R+_,_);const{scrollLeft:e,scrollTop:a}=t;O=0===F?0:Math.max(0,Math.min(a+O/F,t.scrollHeight-n/F+M)),D=0===A?0:Math.max(0,Math.min(e+D/A,t.scrollWidth-r/A+P)),N+=a-O,R+=e-D}T.push({el:t,top:O,left:D})}return T})(e,{boundary:t,block:"nearest",scrollMode:"if-needed"});n.forEach((function(e){var t=e.el,n=e.top,r=e.left;t.scrollTop=n,t.scrollLeft=r}))}},environment:"undefined"==typeof window?void 0:window};function yt(e,t,n){void 0===n&&(n=ut);var r=e["default"+gt(t)];return void 0!==r?r:n[t]}function vt(e,t,n){void 0===n&&(n=ut);var r=e[t];if(void 0!==r)return r;var s=e["initial"+gt(t)];return void 0!==s?s:yt(e,t,n)}function _t(e,t,n){var r=e.items,s=e.initialHighlightedIndex,o=e.defaultHighlightedIndex,a=e.isItemDisabled,i=e.itemToKey,c=t.selectedItem,l=t.highlightedIndex;return 0===r.length?-1:void 0===s||l!==s||a(r[s],s)?void 0===o||a(r[o],o)?c?r.findIndex((function(e){return i(c)===i(e)})):n<0&&!a(r[r.length-1],r.length-1)?r.length-1:n>0&&!a(r[0],0)?0:-1:o:s}var wt=Ze;function Et(e,t,n){var r;return void 0===n&&(n=!0),Qe({isOpen:!1,highlightedIndex:-1},(null==(r=e.items)?void 0:r.length)&&t>=0&&Qe({selectedItem:e.items[t],isOpen:yt(e,"isOpen"),highlightedIndex:yt(e,"highlightedIndex")},n&&{inputValue:e.itemToString(e.items[t])}))}function kt(e,t){return e.isOpen===t.isOpen&&e.inputValue===t.inputValue&&e.highlightedIndex===t.highlightedIndex&&e.selectedItem===t.selectedItem}function Ct(){var e=t().useRef(!0);return t().useEffect((function(){return e.current=!1,function(){e.current=!0}}),[]),e.current}function St(e){var t=yt(e,"highlightedIndex");return t>-1&&e.isItemDisabled(e.items[t],t)?-1:t}var It=Qe({},{environment:ze().shape({addEventListener:ze().func.isRequired,removeEventListener:ze().func.isRequired,document:ze().shape({createElement:ze().func.isRequired,getElementById:ze().func.isRequired,activeElement:ze().any.isRequired,body:ze().any.isRequired}).isRequired,Node:ze().func.isRequired}),itemToString:ze().func,itemToKey:ze().func,stateReducer:ze().func},{getA11yStatusMessage:ze().func,highlightedIndex:ze().number,defaultHighlightedIndex:ze().number,initialHighlightedIndex:ze().number,isOpen:ze().bool,defaultIsOpen:ze().bool,initialIsOpen:ze().bool,selectedItem:ze().any,initialSelectedItem:ze().any,defaultSelectedItem:ze().any,id:ze().string,labelId:ze().string,menuId:ze().string,getItemId:ze().func,toggleButtonId:ze().string,onSelectedItemChange:ze().func,onHighlightedIndexChange:ze().func,onStateChange:ze().func,onIsOpenChange:ze().func,scrollIntoView:ze().func});Ye(Ye({},It),{items:ze().array.isRequired,isItemDisabled:ze().func}),Ye(Ye({},bt),{isItemDisabled:function(){return!1}});var xt=Object.freeze({__proto__:null,ControlledPropUpdatedSelectedItem:22,FunctionCloseMenu:17,FunctionOpenMenu:16,FunctionReset:21,FunctionSelectItem:19,FunctionSetHighlightedIndex:18,FunctionSetInputValue:20,FunctionToggleMenu:15,InputBlur:9,InputChange:8,InputClick:10,InputKeyDownArrowDown:0,InputKeyDownArrowUp:1,InputKeyDownEnd:4,InputKeyDownEnter:7,InputKeyDownEscape:2,InputKeyDownHome:3,InputKeyDownPageDown:6,InputKeyDownPageUp:5,ItemClick:13,ItemMouseMove:12,MenuMouseLeave:11,ToggleButtonClick:14});function Ot(e){var t=function(e){var t=vt(e,"selectedItem"),n=vt(e,"isOpen"),r=function(e){var t=vt(e,"highlightedIndex");return t>-1&&e.isItemDisabled(e.items[t],t)?-1:t}(e),s=vt(e,"inputValue");return{highlightedIndex:r<0&&t&&n?e.items.findIndex((function(n){return e.itemToKey(n)===e.itemToKey(t)})):r,isOpen:n,selectedItem:t,inputValue:s}}(e),n=t.selectedItem,r=t.inputValue;return""===r&&n&&void 0===e.defaultInputValue&&void 0===e.initialInputValue&&void 0===e.inputValue&&(r=e.itemToString(n)),Qe({},t,{inputValue:r})}Qe({},It,{items:ze().array.isRequired,isItemDisabled:ze().func,inputValue:ze().string,defaultInputValue:ze().string,initialInputValue:ze().string,inputId:ze().string,onInputValueChange:ze().func});var Nt=Ze,Rt=Qe({},bt,{isItemDisabled:function(){return!1}});function Tt(e,t){var n,r,s=t.type,o=t.props,a=t.altKey;switch(s){case 13:r={isOpen:yt(o,"isOpen"),highlightedIndex:St(o),selectedItem:o.items[t.index],inputValue:o.itemToString(o.items[t.index])};break;case 0:r=e.isOpen?{highlightedIndex:ot(e.highlightedIndex,1,o.items,o.isItemDisabled,!0)}:{highlightedIndex:a&&null==e.selectedItem?-1:_t(o,e,1),isOpen:o.items.length>=0};break;case 1:r=e.isOpen?a?Et(o,e.highlightedIndex):{highlightedIndex:ot(e.highlightedIndex,-1,o.items,o.isItemDisabled,!0)}:{highlightedIndex:_t(o,e,-1),isOpen:o.items.length>=0};break;case 7:r=Et(o,e.highlightedIndex);break;case 2:r=Qe({isOpen:!1,highlightedIndex:-1},!e.isOpen&&{selectedItem:null,inputValue:""});break;case 5:r={highlightedIndex:ot(e.highlightedIndex,-10,o.items,o.isItemDisabled,!0)};break;case 6:r={highlightedIndex:ot(e.highlightedIndex,10,o.items,o.isItemDisabled,!0)};break;case 3:r={highlightedIndex:at(0,!1,o.items,o.isItemDisabled)};break;case 4:r={highlightedIndex:at(o.items.length-1,!0,o.items,o.isItemDisabled)};break;case 9:r=Qe({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&(null==(n=o.items)?void 0:n.length)&&t.selectItem&&{selectedItem:o.items[e.highlightedIndex],inputValue:o.itemToString(o.items[e.highlightedIndex])});break;case 8:r={isOpen:!0,highlightedIndex:St(o),inputValue:t.inputValue};break;case 10:r={isOpen:!e.isOpen,highlightedIndex:e.isOpen?-1:_t(o,e,0)};break;case 19:r={selectedItem:t.selectedItem,inputValue:o.itemToString(t.selectedItem)};break;case 22:r={inputValue:t.inputValue};break;default:return function(e,t,n){var r,s=t.type,o=t.props;switch(s){case n.ItemMouseMove:r={highlightedIndex:t.disabled?-1:t.index};break;case n.MenuMouseLeave:r={highlightedIndex:-1};break;case n.ToggleButtonClick:case n.FunctionToggleMenu:r={isOpen:!e.isOpen,highlightedIndex:e.isOpen?-1:_t(o,e,0)};break;case n.FunctionOpenMenu:r={isOpen:!0,highlightedIndex:_t(o,e,0)};break;case n.FunctionCloseMenu:r={isOpen:!1};break;case n.FunctionSetHighlightedIndex:r={highlightedIndex:o.isItemDisabled(o.items[t.highlightedIndex],t.highlightedIndex)?-1:t.highlightedIndex};break;case n.FunctionSetInputValue:r={inputValue:t.inputValue};break;case n.FunctionReset:r={highlightedIndex:St(o),isOpen:yt(o,"isOpen"),selectedItem:yt(o,"selectedItem"),inputValue:yt(o,"inputValue")};break;default:throw new Error("Reducer called without proper action type.")}return Qe({},e,r)}(e,t,xt)}return Qe({},e,r)}var Dt=["onMouseLeave","refKey","ref"],Pt=["item","index","refKey","ref","onMouseMove","onMouseDown","onClick","onPress","disabled"],Mt=["onClick","onPress","refKey","ref"],At=["onKeyDown","onChange","onInput","onBlur","onChangeText","onClick","refKey","ref"];function Ft(t){void 0===t&&(t={}),Nt(t,Ft);var n=Qe({},Rt,t),r=n.items,s=n.scrollIntoView,o=n.environment,a=n.getA11yStatusMessage,i=function(t,n,r,s){var o=(0,e.useRef)(),a=ft(t,n,r,s),i=a[0],c=a[1],l=Ct();return(0,e.useEffect)((function(){st(n,"selectedItem")&&(l||n.itemToKey(n.selectedItem)!==n.itemToKey(o.current)&&c({type:22,inputValue:n.itemToString(n.selectedItem)}),o.current=i.selectedItem===o.current?n.selectedItem:i.selectedItem)}),[i.selectedItem,n.selectedItem]),[rt(i,n),c]}(Tt,n,Ot,kt),c=i[0],l=i[1],u=c.isOpen,d=c.highlightedIndex,p=c.selectedItem,h=c.inputValue,g=(0,e.useRef)(null),m=(0,e.useRef)({}),f=(0,e.useRef)(null),b=(0,e.useRef)(null),y=Ct(),v=ht(n),_=(0,e.useRef)(),w=mt({state:c,props:n}),E=(0,e.useCallback)((function(e){return m.current[v.getItemId(e)]}),[v]);!function(t,n,r,s){void 0===s&&(s={});var o=s.document,a=Ct();(0,e.useEffect)((function(){if(t&&!a&&o){var e=t(n);dt(e,o)}}),r),(0,e.useEffect)((function(){return function(){var e,t;dt.cancel(),(t=null==(e=o)?void 0:e.getElementById("a11y-status-message"))&&t.remove()}}),[o])}(a,c,[u,d,p,h],o);var k=function(t){var n=t.highlightedIndex,r=t.isOpen,s=t.itemRefs,o=t.getItemNodeFromIndex,a=t.menuElement,i=t.scrollIntoView,c=(0,e.useRef)(!0);return pt((function(){n<0||!r||!Object.keys(s.current).length||(!1===c.current?c.current=!0:i(o(n),a))}),[n]),c}({menuElement:g.current,highlightedIndex:d,isOpen:u,itemRefs:m,scrollIntoView:s,getItemNodeFromIndex:E});wt({props:n,state:c}),(0,e.useEffect)((function(){vt(n,"isOpen")&&f.current&&f.current.focus()}),[]),(0,e.useEffect)((function(){y||(_.current=r.length)}));var C=function(t,n,r){var s=(0,e.useRef)({isMouseDown:!1,isTouchMove:!1,isTouchEnd:!1});return(0,e.useEffect)((function(){if(!t)return Ze;var e=r.map((function(e){return e.current}));function o(){s.current.isTouchEnd=!1,s.current.isMouseDown=!0}function a(r){s.current.isMouseDown=!1,it(r.target,e,t)||n()}function i(){s.current.isTouchEnd=!1,s.current.isTouchMove=!1}function c(){s.current.isTouchMove=!0}function l(r){s.current.isTouchEnd=!0,s.current.isTouchMove||it(r.target,e,t,!1)||n()}return t.addEventListener("mousedown",o),t.addEventListener("mouseup",a),t.addEventListener("touchstart",i),t.addEventListener("touchmove",c),t.addEventListener("touchend",l),function(){t.removeEventListener("mousedown",o),t.removeEventListener("mouseup",a),t.removeEventListener("touchstart",i),t.removeEventListener("touchmove",c),t.removeEventListener("touchend",l)}}),[r,t,n]),s.current}(o,(0,e.useCallback)((function(){w.current.state.isOpen&&l({type:9,selectItem:!1})}),[l,w]),(0,e.useMemo)((function(){return[g,b,f]}),[g.current,b.current,f.current])),S=Ze;(0,e.useEffect)((function(){u||(m.current={})}),[u]),(0,e.useEffect)((function(){var e;u&&null!=o&&o.document&&null!=f&&null!=(e=f.current)&&e.focus&&o.document.activeElement!==f.current&&f.current.focus()}),[u,o]);var I=(0,e.useMemo)((function(){return{ArrowDown:function(e){e.preventDefault(),l({type:0,altKey:e.altKey})},ArrowUp:function(e){e.preventDefault(),l({type:1,altKey:e.altKey})},Home:function(e){w.current.state.isOpen&&(e.preventDefault(),l({type:3}))},End:function(e){w.current.state.isOpen&&(e.preventDefault(),l({type:4}))},Escape:function(e){var t=w.current.state;(t.isOpen||t.inputValue||t.selectedItem||t.highlightedIndex>-1)&&(e.preventDefault(),l({type:2}))},Enter:function(e){w.current.state.isOpen&&229!==e.which&&(e.preventDefault(),l({type:7}))},PageUp:function(e){w.current.state.isOpen&&(e.preventDefault(),l({type:5}))},PageDown:function(e){w.current.state.isOpen&&(e.preventDefault(),l({type:6}))}}}),[l,w]),x=(0,e.useCallback)((function(e){return Qe({id:v.labelId,htmlFor:v.inputId},e)}),[v]),O=(0,e.useCallback)((function(e,t){var n,r=void 0===e?{}:e,s=r.onMouseLeave,o=r.refKey,a=void 0===o?"ref":o,i=r.ref,c=Ve(r,Dt),u=(void 0===t?{}:t).suppressRefError;return S("getMenuProps",void 0!==u&&u,a,g),Qe(((n={})[a]=nt(i,(function(e){g.current=e})),n.id=v.menuId,n.role="listbox",n["aria-labelledby"]=c&&c["aria-label"]?void 0:""+v.labelId,n.onMouseLeave=tt(s,(function(){l({type:11})})),n),c)}),[l,S,v]),N=(0,e.useCallback)((function(e){var t,n,r=void 0===e?{}:e,s=r.item,o=r.index,a=r.refKey,i=void 0===a?"ref":a,c=r.ref,u=r.onMouseMove,d=r.onMouseDown,p=r.onClick;r.onPress;var h=r.disabled,g=Ve(r,Pt);void 0!==h&&console.warn('Passing "disabled" as an argument to getItemProps is not supported anymore. Please use the isItemDisabled prop from useCombobox.');var f=w.current,b=f.props,y=f.state,_=function(e,t,n,r){var s,o;if(void 0===e){if(void 0===t)throw new Error(r);s=n[t],o=t}else o=void 0===t?n.indexOf(e):t,s=e;return[s,o]}(s,o,b.items,"Pass either item or index to getItemProps!"),E=_[0],S=_[1],I=b.isItemDisabled(E,S),x=p;return Qe(((t={})[i]=nt(c,(function(e){e&&(m.current[v.getItemId(S)]=e)})),t["aria-disabled"]=I,t["aria-selected"]=S===y.highlightedIndex,t.id=v.getItemId(S),t.role="option",t),!I&&((n={}).onClick=tt(x,(function(){l({type:13,index:S})})),n),{onMouseMove:tt(u,(function(){C.isTouchEnd||S===y.highlightedIndex||(k.current=!1,l({type:12,index:S,disabled:I}))})),onMouseDown:tt(d,(function(e){return e.preventDefault()}))},g)}),[l,v,w,C,k]),R=(0,e.useCallback)((function(e){var t,n=void 0===e?{}:e,r=n.onClick;n.onPress;var s=n.refKey,o=void 0===s?"ref":s,a=n.ref,i=Ve(n,Mt),c=w.current.state;return Qe(((t={})[o]=nt(a,(function(e){b.current=e})),t["aria-controls"]=v.menuId,t["aria-expanded"]=c.isOpen,t.id=v.toggleButtonId,t.tabIndex=-1,t),!i.disabled&&Qe({},{onClick:tt(r,(function(){l({type:14})}))}),i)}),[l,w,v]),T=(0,e.useCallback)((function(e,t){var n,r=void 0===e?{}:e,s=r.onKeyDown,a=r.onChange,i=r.onInput,c=r.onBlur;r.onChangeText;var u=r.onClick,d=r.refKey,p=void 0===d?"ref":d,h=r.ref,g=Ve(r,At),m=(void 0===t?{}:t).suppressRefError;S("getInputProps",void 0!==m&&m,p,f);var b,y=w.current.state,_={};return g.disabled||((b={}).onChange=tt(a,i,(function(e){l({type:8,inputValue:e.target.value})})),b.onKeyDown=tt(s,(function(e){var t=function(e){var t=e.key,n=e.keyCode;return n>=37&&n<=40&&0!==t.indexOf("Arrow")?"Arrow"+t:t}(e);t&&I[t]&&I[t](e)})),b.onBlur=tt(c,(function(e){if(null!=o&&o.document&&y.isOpen&&!C.isMouseDown){var t=null===e.relatedTarget&&o.document.activeElement!==o.document.body;l({type:9,selectItem:!t})}})),b.onClick=tt(u,(function(){l({type:10})})),_=b),Qe(((n={})[p]=nt(h,(function(e){f.current=e})),n["aria-activedescendant"]=y.isOpen&&y.highlightedIndex>-1?v.getItemId(y.highlightedIndex):"",n["aria-autocomplete"]="list",n["aria-controls"]=v.menuId,n["aria-expanded"]=y.isOpen,n["aria-labelledby"]=g&&g["aria-label"]?void 0:v.labelId,n.autoComplete="off",n.id=v.inputId,n.role="combobox",n.value=y.inputValue,n),_,g)}),[l,v,o,I,w,C,S]),D=(0,e.useCallback)((function(){l({type:15})}),[l]),P=(0,e.useCallback)((function(){l({type:17})}),[l]),M=(0,e.useCallback)((function(){l({type:16})}),[l]),A=(0,e.useCallback)((function(e){l({type:18,highlightedIndex:e})}),[l]),F=(0,e.useCallback)((function(e){l({type:19,selectedItem:e})}),[l]);return{getItemProps:N,getLabelProps:x,getMenuProps:O,getInputProps:T,getToggleButtonProps:R,toggleMenu:D,openMenu:M,closeMenu:P,setHighlightedIndex:A,setInputValue:(0,e.useCallback)((function(e){l({type:20,inputValue:e})}),[l]),selectItem:F,reset:(0,e.useCallback)((function(){l({type:21})}),[l]),highlightedIndex:d,isOpen:u,selectedItem:p,inputValue:h}}Ft.stateChangeTypes=xt,ze().array,ze().array,ze().array,ze().func,ze().number,ze().number,ze().number,ze().func,ze().func,ze().string,ze().string;const $t=(0,r.createElement)(be.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(be.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})),qt=(0,r.createElement)(be.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(be.Path,{d:"M6.5 12.4L12 8l5.5 4.4-.9 1.2L12 10l-4.5 3.6-1-1.2z"})),Bt=(0,r.createElement)(be.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(be.Path,{d:"M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"}));function Lt({rule:t,ruleMetadata:n,searchContent:a,searchResults:i,recentItems:c,isSearching:l,value:u,onSelect:d,placeholder:p,isMultiValue:h=!1,readOnly:g=!1,className:m="",currentSelectedValues:f=[]}){const[b,y]=(0,r.useState)([]),[v,_]=(0,r.useState)(!1),[w,E]=(0,r.useState)(!1),k=(0,r.useRef)(u),C=(0,r.useRef)(t);(0,r.useEffect)((()=>{u!==k.current&&(k.current=u,E(!1))}),[u]);const S=(0,r.useCallback)((e=>{const t=e.id.toString();return f.map((e=>e.toString())).includes(t)}),[f]),I=(0,r.useCallback)((e=>{if(!e)return"";const t=e.title||e.name||"";return""!==e.id&&e.id&&"searching"!==e.type?`${t} (ID: ${e.id})`:t}),[]),x=(0,r.useCallback)((()=>{if(h)return null;if("object_selector"!==n.value_type&&"hierarchical_object_selector"!==n.value_type)return null;if("author_id"===t)return null;let e=(0,o.__)("All Items","generateblocks-pro");if(t.startsWith("post:")){const n=t.replace("post:","");switch(n){case"post":e=(0,o.__)("All Posts","generateblocks-pro");break;case"page":e=(0,o.__)("All Pages","generateblocks-pro");break;default:const t=n.charAt(0).toUpperCase()+n.slice(1);e=`${(0,o.__)("All","generateblocks-pro")} ${t}`}}else t.startsWith("taxonomy:")||t.startsWith("post_terms:")?e=(0,o.__)("All Terms","generateblocks-pro"):"child_of"===t?e=(0,o.__)("Any Parent","generateblocks-pro"):"parent_of"===t&&(e=(0,o.__)("Any Child","generateblocks-pro"));return{id:"",title:e,name:e}}),[t,n.value_type,h]),O=(0,r.useCallback)((e=>{const t=x();return t&&e===(t.title||t.name)}),[x]),N=(0,r.useCallback)((()=>h?0<f.length:u&&u.trim()&&!O(u)),[h,f,u,O]),R=(0,r.useCallback)((e=>{g||(O(e)&&!w||!w?_(!1):(_(!0),a(e)))}),[a,g,O,w]),{isOpen:T,getMenuProps:D,getInputProps:P,highlightedIndex:M,getItemProps:A,selectItem:F,setHighlightedIndex:$,closeMenu:q,openMenu:B,setInputValue:L}=Ft({items:b,itemToString:e=>e?I(e):"",defaultInputValue:h?"":u,onInputValueChange:({inputValue:e,type:t})=>{t===Ft.stateChangeTypes.InputChange&&E(!0),R(e||"")},onSelectedItemChange:({selectedItem:e})=>{e&&"searching"!==e.type&&(E(!1),d(e))},onIsOpenChange:({isOpen:e})=>{e&&(_(!1),E(!1))},stateReducer:(e,t)=>{const{type:n,changes:r}=t;switch(n){case Ft.stateChangeTypes.InputKeyDownEnter:case Ft.stateChangeTypes.ItemClick:return r.selectedItem&&"searching"===r.selectedItem.type?e:{...r,inputValue:h?"":I(r.selectedItem),isOpen:h};case Ft.stateChangeTypes.InputBlur:return{...r,isOpen:!!g&&e.isOpen};case Ft.stateChangeTypes.MenuKeyDownEscape:return{...r,isOpen:!1};case Ft.stateChangeTypes.InputClick:case Ft.stateChangeTypes.InputFocus:return E(!1),_(!1),r;default:return r}}});(0,r.useEffect)((()=>{!w&&L&&L((h?"":u)||"")}),[u,w,h,L]);const V=(0,r.useCallback)((e=>{if(e.preventDefault(),e.stopPropagation(),g||h)return;const t=x();t?F(t):d({id:"",title:"",name:""})}),[g,h,x,F,d]);(0,r.useEffect)((()=>{if(t!==C.current&&(C.current=t,!h&&(!u||O(u)))){const e=x();e&&F&&setTimeout((()=>{F(e)}),0)}}),[t,h,u,x,F,O]),(0,r.useEffect)((()=>{const e=x(),t=[];l&&v&&w&&t.push({id:"searching",title:(0,o.__)("Searching…","generateblocks-pro"),name:(0,o.__)("Searching…","generateblocks-pro"),type:"searching"}),e&&t.push(e),v&&w&&0<i.length?t.push(...i):0<c.length&&t.push(...c),y(t)}),[i,c,v,w,x,l]);const Q=(0,r.useCallback)((e=>{if(!g||" "!==e.key||(e.preventDefault(),T)){if(T)switch(e.key){case"Tab":if(e.preventDefault(),e.shiftKey){const e=0>=M?b.length-1:M-1;$(e)}else{const e=b.length-1<=M?0:M+1;$(e)}break;case"Enter":e.preventDefault(),0<=M&&b[M]&&"searching"!==b[M].type&&F(b[M]);break;case"Escape":e.preventDefault(),q();break;case" ":g&&T&&(e.preventDefault(),0<=M&&b[M]&&"searching"!==b[M].type&&F(b[M]));break;case"ArrowDown":case"ArrowUp":break;default:g&&1===e.key.length&&e.preventDefault()}}else B()}),[T,M,b,$,F,q,B,g]);return(0,e.createElement)("div",{className:`gb-object-selector ${m}`},(0,e.createElement)("div",{className:"gb-combobox-container"},(0,e.createElement)("div",{className:"gb-input-wrapper"},(0,e.createElement)("input",{...P({placeholder:p,className:"components-text-control__input gb-object-search",onKeyDown:Q,"aria-expanded":T,"aria-haspopup":"listbox",tabIndex:0}),style:{cursor:g?"pointer":"text",userSelect:g?"none":"text"}}),(0,e.createElement)("div",{className:"gb-input-icons"},N()&&!g&&(0,e.createElement)(s.Button,{icon:$t,onClick:V,className:"gb-clear-button",size:"compact",label:(0,o.__)("Clear selection","generateblocks-pro"),iconSize:"16"}),0<b.length&&(0,e.createElement)("span",{className:"gb-dropdown-indicator "+(T?"gb-dropdown-indicator--open":""),"aria-hidden":"true"},T?qt:Bt))),(0,e.createElement)("ul",{...D({className:"gb-search-results",role:"listbox","aria-label":(0,o.__)("Search results","generateblocks-pro"),style:{display:T&&0<b.length?"block":"none"}})},T&&0<b.length&&(0,e.createElement)(e.Fragment,null,!g&&!v&&0<c.length&&!l&&(0,e.createElement)("li",{className:"gb-search-results-header",role:"presentation"},(0,o.__)("Recent Items","generateblocks-pro")),b.map(((t,n)=>{const r=S(t),o=M===n,a="searching"===t.type;return(0,e.createElement)("li",{key:`${t.id}-${n}`,...A({item:t,index:n,role:"option","aria-selected":r}),className:`gb-search-result-item ${o?"gb-search-result-item--highlighted":""} ${r?"gb-search-result-item--selected":""} ${a?"gb-search-result-item--searching":""}`,style:{cursor:a?"default":"pointer"}},a?(0,e.createElement)("div",{className:"gb-search-result-item__searching"},(0,e.createElement)(s.Spinner,{size:"16"}),(0,e.createElement)("span",{className:"gb-search-result-item__text"},t.title||t.name)):(0,e.createElement)(e.Fragment,null,(0,e.createElement)("span",{className:"gb-search-result-item__text"},I(t)),r&&(0,e.createElement)("span",{className:"gb-search-result-item__check","aria-hidden":"true"},"✓")))}))))))}const Vt=({condition:t,groupIndex:n,conditionIndex:a,onUpdate:i,onRemove:c,conditionTypes:l,logicOperator:u="AND",selectedObjectTitles:d,setSelectedObjectTitles:p})=>{const{getRulesForType:h,getOperatorsForType:g}=fe(),[m,f]=(0,r.useState)({}),[b,y]=(0,r.useState)({}),[v,_]=(0,r.useState)({}),[w,E]=(0,r.useState)(!1),[k,C]=(0,r.useState)([]),[S,I]=(0,r.useState)([]),[x,O]=(0,r.useState)(""),[N,R]=(0,r.useState)(!1),[T,D]=(0,r.useState)(!1),P=()=>t.type&&t.operator&&t.rule;(0,r.useEffect)((()=>{t.type&&t.operator&&t.rule&&!T&&D(!0)}),[t.type,t.operator,t.rule,T]),(0,r.useEffect)((()=>{t.type&&(async()=>{try{E(!0);const e=await h(t.type);let r;if(f(e),r=t.rule?await g(t.type,t.rule):await g(t.type),y(r),t.operator&&t.rule){const e=await g(t.type,t.rule);if(e&&!e[t.operator]){const r=Object.keys(e)[0];if(r){const e={...t,operator:r};i(n,a,e)}}}}catch(e){console.error("Error loading condition data:",e)}finally{E(!1)}})()}),[t.type,t.rule,h,g]),(0,r.useEffect)((()=>{if(t.type&&t.rule&&t.operator&&0!==Object.keys(b).length&&!b[t.operator]){const e=Object.keys(b)[0];if(e){const r={...t,operator:e};i(n,a,r)}else{const e={...t,operator:""};i(n,a,e)}}}),[t.operator,b]),(0,r.useEffect)((()=>{t.type&&t.rule?(async()=>{try{const e=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/get_rule_metadata?type=${t.type}&rule=${encodeURIComponent(t.rule)}`});e.success&&_(e.response)}catch(e){console.error("Error loading rule metadata:",e),_({needs_value:!0,value_type:"text",supports_multi:!1})}})():_({})}),[t.type,t.rule]),(0,r.useEffect)((()=>{A()?I(M()):X()&&t.rule?(async()=>{try{let e;if("hierarchical_object_selector"===v.value_type)e=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/search_hierarchical_posts"});else if("author_id"===t.rule)e=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/search_users"});else if(t.rule.startsWith("post:")){const n=t.rule.replace("post:","");e=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_posts?post_type=${n}`})}else if(t.rule.startsWith("taxonomy:")){const n=t.rule.replace("taxonomy:","");e=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_terms?taxonomy=${n}`})}else if(t.rule.startsWith("post_terms:")){const n=t.rule.replace("post_terms:","");e=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_terms?taxonomy=${n}`})}e?.success&&I(e.response)}catch(e){console.error("Error loading recent items:",e)}})():I([])}),[t.rule,v.value_type]);const M=()=>[{id:"1",name:(0,o.__)("Monday","generateblocks-pro")},{id:"2",name:(0,o.__)("Tuesday","generateblocks-pro")},{id:"3",name:(0,o.__)("Wednesday","generateblocks-pro")},{id:"4",name:(0,o.__)("Thursday","generateblocks-pro")},{id:"5",name:(0,o.__)("Friday","generateblocks-pro")},{id:"6",name:(0,o.__)("Saturday","generateblocks-pro")},{id:"7",name:(0,o.__)("Sunday","generateblocks-pro")}],A=()=>"day_selector"===v.value_type,F=()=>"datetime"===v.value_type,$=()=>"time"===v.value_type,q=()=>F()&&"between"===t.operator,B=()=>$()&&"between"===t.operator,L=()=>!!t.operator&&(W()&&G()||X()&&V()||q()||B()),V=()=>["includes_any","includes_all","excludes_any","excludes_all"].includes(t.operator),Q=()=>(e=>{if(!e)return[];if(Array.isArray(e))return e;try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch(e){}return[e]})(t.value),j=e=>{if(!e)return null;const t=new Date(e);return isNaN(t.getTime())?null:t},z=e=>e?("string"==typeof e&&(e=new Date(e)),isNaN(e.getTime())?"":`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`):"",H=()=>{if(!q()||!t.value)return null;const e=t.value.split(",").map((e=>e.trim()));return j(e[0])},K=()=>{if(!q()||!t.value)return null;const e=t.value.split(",").map((e=>e.trim()));return j(e[1])},U=(e,t)=>{const n=[e?z(e):"",t?z(t):""].filter((e=>e)).join(", ");ne("value",n)},W=()=>"custom_field"===v.value_type,G=()=>!!W()&&["equals","contains","not_contains","starts_with","ends_with","greater_than","less_than"].includes(t.operator),Y=()=>W()&&t.value?t.value.includes("|")?t.value.split("|")[0]:t.value:"",J=()=>W()&&t.value&&t.value.includes("|")&&t.value.split("|")[1]||"",Z=(e,t="")=>{let n=e;t&&G()&&(n=`${e}|${t}`),ne("value",n)},X=()=>"object_selector"===v.value_type||"hierarchical_object_selector"===v.value_type||"day_selector"===v.value_type,ee=()=>{switch(v.value_type){case"custom_field":return"query_arg"===t.type?(0,o.__)("Parameter name","generateblocks-pro"):"post_meta"===t.type?(0,o.__)("Meta key","generateblocks-pro"):(0,o.__)("Field name","generateblocks-pro");case"datetime":return(0,o.__)("Select date and time","generateblocks-pro");case"time":return(0,o.__)("Select time","generateblocks-pro");case"day_selector":return V()?(0,o.__)("Select days…","generateblocks-pro"):(0,o.__)("Select day…","generateblocks-pro");case"hierarchical_object_selector":return"child_of"===t.rule?V()?(0,o.__)("Select parent posts (or leave empty for any parent)","generateblocks-pro"):(0,o.__)("Any Parent (or search for specific)","generateblocks-pro"):"parent_of"===t.rule?V()?(0,o.__)("Select child posts (or leave empty for any child)","generateblocks-pro"):(0,o.__)("Any Child (or search for specific)","generateblocks-pro"):V()?(0,o.__)("Select multiple…","generateblocks-pro"):(0,o.__)("Search or select…","generateblocks-pro");case"object_selector":if("author_id"===t.rule)return V()?(0,o.__)("Select multiple authors…","generateblocks-pro"):(0,o.__)("Select author…","generateblocks-pro");if("location"===t.type&&t.rule.startsWith("post:")){const e=t.rule.replace("post:","");switch(e){case"post":return V()?(0,o.__)("Select multiple posts…","generateblocks-pro"):(0,o.__)("All Posts (or search for specific)","generateblocks-pro");case"page":return V()?(0,o.__)("Select multiple pages…","generateblocks-pro"):(0,o.__)("All Pages (or search for specific)","generateblocks-pro");default:const t=e.charAt(0).toUpperCase()+e.slice(1);return V()?`${(0,o.__)("Select multiple","generateblocks-pro")} ${t}...`:`${(0,o.__)("All","generateblocks-pro")} ${t} (${(0,o.__)("or search for specific","generateblocks-pro")})`}}return V()?(0,o.__)("Select multiple…","generateblocks-pro"):(0,o.__)("Search or select…","generateblocks-pro");default:return"referrer"===t.type?(0,o.__)("Referrer URL or domain","generateblocks-pro"):(0,o.__)("Value","generateblocks-pro")}},te=(0,r.useCallback)((async e=>{if(A())return C([]),void R(!1);if(!t.rule||!e)return C([]),void R(!1);try{let n;R(!0);const r=/^\d+$/.test(e.trim()),s=new URLSearchParams;if("hierarchical_object_selector"===v.value_type)r?s.set("id",e.trim()):s.set("search",e),n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_hierarchical_posts?${s.toString()}`});else if("author_id"===t.rule)r?s.set("id",e.trim()):s.set("search",e),n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_users?${s.toString()}`});else if(t.rule.startsWith("post:")){const o=t.rule.replace("post:","");s.set("post_type",o),r?s.set("id",e.trim()):s.set("search",e),n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_posts?${s.toString()}`})}else if(t.rule.startsWith("taxonomy:")){const o=t.rule.replace("taxonomy:","");s.set("taxonomy",o),r?s.set("id",e.trim()):s.set("search",e),n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_terms?${s.toString()}`})}else if(t.rule.startsWith("post_terms:")){const o=t.rule.replace("post_terms:","");s.set("taxonomy",o),r?s.set("id",e.trim()):s.set("search",e),n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_terms?${s.toString()}`})}n?.success&&C(n.response)}catch(e){console.error("Error searching content:",e)}finally{R(!1)}}),[t.rule,v.value_type]),ne=(e,r)=>{D(!0);const s={...t,[e]:r};if("type"===e){if(s.rule="",s.operator="",s.value="",r){const e={location:{operator:"is",rule:"general:front_page"},user_role:{operator:"is",rule:"general:logged_in"},date_time:{operator:"after",rule:"current_date"},device:{operator:"is",rule:"mobile"},query_arg:{operator:"exists",rule:"custom"},referrer:{operator:"contains",rule:"custom"},post_meta:{operator:"exists",rule:"custom"},user_meta:{operator:"exists",rule:"custom"},cookie:{operator:"exists",rule:"custom"},language:{operator:"is",rule:"locale"},options:{operator:"equals",rule:"custom"},author:{operator:"is",rule:"author_id"}}[r]||{operator:null,rule:null};e.operator&&(s.operator=e.operator),e.rule&&(s.rule=e.rule)}}else"operator"===e?V()!==["includes_any","includes_all","excludes_any","excludes_all"].includes(r)&&(s.value=""):"rule"===e&&(s.value="",p((e=>{const t={...e};return delete t[`${n}-${a}`],Object.keys(t).forEach((e=>{e.startsWith(`${n}-${a}-`)&&delete t[e]})),t})));i(n,a,s)};return(0,e.createElement)("div",{className:(()=>{let e="gb-condition-row";return T&&P()?e+=" gb-condition-complete":T&&!P()&&(e+=" gb-condition-incomplete"),e})()},(0,e.createElement)("div",{className:"gb-condition-row-main"},0===a?(0,e.createElement)("div",{className:"gb-logic-label"},(0,e.createElement)("span",{className:`gb-logic-operator gb-logic-${u.toLowerCase()}`},"IF")):(0,e.createElement)("div",{className:"gb-logic-label"},(0,e.createElement)("span",{className:`gb-logic-operator gb-logic-${u.toLowerCase()}`},u)),(0,e.createElement)("div",{className:"gb-condition-fields"},(0,e.createElement)(s.SelectControl,{value:t.type,onChange:e=>ne("type",e),options:[{label:(0,o.__)("Select type…","generateblocks-pro"),value:""},...Object.entries(l).sort((([,e],[,t])=>e.label.localeCompare(t.label))).map((([e,t])=>({label:t.label,value:e})))],className:"gb-condition-type",__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),w&&(0,e.createElement)(s.Spinner,null),t.type&&!w&&(0,e.createElement)(s.SelectControl,{value:t.operator,onChange:e=>ne("operator",e),options:[{label:(0,o.__)("Select operator…","generateblocks-pro"),value:""},...Object.entries(b).map((([e,t])=>({label:t,value:e})))],className:"gb-condition-operator",disabled:w,__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),t.type&&!w&&(0,e.createElement)(s.SelectControl,{value:t.rule,onChange:e=>ne("rule",e),options:[{label:(0,o.__)("Select rule…","generateblocks-pro"),value:""},...Object.entries(m).filter((([e])=>"date_time"!==t.type||"time_of_day"!==e||"time_of_day"===t.rule)).map((([e,t])=>({label:t,value:e})))],className:"gb-condition-rule",__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),t.rule&&t.operator&&!L()&&(0,e.createElement)(e.Fragment,null,W()&&!G()&&(0,e.createElement)(s.TextControl,{value:Y(),onChange:e=>Z(e),placeholder:ee(),className:"gb-condition-value",__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),!(!t.operator||["exists","not_exists"].includes(t.operator))&&(void 0===v.needs_value||v.needs_value)&&!W()&&!X()&&!F()&&!$()&&(0,e.createElement)(s.TextControl,{value:t.value||"",onChange:e=>ne("value",e),placeholder:ee(),className:"gb-condition-value",__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),F()&&!q()&&(0,e.createElement)(Be,{currentDate:F()&&t.value&&!q()?j(t.value):null,onChange:e=>{const t=z(e);ne("value",t)},placeholder:ee()}),$()&&!B()&&(0,e.createElement)(Le,{currentTime:t.value||"",onChange:e=>ne("value",e),placeholder:ee()}),X()&&!V()&&(0,e.createElement)(Lt,{rule:t.rule,ruleMetadata:v,searchContent:te,searchResults:k,recentItems:S,isSearching:N,value:(()=>{let e=d[`${n}-${a}`];if(!e&&t.value&&t.value.trim()){const r=`${n}-${a}-${t.value.trim()}`;e=d[r]}if(e)return t.value&&t.value.trim()&&!e.startsWith("ID: ")?`${e} (ID: ${t.value.trim()})`:e;if(!t.value||""===t.value){if("author_id"===t.rule)return"";if(t.rule.startsWith("post:")){const e=t.rule.replace("post:","");switch(e){case"post":return(0,o.__)("All Posts","generateblocks-pro");case"page":return(0,o.__)("All Pages","generateblocks-pro");default:const t=e.charAt(0).toUpperCase()+e.slice(1);return`${(0,o.__)("All","generateblocks-pro")} ${t}`}}else{if(t.rule.startsWith("taxonomy:")||t.rule.startsWith("post_terms:"))return(0,o.__)("All Terms","generateblocks-pro");if("child_of"===t.rule)return(0,o.__)("Any Parent","generateblocks-pro");if("parent_of"===t.rule)return(0,o.__)("Any Child","generateblocks-pro")}return(0,o.__)("All Items","generateblocks-pro")}return t.value&&t.value.trim()?`ID: ${t.value.trim()}`:""})(),onSelect:e=>{ne("value",e.id.toString()),p((t=>({...t,[`${n}-${a}`]:e.title||e.name}))),C([])},placeholder:ee(),isMultiValue:!1,readOnly:A(),className:"gb-inline-selector",currentSelectedValues:[t.value||""]}))),(0,e.createElement)(s.Button,{isDestructive:!0,variant:"tertiary",icon:Ce,onClick:()=>c(n,a),className:"gb-remove-condition",label:(0,o.__)("Remove condition","generateblocks-pro"),size:"compact",iconSize:"16"})),t.rule&&t.operator&&L()&&(0,e.createElement)("div",{className:"gb-condition-expansion"},W()&&G()&&(0,e.createElement)("div",{className:"gb-custom-field-expansion"},(0,e.createElement)("div",{className:"gb-custom-field-inputs"},(0,e.createElement)(s.TextControl,{value:Y(),onChange:e=>Z(e,J()),label:ee(),className:"gb-condition-custom-field"}),(0,e.createElement)(s.TextControl,{value:J(),onChange:e=>Z(Y(),e),label:(0,o.__)("Value to compare","generateblocks-pro"),className:"gb-condition-comparison-value"}))),q()&&(0,e.createElement)("div",{className:"gb-date-range-expansion"},(0,e.createElement)("div",{className:"gb-date-range-inputs"},(0,e.createElement)("div",{className:"gb-datetime-picker-field"},(0,e.createElement)("div",{className:"components-base-control__label"},(0,o.__)("Start Date & Time","generateblocks-pro")),(0,e.createElement)(Be,{currentDate:H(),onChange:e=>U(e,K()),placeholder:(0,o.__)("Select start date…","generateblocks-pro")})),(0,e.createElement)("div",{className:"gb-datetime-picker-field"},(0,e.createElement)("div",{className:"components-base-control__label"},(0,o.__)("End Date & Time","generateblocks-pro")),(0,e.createElement)(Be,{currentDate:K(),onChange:e=>U(H(),e),placeholder:(0,o.__)("Select end date…","generateblocks-pro")})))),B()&&(0,e.createElement)("div",{className:"gb-time-range-expansion"},(0,e.createElement)("div",{className:"gb-time-range-inputs"},(0,e.createElement)("div",{className:"gb-time-picker-field"},(0,e.createElement)("div",{className:"components-base-control__label"},(0,o.__)("Start Time","generateblocks-pro")),(0,e.createElement)(Le,{currentTime:t.value?t.value.split(",")[0]?.trim():"",onChange:e=>{const n=t.value?t.value.split(",")[1]?.trim():"";ne("value",e&&n?`${e}, ${n}`:e||"")},placeholder:(0,o.__)("Select start time…","generateblocks-pro")})),(0,e.createElement)("div",{className:"gb-time-picker-field"},(0,e.createElement)("div",{className:"components-base-control__label"},(0,o.__)("End Time","generateblocks-pro")),(0,e.createElement)(Le,{currentTime:t.value?t.value.split(",")[1]?.trim():"",onChange:e=>{const n=t.value?t.value.split(",")[0]?.trim():"";ne("value",n&&e?`${n}, ${e}`:e||"")},placeholder:(0,o.__)("Select end time…","generateblocks-pro")})))),X()&&V()&&(0,e.createElement)("div",{className:"gb-multi-select-expansion"},(0,e.createElement)("div",{className:"gb-multi-object-selector"},(0,e.createElement)("div",{className:"gb-selected-items"},0===Q().length?(0,e.createElement)("div",{className:"gb-empty-selection"},(0,e.createElement)("span",null,(0,o.__)("No items selected","generateblocks-pro"))):Q().map((t=>{const r=d[`${n}-${a}-${t}`]||`ID: ${t}`;return(0,e.createElement)("div",{key:t,className:"gb-selected-item"},(0,e.createElement)("span",null,r),(0,e.createElement)(s.Button,{icon:$e,onClick:()=>(e=>{const t=Q().filter((t=>t!==e));ne("value",t.length>0?JSON.stringify(t):""),p((t=>{const r={...t};return delete r[`${n}-${a}-${e}`],r}))})(t),className:"gb-remove-selected-item",size:"compact",iconSize:"12",label:(0,o.__)("Remove item","generateblocks-pro")}))}))),(0,e.createElement)(Lt,{rule:t.rule,ruleMetadata:v,searchContent:te,searchResults:k,recentItems:S,isSearching:N,value:x,onSelect:e=>{const t=Q(),r=e.id.toString();if(!t.includes(r)){const s=[...t,r];ne("value",JSON.stringify(s)),p((t=>({...t,[`${n}-${a}-${r}`]:e.title||e.name})))}O(""),C([])},placeholder:A()?(0,o.__)("Click to select days…","generateblocks-pro"):(0,o.__)("Search to add items…","generateblocks-pro"),isMultiValue:!0,readOnly:A(),className:"",currentSelectedValues:Q()})))))};function Qt(e){if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Qt);if("object"==typeof e){const t={};for(const n in e)e.hasOwnProperty(n)&&(t[n]=Qt(e[n]));return t}return e}function jt(e,t){if(e===t)return!0;if(null===e||null===t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const s of n){if(!r.includes(s))return!1;if(!jt(e[s],t[s]))return!1}return!0}function zt({onNavigateBack:t,onSave:n=null,initialConditions:a=null,initialTitle:i="",conditionId:c=null,isNew:l=!1,onUnsavedChanges:u=null}){const{conditionTypes:d,loading:p}=fe(),h=re({mutationFn:async({title:e,conditions:t,category:n,status:r})=>{let s;s=n?Array.isArray(n)?n:[n]:[];const o=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/conditions/",method:"POST",data:{title:e,conditions:t||{logic:"OR",groups:[]},category:s.length>0?s:"",status:r||"publish"}});if(o.success)return o.response;throw new Error("Failed to create condition")},onSuccess:()=>{me()}}),g=re({mutationFn:async({id:e,title:t,conditions:n,category:r,status:s})=>{let o;o=r?Array.isArray(r)?r:[r]:[];const a=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/${e}`,method:"PUT",data:{title:t,category:o.length>0?o:"",conditions:n,status:s}});if(a.success)return a.response;throw new Error("Failed to update condition")},onSuccess:()=>{me()}}),m=(0,r.useRef)(null),f=!!c&&!l,b=(0,r.useMemo)((()=>({conditions:a?.groups?.length>0?Qt(a):{logic:"OR",groups:[{logic:"AND",conditions:[{type:"",rule:"",operator:"",value:""}]}]},conditionTitle:i||"",selectedObjectTitles:{},isSaving:!1})),[a,i]),[y,v]=(0,r.useState)(b.conditions),[_,w]=(0,r.useState)(b.conditionTitle),[E,k]=(0,r.useState)(""),[C,S]=(0,r.useState)("publish"),[I,x]=(0,r.useState)([]),[O,N]=(0,r.useState)(!1),[R,T]=(0,r.useState)(b.selectedObjectTitles),[D,P]=(0,r.useState)(b.isSaving),[M,A]=(0,r.useState)(null),[F,$]=(0,r.useState)(null);(0,r.useEffect)((()=>{v(a?.groups?.length>0?Qt(a):{logic:"OR",groups:[{logic:"AND",conditions:[{type:"",rule:"",operator:"",value:""}]}]}),w(i||""),T({})}),[a,i]),(0,r.useEffect)((()=>{f&&c&&(async()=>{try{const e=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/${c}`});if(e?.success){if(e.response?.gblocks_condition_cat?.length>0){const t=e.response.gblocks_condition_cat[0],n=await oe()({path:`/wp/v2/condition-categories/${t}`});n&&n.slug&&k(n.slug)}e.response?.status&&(S(e.response.status),$((t=>({...t,conditionStatus:e.response.status}))))}}catch(e){}})()}),[f,c]),(0,r.useEffect)((()=>{(async()=>{try{const e=await oe()({path:"/wp/v2/condition-categories"});e&&x(e)}catch(e){}})()}),[]),(0,r.useEffect)((()=>{v(b.conditions),w(b.conditionTitle),T(b.selectedObjectTitles),P(b.isSaving),A(null),$({conditions:Qt(b.conditions),conditionTitle:b.conditionTitle,conditionStatus:"publish"})}),[b]);const q=(0,r.useMemo)((()=>!!F&&!jt({conditions:y,conditionTitle:_,conditionStatus:C},F)),[y,_,C,F]);(0,r.useEffect)((()=>{u&&u(q);const e=new CustomEvent("gb-conditions-unsaved-changes",{detail:{hasUnsavedChanges:q}});window.dispatchEvent(e)}),[q,u]),(0,r.useEffect)((()=>{if(!q)return;const e=e=>(e.preventDefault(),e.returnValue=(0,o.__)("You have unsaved changes. Are you sure you want to leave?","generateblocks-pro"),e.returnValue);return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}}),[q]),(0,r.useEffect)((()=>{y.groups&&(m.current&&m.current.abort(),(async()=>{m.current=new AbortController;try{await B(m.current.signal)}catch(e){"AbortError"!==e.name&&console.debug("Title loading failed:",e)}})())}),[y.groups]),(0,r.useEffect)((()=>()=>{m.current&&m.current.abort()}),[]);const B=async e=>{const t={};for(let n=0;n<y.groups.length;n++){const r=y.groups[n];for(let s=0;s<r.conditions.length;s++){const o=r.conditions[s];if(e?.aborted)throw new Error("AbortError");if(!o.rule||!o.value)continue;const a=L(o.value);if(0!==a.length)if("date_time"!==o.type||"day_of_week"!==o.rule){if(o.rule.startsWith("post:")||o.rule.startsWith("taxonomy:")||o.rule.startsWith("post_terms:")||"child_of"===o.rule||"parent_of"===o.rule||"author_id"===o.rule)for(const r of a){if(!r)continue;if(e?.aborted)throw new Error("AbortError");const a=["includes_any","includes_all","excludes_any","excludes_all"].includes(o.operator)?`${n}-${s}-${r}`:`${n}-${s}`;if(t[a])continue;let i=null;if("author_id"===o.rule)i=await H(r,e);else if("child_of"===o.rule||"parent_of"===o.rule)i=await z(r,e);else if(o.rule.startsWith("post:")){const t=o.rule.replace("post:","");i=await Q(r,t,e)}else if(o.rule.startsWith("taxonomy:")||o.rule.startsWith("post_terms:")){let t;t=o.rule.startsWith("taxonomy:")?o.rule.replace("taxonomy:",""):o.rule.replace("post_terms:",""),i=await j(r,t,e)}t[a]=i||`ID: ${r}`}}else for(const e of a)t[["includes_any","includes_all","excludes_any","excludes_all"].includes(o.operator)?`${n}-${s}-${e}`:`${n}-${s}`]=V(e)}}T(t)},L=e=>{if(!e)return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch(e){}return[e]},V=e=>({1:(0,o.__)("Monday","generateblocks-pro"),2:(0,o.__)("Tuesday","generateblocks-pro"),3:(0,o.__)("Wednesday","generateblocks-pro"),4:(0,o.__)("Thursday","generateblocks-pro"),5:(0,o.__)("Friday","generateblocks-pro"),6:(0,o.__)("Saturday","generateblocks-pro"),7:(0,o.__)("Sunday","generateblocks-pro")}[e]||e),Q=async(e,t,n=null)=>{try{const r=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_posts?post_type=${t}`,signal:n});if(r?.success&&r.response){const t=r.response.find((t=>t.id.toString()===e.toString()));if(t)return t.title}const s=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_posts?post_type=${t}&id=${encodeURIComponent(e)}`,signal:n});if(s?.success&&s.response){const t=s.response.find((t=>t.id.toString()===e.toString()));if(t)return t.title}}catch(n){if("AbortError"===n.name)throw n;console.debug("Could not fetch post title for ID:",e,"Type:",t,n)}return null},j=async(e,t,n=null)=>{try{const r=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_terms?taxonomy=${t}`,signal:n});if(r?.success&&r.response){const t=r.response.find((t=>t.id.toString()===e.toString()));if(t)return t.name}const s=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_terms?taxonomy=${t}&id=${encodeURIComponent(e)}`,signal:n});if(s?.success&&s.response){const t=s.response.find((t=>t.id.toString()===e.toString()));if(t)return t.name}}catch(n){if("AbortError"===n.name)throw n;console.debug("Could not fetch term name for ID:",e,"Taxonomy:",t,n)}return null},z=async(e,t=null)=>{try{const n=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/search_hierarchical_posts",signal:t});if(n?.success&&n.response){const t=n.response.find((t=>t.id.toString()===e.toString()));if(t)return t.title.replace(/^(—\s*)+/,"")}const r=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_hierarchical_posts?id=${encodeURIComponent(e)}`,signal:t});if(r?.success&&r.response){const t=r.response.find((t=>t.id.toString()===e.toString()));if(t)return t.title.replace(/^(—\s*)+/,"")}}catch(t){if("AbortError"===t.name)throw t;console.debug("Could not fetch hierarchical post title for ID:",e,t)}return null},H=async(e,t=null)=>{try{const n=await oe()({path:"/generateblocks-pro/advanced-conditions/v1/search_users",signal:t});if(n?.success&&n.response){const t=n.response.find((t=>t.id.toString()===e.toString()));if(t)return t.name||t.title}const r=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/search_users?id=${encodeURIComponent(e)}`,signal:t});if(r?.success&&r.response){const t=r.response.find((t=>t.id.toString()===e.toString()));if(t)return t.name||t.title}}catch(t){if("AbortError"===t.name)throw t;console.debug("Could not fetch user name for ID:",e,t)}return null},K=(e,t,n)=>{v((r=>{const s={...r};return s.groups[e].conditions[t]=n,s}))},U=(e,t)=>{v((n=>({...n,groups:n.groups.map(((n,r)=>{if(r!==e)return n;const s=n.conditions.filter(((e,n)=>n!==t));return{...n,conditions:s}})).filter((e=>0<e.conditions.length))})))},W=async(e,t)=>{try{let r;if(r=f?await g.mutateAsync({id:c,title:e,conditions:t,category:E,status:C}):await h.mutateAsync({title:e,conditions:t,category:E,status:C}),!r)throw new Error("Failed to save condition");n&&n({id:r.id||c,title:e,conditions:t,isNew:!f})}catch(e){throw console.error("Error saving condition:",e),A((0,o.__)("Failed to save condition. Please try again.","generateblocks-pro")),e}},G=!l||_.trim();return(0,e.createElement)("div",{className:"gb-conditions-editor"},(0,e.createElement)("div",{className:"gb-conditions-editor-header"},(0,e.createElement)("div",{className:"gb-conditions-title-section"},(0,e.createElement)(s.TextControl,{label:(0,o.__)("Condition Name","generateblocks-pro"),value:_,onChange:w,placeholder:(0,o.__)("Enter condition name…","generateblocks-pro"),className:"gb-condition-title-input",disabled:D,hideLabelFromVision:!0}),(0,e.createElement)(s.SelectControl,{label:(0,o.__)("Category","generateblocks-pro"),value:E,onChange:e=>{"new"===e?N(!0):k(e)},options:[{label:(0,o.__)("No category","generateblocks-pro"),value:""},...I.map((e=>({label:(0,Se.decodeEntities)(e.name),value:e.slug}))),{label:(0,o.__)("+ Add new category","generateblocks-pro"),value:"new"}],className:"gb-condition-category-select",disabled:D,hideLabelFromVision:!0,__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0})),(0,e.createElement)("div",{className:"gb-conditions-header-actions"},(0,e.createElement)(s.SelectControl,{label:(0,o.__)("Status","generateblocks-pro"),value:C,onChange:S,options:[{label:(0,o.__)("Published","generateblocks-pro"),value:"publish"},{label:(0,o.__)("Draft","generateblocks-pro"),value:"draft"}],className:"gb-condition-status-select",disabled:D,hideLabelFromVision:!0,__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),(0,e.createElement)(s.Button,{variant:"secondary",onClick:()=>{if(q){const e=(0,o.__)("You have unsaved changes. Are you sure you want to go back without saving?","generateblocks-pro");if(!window.confirm(e))return}t()},disabled:D},(0,o.__)("Cancel","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"primary",onClick:async()=>{try{if(A(null),!_.trim())return void A((0,o.__)("Please enter a condition name.","generateblocks-pro"));const e=(e=>{const t=[];return e.groups&&0!==e.groups.length?(e.groups.forEach(((e,n)=>{e.conditions&&0!==e.conditions.length?e.conditions.filter((e=>e.type)).forEach((r=>{const s=e.conditions.indexOf(r)+1,a=(0,o.sprintf)(
// translators: %1$s is the condition number (1-based index), %2$s is the group number (1-based index).
// translators: %1$s is the condition number (1-based index), %2$s is the group number (1-based index).
(0,o.__)("Condition %1$s in Group %2$s","generateblocks-pro"),s,n+1);r.operator||t.push(`${a}: ${(0,o.__)("Please select an operator.","generateblocks-pro")}`),r.rule||t.push(`${a}: ${(0,o.__)("Please select a rule.","generateblocks-pro")}`)})):t.push((0,o.sprintf)(
// translators: %d is the group number (1-based index).
// translators: %d is the group number (1-based index).
(0,o.__)("Group %d has no conditions.","generateblocks-pro"),n+1))})),{isValid:0===t.length,errors:t}):{isValid:!0,errors:[]}})(y);if(!e.isValid){const t=(0,o.__)("Please complete the following:","generateblocks-pro")+"\n\n"+e.errors.join("\n");return void A(t)}if(!y.groups||0===y.groups.length)return void await W(_,{logic:"OR",groups:[]});P(!0);const t=(e=>{if(!e.groups)return e;const t=e.groups.map((e=>({...e,conditions:e.conditions.filter((e=>!!(e.type&&e.operator&&e.rule)||(e.type||e.operator||e.rule||e.value,!1)))}))).filter((e=>e.conditions.length>0));return{...e,groups:t}})(y);if(!(await oe()({path:"/generateblocks-pro/advanced-conditions/v1/validate_conditions",method:"POST",data:{conditions:t}})).success)return void A((0,o.__)("Condition validation failed. Please check your configuration and try again.","generateblocks-pro"));await W(_,t)}catch(e){console.error("Error saving condition:",e);let t=(0,o.__)("Failed to save condition. Please try again.","generateblocks-pro");e.message&&e.message.includes("validation")&&(t=(0,o.__)("Condition validation failed. Please check that all fields are properly filled out.","generateblocks-pro")),A(t)}finally{P(!1)}},disabled:!_.trim()||D,isBusy:D},D?(0,o.__)("Saving…","generateblocks-pro"):(0,o.__)("Save Conditions","generateblocks-pro")))),(0,e.createElement)("div",{className:"gb-conditions-content"},q&&(0,e.createElement)(s.Notice,{status:"info",isDismissible:!1,className:"gb-conditions-unsaved-notice"},(0,o.__)("You have unsaved changes.","generateblocks-pro")),!!M&&(0,e.createElement)(s.Notice,{status:"error",isDismissible:!1,className:"gb-conditions-error-notice"},(0,e.createElement)("div",{style:{whiteSpace:"pre-line"}},M)),p?(0,e.createElement)("div",{className:"gb-loading"},(0,e.createElement)(s.Spinner,null),(0,e.createElement)("p",null,(0,o.__)("Loading condition types…","generateblocks-pro"))):(0,e.createElement)(e.Fragment,null,G&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"gb-conditions-groups"},y.groups&&0<y.groups.length?y.groups.map(((t,n)=>(0,e.createElement)("div",{key:n,className:"gb-condition-group"},(0,e.createElement)("div",{className:"gb-group-header"},(0,e.createElement)("div",{className:"gb-group-logic"},(0,e.createElement)("span",{className:"gb-group-label"},(0,o.__)("Group Logic","generateblocks-pro")),(0,e.createElement)(s.SelectControl,{value:t.logic,onChange:e=>((e,t)=>{v((n=>{const r={...n};return r.groups[e].logic=t,r}))})(n,e),options:[{label:(0,o.__)("AND","generateblocks-pro"),value:"AND"},{label:(0,o.__)("OR","generateblocks-pro"),value:"OR"}],className:"gb-group-logic-select",disabled:D,__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0})),1<y.groups.length&&(0,e.createElement)(s.Button,{isDestructive:!0,variant:"tertiary",icon:Ce,onClick:()=>(e=>{v((t=>({...t,groups:t.groups.filter(((t,n)=>n!==e))})))})(n),className:"gb-remove-group",label:(0,o.__)("Remove group","generateblocks-pro"),size:"compact",iconSize:"16",disabled:D})),(0,e.createElement)("div",{className:"gb-group-conditions"},t.conditions.map(((r,s)=>(0,e.createElement)(Vt,{key:s,condition:r,groupIndex:n,conditionIndex:s,onUpdate:K,onRemove:U,conditionTypes:d,logicOperator:t.logic,selectedObjectTitles:R,setSelectedObjectTitles:T})))),(0,e.createElement)(s.Button,{variant:"secondary",icon:De,onClick:()=>(e=>{v((t=>({...t,groups:t.groups.map(((t,n)=>n===e?{...t,conditions:[...t.conditions,{type:"",rule:"",operator:"",value:""}]}:t))})))})(n),className:"gb-add-condition",disabled:D},(0,o.__)("Add","generateblocks-pro")," ",t.logic.toUpperCase()," ",(0,o.__)("condition","generateblocks-pro"))))):(0,e.createElement)("div",{className:"gb-no-conditions"},(0,e.createElement)("p",null,(0,o.__)("No conditions set","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"primary",icon:De,onClick:()=>{v({logic:"OR",groups:[{logic:"AND",conditions:[{type:"",rule:"",operator:"",value:""}]}]})},disabled:D},(0,o.__)("Add first condition","generateblocks-pro")))),y.groups&&0===y.groups.length&&G&&(0,e.createElement)("div",{className:"gb-conditions-help-text"},(0,e.createElement)("p",null,(0,o.__)("Create your first condition to control when this content should appear.","generateblocks-pro"))),y.groups&&0<y.groups.length&&(0,e.createElement)(s.Button,{variant:"tertiary",icon:De,onClick:()=>{v((e=>({...e,logic:e.logic||"OR",groups:[...e.groups,{logic:"AND",conditions:[{type:"",rule:"",operator:"",value:""}]}]})))},className:"gb-add-group",disabled:D},"AND"===(y.logic||"OR")?(0,o.__)("Add AND condition group","generateblocks-pro"):(0,o.__)("Add OR condition group","generateblocks-pro")),y.groups&&1<y.groups.length&&(0,e.createElement)("div",{className:"gb-top-level-logic"},(0,e.createElement)(s.SelectControl,{label:(0,o.__)("How should these condition groups be combined?","generateblocks-pro"),value:y.logic||"OR",onChange:e=>{v((t=>({...t,logic:e})))},options:[{label:(0,o.__)("OR - Show if ANY group matches","generateblocks-pro"),value:"OR"},{label:(0,o.__)("AND - Show only if ALL groups match","generateblocks-pro"),value:"AND"}],help:"OR"===(y.logic||"OR")?(0,o.__)("Content will show if any condition group is satisfied.","generateblocks-pro"):(0,o.__)("Content will show only if all condition groups are satisfied.","generateblocks-pro"),disabled:D,__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0})),(0,e.createElement)(Ae,{conditions:y,onConditionsImport:e=>{v(e)}})),l&&!_.trim()&&(0,e.createElement)("div",{className:"gb-conditions-help-text"},(0,e.createElement)("p",null,(0,o.__)("Enter a condition name above to start building your conditions.","generateblocks-pro"))))),(0,e.createElement)(Fe,{isOpen:O,onClose:()=>N(!1),onCreateCategory:async({name:e,slug:t})=>{try{await oe()({path:"/wp/v2/condition-categories",method:"POST",data:{name:e,slug:t}})&&(x([...I,{name:e,slug:t}]),k(t))}catch(e){throw e}}}))}function Ht(t){return(0,e.createElement)(Y,{client:ge()},(0,e.createElement)(zt,{...t}))}function Kt({category:t,updateCategory:n,saving:a}){const[i,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)((0,Se.decodeEntities)(t.name)),[d,p]=(0,r.useState)(!1),h=async()=>{p(!0),await n(t.id,l),p(!1),c(!1)},g=()=>{c(!1),u((0,Se.decodeEntities)(t.name))};return i&&!t.isUncategorized?(0,e.createElement)("div",{className:"gb-edit-taxonomy-form"},(0,e.createElement)(s.TextControl,{value:l,onChange:u,disabled:d||a,onKeyDown:e=>{"Enter"===e.key?h():"Escape"===e.key&&g()},__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),(0,e.createElement)("div",{className:"gb-edit-actions"},(0,e.createElement)(s.Button,{variant:"primary",size:"small",onClick:h,disabled:!l.trim()||d||a,isBusy:d||a,__next40pxDefaultSize:!0},(0,o.__)("Save","generateblocks-pro")),(0,e.createElement)(s.Button,{variant:"secondary",size:"small",onClick:g,disabled:d||a,__next40pxDefaultSize:!0},(0,o.__)("Cancel","generateblocks-pro")))):(0,e.createElement)("div",{style:{display:"flex",alignItems:"center",gap:"10px"}},(0,e.createElement)("strong",{className:t.isUncategorized?"gb-uncategorized-label":""},(0,Se.decodeEntities)(t.name)),!t.isUncategorized&&(0,e.createElement)(s.Button,{icon:Oe,size:"small",onClick:()=>{c(!0),u((0,Se.decodeEntities)(t.name))},label:(0,o.__)("Edit category name","generateblocks-pro"),style:{visibility:"hidden"},className:"gb-taxonomy-edit-button"}))}function Ut({taxonomyConfig:t={slug:"",restBase:"",labels:{singular:"Category",plural:"Categories",uncategorized:"Uncategorized",itemsCount:"items"}},itemsEndpoint:n,itemsTaxonomyField:a,manageEndpoint:i,onNavigateBack:c,onTaxonomyChange:l}){const[u,d]=(0,r.useState)([]),[p,h]=(0,r.useState)(!1),[g,m]=(0,r.useState)(!1),[f,b]=(0,r.useState)(null),[y,v]=(0,r.useState)(""),{labels:_={},restBase:w}=t;(0,r.useEffect)((()=>{E()}),[]);const E=async()=>{h(!0),b(null);try{const e=[oe()({path:`/wp/v2/${w}`})];n&&e.push(oe()({path:`${n}?per_page=100`}));const t=await Promise.all(e),r=t[0],s=t[1];if(r){let e=[...r];if(s?.success&&a){const t=(s.response?.[Object.keys(s.response)[0]]||[]).filter((e=>!e[a]||0===e[a].length)).length;e=[{id:"uncategorized",name:_.uncategorized||(0,o.__)("Uncategorized","generateblocks-pro"),slug:"",count:t,isUncategorized:!0},...r]}d(e)}}catch(e){b((0,o.__)("Failed to load categories.","generateblocks-pro"))}finally{h(!1)}},k=async()=>{if(y.trim()){m(!0),b(null);try{const e=y.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-");(await oe()({path:i,method:"POST",data:{name:y.trim(),slug:e}})).success&&(await E(),v(""),l&&l())}catch(e){b((0,o.__)("Failed to create category.","generateblocks-pro"))}finally{m(!1)}}},C=async(e,t)=>{if(t.trim()){m(!0),b(null);try{(await oe()({path:`${i}/${e}`,method:"POST",data:{name:t.trim()}})).success&&(await E(),l&&l())}catch(e){b((0,o.__)("Failed to update category.","generateblocks-pro"))}finally{m(!1)}}},S=async e=>{const t=_.singular?.toLowerCase()||"category",n=(0,o.sprintf)(/* translators: %1$s: singular taxonomy label, %2$s: singular taxonomy label */ /* translators: %1$s: singular taxonomy label, %2$s: singular taxonomy label */
(0,o.__)("Are you sure you want to delete this %1$s? Items using this %2$s will become uncategorized.","generateblocks-pro"),t,t);if(confirm(n)){m(!0),b(null);try{(await oe()({path:`${i}/${e}`,method:"DELETE"})).success&&(await E(),l&&l())}catch(e){b((0,o.__)("Failed to delete category.","generateblocks-pro"))}finally{m(!1)}}},I=(0,r.useMemo)((()=>[{id:"name",header:(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("%s Name","generateblocks-pro"),_.singular||"Category"),accessorKey:"name",cell:t=>{const n=t.row.original;return(0,e.createElement)(Kt,{category:n,updateCategory:C,saving:g})}},{id:"items",header:_.itemsCount?_.itemsCount.charAt(0).toUpperCase()+_.itemsCount.slice(1):(0,o.__)("Items","generateblocks-pro"),cell:e=>`${e.row.original.count||0} ${_.itemsCount||"items"}`},{id:"actions",header:(0,o.__)("Actions","generateblocks-pro"),cell:t=>{const n=t.row.original;return n.isUncategorized?(0,e.createElement)("span",{className:"gb-uncategorized-actions"},(0,o.__)("Built-in","generateblocks-pro")):(0,e.createElement)(s.DropdownMenu,{icon:ye,label:(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("%s actions","generateblocks-pro"),_.singular||"Category"),className:"gb-taxonomy-actions",popoverProps:{placement:"left"}},(({onClose:t})=>(0,e.createElement)(s.MenuGroup,null,(0,e.createElement)(s.MenuItem,{icon:Ce,onClick:()=>{S(n.id),t()},isDestructive:!0},(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("Delete %s","generateblocks-pro"),_.singular||"Category")))))}}]),[_,C,S,g]);return(0,e.createElement)("div",{className:"gb-taxonomy-manager"},(0,e.createElement)("div",{className:"gb-taxonomy-manager-header"},(0,e.createElement)("div",{className:"gb-taxonomy-title-section"},(0,e.createElement)("h2",null,(0,o.sprintf)(/* translators: %s: plural taxonomy label */ /* translators: %s: plural taxonomy label */
(0,o.__)("Manage %s","generateblocks-pro"),_.plural||"Categories"))),(0,e.createElement)("div",{className:"gb-taxonomy-header-actions"},(0,e.createElement)(s.Button,{variant:"secondary",onClick:()=>{c()},disabled:g},(0,o.__)("Back","generateblocks-pro")))),(0,e.createElement)("div",{className:"gb-taxonomy-content"},!!f&&(0,e.createElement)(s.Notice,{status:"error",isDismissible:!1,className:"gb-taxonomy-error-notice"},f),(0,e.createElement)("div",{className:"gb-create-taxonomy-section"},(0,e.createElement)("h3",null,(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("Create New %s","generateblocks-pro"),_.singular||"Category")),(0,e.createElement)("div",{className:"gb-create-taxonomy-form"},(0,e.createElement)(s.TextControl,{label:(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("%s Name","generateblocks-pro"),_.singular||"Category"),value:y,onChange:v,placeholder:(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("Enter %s name…","generateblocks-pro"),_.singular?.toLowerCase()||"category"),disabled:g,onKeyDown:e=>{"Enter"===e.key&&k()},__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}),(0,e.createElement)(s.Button,{variant:"primary",icon:De,onClick:k,disabled:!y.trim()||g,isBusy:g,__next40pxDefaultSize:!0},(0,o.sprintf)(/* translators: %s: singular taxonomy label */ /* translators: %s: singular taxonomy label */
(0,o.__)("Create %s","generateblocks-pro"),_.singular||"Category")))),(0,e.createElement)("div",{className:"gb-taxonomy-list-section"},(0,e.createElement)("h3",null,(0,o.sprintf)(/* translators: %s: plural taxonomy label */ /* translators: %s: plural taxonomy label */
(0,o.__)("Existing %s","generateblocks-pro"),_.plural||"Categories")),p?(0,e.createElement)("div",{className:"gb-taxonomy-loading"},(0,e.createElement)(s.Spinner,null),(0,e.createElement)("span",null,(0,o.sprintf)(/* translators: %s: plural taxonomy label */ /* translators: %s: plural taxonomy label */
(0,o.__)("Loading %s…","generateblocks-pro"),_.plural?.toLowerCase()||"categories"))):(0,e.createElement)("div",{className:"gb-dashboard-table-wrapper"},0===u.length?(0,e.createElement)("p",{style:{marginTop:"0"}},(0,o.sprintf)(/* translators: %s: plural taxonomy label */ /* translators: %s: plural taxonomy label */
(0,o.__)("No %s created yet.","generateblocks-pro"),_.plural?.toLowerCase()||"categories")):(0,e.createElement)(Ie.Table,{className:"gb-dashboard-table table-view-list",columns:I,data:u,"aria-labelledby":"taxonomy-table-header"})))))}const Wt={taxonomyConfig:{slug:"gblocks_condition_cat",restBase:"condition-categories",labels:{singular:(0,o.__)("Category","generateblocks-pro"),plural:(0,o.__)("Categories","generateblocks-pro"),uncategorized:(0,o.__)("Uncategorized","generateblocks-pro"),itemsCount:"conditions"}},itemsEndpoint:"/generateblocks-pro/advanced-conditions/v1/conditions",itemsTaxonomyField:"gblocks_condition_cat",manageEndpoint:"/generateblocks-pro/advanced-conditions/v1/manage_category"};function Gt({onNavigateBack:t,onCategoriesChange:n}){return(0,e.createElement)("div",{className:"gb-categories-manager"},(0,e.createElement)(Ut,{...Wt,onNavigateBack:t,onTaxonomyChange:n}))}function Yt({currentView:t,views:n={},className:s="",minHeight:o=400,viewOrder:a=[]}){const[i,c]=(0,r.useState)(t),[l,u]=(0,r.useState)(!1),[d,p]=(0,r.useState)(!1),[h,g]=(0,r.useState)("forward");(0,r.useEffect)((()=>{d||p(!0)}),[]),(0,r.useEffect)((()=>{if(d&&i!==t){const e=a.indexOf(t),n=a.indexOf(i);g(-1!==e&&-1!==n?e>n?"forward":"backward":"forward"),u(!0);const r=setTimeout((()=>{u(!1),c(t)}),260);return()=>clearTimeout(r)}}),[t,i,d,a]);const m=["gb-navigator",s,l?"gb-navigator--transitioning":"",l?`gb-navigator--${h}`:""].filter(Boolean).join(" ");return(0,e.createElement)("div",{className:m,style:{minHeight:`${o}px`}},Object.entries(n).map((([n,r])=>{const s=n===t,o=["gb-navigator-view",`gb-navigator-view--${n}`,s?"gb-navigator-view--active":"gb-navigator-view--inactive"].join(" ");return(0,e.createElement)("div",{key:n,className:o,"aria-hidden":!s},(s||l)&&r)})))}function Jt({isModalMode:t=!1,onConditionSelect:n=null,onCreateCondition:a=null}={}){const[i,c]=(0,r.useState)((()=>{const e=new URLSearchParams(window.location.search);return parseInt(e.get("conditionPage")||"1",10)})),[l,u]=(0,r.useState)("list"),[d,p]=(0,r.useState)({conditionId:null,initialConditions:null,initialTitle:"",isNew:!1}),{data:h,isLoading:g}=function(e=100,t=1){return ee({queryKey:["conditions",{perPage:e,page:t}],queryFn:()=>async function({perPage:e=100,page:t=1}){const n=await oe()({path:`/generateblocks-pro/advanced-conditions/v1/conditions/?page=${t}&per_page=${e}`});if(n.success)return n.response;throw new Error("Failed to fetch conditions")}({perPage:e,page:t}),select:e=>({conditions:e?.conditions||[],total:e?.total||0,pages:e?.pages||1})})}(20,i),m=h?.conditions||[],f=h?.pages||1,[b,y]=(0,r.useState)(0),v=ge(),_=(0,r.useMemo)((()=>m&&m.length>0?m.map((e=>{const t=e.title?.rendered||e.title||"Untitled";return{...e,title:{...e.title,rendered:t}}})):[]),[m]);(0,r.useEffect)((()=>{if(t)return;const e=new URLSearchParams(window.location.search),n=e.get("edit");if(e.get("categories"))u("categories");else if(n&&"new"!==n){const e=_.find((e=>e.id.toString()===n));e&&(p({conditionId:e.id,initialConditions:e.gbConditions||{logic:"OR",groups:[]},initialTitle:e.title?.rendered||"",isNew:!1}),u("edit"))}else"new"===n?(p({conditionId:null,initialConditions:{logic:"OR",groups:[]},initialTitle:"",isNew:!0}),u("edit")):u("list")}),[_,t]);const w=(e,n=null)=>{if(t)return;const r=new URL(window.location);"edit"===e?(n?r.searchParams.set("edit",n):r.searchParams.set("edit","new"),r.searchParams.delete("categories")):"categories"===e?(r.searchParams.set("categories","manage"),r.searchParams.delete("edit")):(r.searchParams.delete("edit"),r.searchParams.delete("categories")),window.history.pushState({},"",r)};(0,r.useEffect)((()=>{if(t)return;const e=new URL(window.location);e.searchParams.set("conditionPage",i),window.history.replaceState({},"",e)}),[i,t]);const E=e=>{c(e)},k=()=>{u("list"),w("list"),p({conditionId:null,initialConditions:null,initialTitle:"",isNew:!1})};if((0,r.useEffect)((()=>{if(t)return;const e=()=>{const e=new URLSearchParams(window.location.search),t=e.get("edit");if(e.get("categories"))u("categories");else if(t&&"new"!==t){const e=_.find((e=>e.id.toString()===t));e&&(p({conditionId:e.id,initialConditions:e.gbConditions||{logic:"OR",groups:[]},initialTitle:e.title?.rendered||"",isNew:!1}),u("edit"))}else"new"===t?(p({conditionId:null,initialConditions:{logic:"OR",groups:[]},initialTitle:"",isNew:!0}),u("edit")):u("list")};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[_,t]),g)return(0,e.createElement)("div",{className:"gb-dashboard-admin"},(0,e.createElement)(s.Spinner,null));const C={list:(0,e.createElement)("div",{className:"gb-dashboard-admin"},(0,e.createElement)("div",{className:"gb-dashboard-admin__header"},(0,e.createElement)("div",{className:"gb-dashboard-admin__header-buttons"},(0,e.createElement)(s.Button,{variant:"primary",onClick:()=>{t&&a?a():(p({conditionId:null,initialConditions:{logic:"OR",groups:[]},initialTitle:"",isNew:!0}),u("edit"),w("edit"))}},(0,o.__)("Add New","generateblocks-pro"))),(0,e.createElement)("div",{className:"gb-dashboard-admin__header-buttons-right"},(0,e.createElement)(s.Button,{variant:"secondary",onClick:()=>{u("categories"),w("categories")}},(0,o.__)("Manage Categories","generateblocks-pro")))),(0,e.createElement)("div",{className:"gb-dashboard-admin__inner"},(0,e.createElement)(Te,{conditions:_,onEditCondition:e=>{t&&n?n(e):(p({conditionId:e.id,initialConditions:e.gbConditions||{logic:"OR",groups:[]},initialTitle:e.title?.rendered||"",isNew:!1}),u("edit"),w("edit",e.id))},refreshKey:b}),f>1&&(0,e.createElement)("div",{className:"gb-dashboard__pagination"},(0,e.createElement)(s.Button,{disabled:1===i,onClick:()=>E(i-1),variant:"secondary"},(0,o.__)("Previous","generateblocks-pro")),(0,e.createElement)("span",null,(0,o.sprintf)(
// translators: %1$s: current page, %2$s: total pages
// translators: %1$s: current page, %2$s: total pages
(0,o.__)("Page %1$s of %2$s","generateblocks-pro"),i,f)),(0,e.createElement)(s.Button,{disabled:i===f,onClick:()=>E(i+1),variant:"secondary"},(0,o.__)("Next","generateblocks-pro"))))),edit:(0,e.createElement)("div",{className:"gb-dashboard-admin"},(0,e.createElement)(Ht,{onNavigateBack:k,onSave:async()=>{v.invalidateQueries({queryKey:["conditions"]}),k()},conditionId:d.conditionId,initialConditions:d.initialConditions,initialTitle:d.initialTitle,isNew:d.isNew})),categories:(0,e.createElement)("div",{className:"gb-dashboard-admin"},(0,e.createElement)(Gt,{onNavigateBack:()=>{u("list"),w("list")},onCategoriesChange:()=>{y((e=>e+1))}}))},S=t?{list:C.list,categories:C.categories}:C,I=t?["list","categories"]:["list","edit","categories"];return(0,e.createElement)(Yt,{currentView:l,views:S,viewOrder:I,className:"gb-conditions-dashboard",minHeight:400})}function Zt(t){return(0,e.createElement)(Y,{client:ge()},(0,e.createElement)(Jt,{...t}))}document.addEventListener("DOMContentLoaded",(function(){const t=document.getElementById("gb-conditions-dashboard");var n,s;t&&(n=(0,e.createElement)(Zt,null),s=t,void 0!==r.createRoot?(0,r.createRoot)(s).render(n):(0,r.render)(n,s))}))})()})();