(()=>{var e={1020(e,t,r){"use strict";var s=r(1609),n=Symbol.for("react.element"),a=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),o=s.__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,r){var s,l={},c=null,u=null;for(s in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)a.call(t,s)&&!i.hasOwnProperty(s)&&(l[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps)void 0===l[s]&&(l[s]=t[s]);return{$$typeof:n,type:e,key:c,ref:u,props:l,_owner:o.current}}},4848(e,t,r){"use strict";e.exports=r(1020)},1609(e){"use strict";e.exports=window.React},6942(e,t){var r;!function(){"use strict";var s={}.hasOwnProperty;function n(){for(var e="",t=0;t{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=r(1609);const t=window.wp.blocks,s=window.wp.element,n=window.wp.blockEditor,a=window.wp.components,o=window.wp.data,i=window.wp.i18n,l=window.wp.htmlEntities,c=window.wp.apiFetch;var u=r.n(c),d=r(6942),h=r.n(d);const m=window.wp.hooks;function p({name:e,clientId:t,align:r,children:a}){const{getBlockRootClientId:i}=(0,o.useSelect)((e=>e("core/block-editor")),[]),l=(0,o.useSelect)((e=>{const{getSettings:t}=e(n.store);return t().supportsLayout||!1}),[]),c=e.toString().replace("/","-"),u={className:h()({"wp-block":!0,"gb-is-root-block":!0,[`gb-root-block-${c}`]:!0,[`align${r}`]:l}),"data-align":r&&!l?r:null,"data-block":t},d=i(t);return(0,m.applyFilters)("generateblocks.rootElement.disable",d,{name:e})?a:(0,s.createElement)("div",u,a)}const f=window.wp.primitives,g=(0,s.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,s.createElement)(f.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"})),b=(0,s.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,s.createElement)(f.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"}));function y({currentView:t,views:r={},className:n="",minHeight:a=400,viewOrder:o=[]}){const[i,l]=(0,s.useState)(t),[c,u]=(0,s.useState)(!1),[d,h]=(0,s.useState)(!1),[m,p]=(0,s.useState)("forward");(0,s.useEffect)((()=>{d||h(!0)}),[]),(0,s.useEffect)((()=>{if(d&&i!==t){const e=o.indexOf(t),r=o.indexOf(i);p(-1!==e&&-1!==r?e>r?"forward":"backward":"forward"),u(!0);const s=setTimeout((()=>{u(!1),l(t)}),260);return()=>clearTimeout(s)}}),[t,i,d,o]);const f=["gb-navigator",n,c?"gb-navigator--transitioning":"",c?`gb-navigator--${m}`:""].filter(Boolean).join(" ");return(0,e.createElement)("div",{className:f,style:{minHeight:`${a}px`}},Object.entries(r).map((([r,s])=>{const n=r===t,a=["gb-navigator-view",`gb-navigator-view--${r}`,n?"gb-navigator-view--active":"gb-navigator-view--inactive"].join(" ");return(0,e.createElement)("div",{key:r,className:a,"aria-hidden":!n},(n||c)&&s)})))}function v({trigger:t,itemId:r=null,itemType:n="item",dashboardView:o,editorView:l,onItemSelect:c=null,getNewTabUrl:u,onEditorSave:d=null,editorProps:h={},modalProps:m={},labels:p={},className:f="",confirmMessages:v}){const _={backButton:(0,i.__)("Back to Dashboard","generateblocks-pro"),createNew:(0,i.__)("Create New Item","generateblocks-pro"),edit:(0,i.__)("Edit Item","generateblocks-pro"),dashboard:(0,i.__)("Dashboard","generateblocks-pro"),openInNewTab:(0,i.__)("Open in new tab","generateblocks-pro"),close:(0,i.__)("Close","generateblocks-pro"),unsavedChanges:(0,i.__)("Unsaved changes","generateblocks-pro"),...p},{isOpen:w,setIsOpen:E,currentView:k,contentHeight:C,selectedItemId:S,selectedItemTitle:O,selectedItemData:R,hasUnsavedChanges:x,setHasUnsavedChanges:P,setSelectedItemId:I,setSelectedItemTitle:N,setSelectedItemData:F,headerRef:T,modalRef:D,handleItemSelect:M,handleBackToDashboard:q,handleBackToDashboardAfterSave:Q,handleOpenInNewTab:A,handleClose:L}=function({itemId:e=null,onItemSelect:t=null,getNewTabUrl:r,confirmMessages:n={unsavedBack:(0,i.__)("You have unsaved changes. Are you sure you want to go back?","generateblocks-pro"),unsavedClose:(0,i.__)("You have unsaved changes. Are you sure you want to close?","generateblocks-pro")}}){const[a,o]=(0,s.useState)(!1),[l,c]=(0,s.useState)(e?"editor":"dashboard"),[u,d]=(0,s.useState)(0),[h,m]=(0,s.useState)(e),[p,f]=(0,s.useState)(""),[g,b]=(0,s.useState)(null),[y,v]=(0,s.useState)(!1),_=(0,s.useRef)(null),w=(0,s.useRef)(null),E=(0,s.useRef)(!1);(0,s.useEffect)((()=>{E.current||(m(e),c(e?"editor":"dashboard")),E.current=!1}),[e]);const k=(0,s.useCallback)(((e,r,s)=>{m(e),f(r||""),b(s||null),c("editor"),t&&t(e,r,s)}),[t]),C=(0,s.useCallback)((()=>{y&&!window.confirm(n.unsavedBack)||(E.current=!0,c("dashboard"),m(null),f(""),b(null),v(!1))}),[y,n.unsavedBack]),S=(0,s.useCallback)((()=>{E.current=!0,c("dashboard"),m(null),f(""),b(null),v(!1)}),[]),O=(0,s.useCallback)((()=>{if("editor"===l&&h&&r){const e=r(h,g);e&&window.open(e,"_blank")}}),[l,h,g,r]),R=(0,s.useCallback)((()=>{"editor"===l&&y&&!window.confirm(n.unsavedClose)||(o(!1),setTimeout((()=>{c(e?"editor":"dashboard"),m(e),f(""),v(!1)}),300))}),[l,y,n.unsavedClose,e]);return(0,s.useEffect)((()=>{const e=()=>{if(!w.current||!_.current||!a)return;const e=w.current.querySelector(".components-modal__content"),t=_.current;if(e&&t){const r=e.clientHeight,s=t.offsetHeight;d(r-s)}};if(a){e();const t=new ResizeObserver(e);return w.current&&t.observe(w.current),_.current&&t.observe(_.current),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}}}),[a]),(0,s.useEffect)((()=>{const e=e=>{"Escape"===e.key&&a&&(e.preventDefault(),R())};return a&&document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}}),[a,R]),{isOpen:a,setIsOpen:o,currentView:l,setCurrentView:c,contentHeight:u,selectedItemId:h,selectedItemTitle:p,selectedItemData:g,hasUnsavedChanges:y,setHasUnsavedChanges:v,setSelectedItemId:m,setSelectedItemTitle:f,setSelectedItemData:b,headerRef:_,modalRef:w,handleItemSelect:k,handleBackToDashboard:C,handleBackToDashboardAfterSave:S,handleOpenInNewTab:O,handleClose:R}}({itemId:r,onItemSelect:c,getNewTabUrl:u,confirmMessages:v}),B={dashboard:o&&(0,s.cloneElement)(o,{isModalMode:!0,isIframeMode:!0,onItemSelect:e=>{"object"==typeof e&&e.id&&M(e.id,e.title?.rendered||e.title||"")},onCreateItem:()=>M("new",_.createNew),onConditionSelect:e=>{M(e.id,e.title?.rendered||"",e)},onCreateCondition:()=>M("new",_.createNew),onModalSelect:(e,t)=>{M(e,t)},onCreateOverlay:(e,t)=>M(e||"new",_.createNew,{overlayType:t})}),editor:l&&S&&(0,s.cloneElement)(l,{embedded:!0,onUnsavedChanges:P,formId:S,conditionId:"new"===S?null:S,isNew:"new"===S,onNavigateBack:q,onSave:(e=null)=>{e?.id&&(I(e.id),N(e?.title?.rendered||e?.title||""),F(e)),d?d(e):Q()},overlayId:S,overlayTitle:O,overlayType:R?.overlayType,onClose:q,...h})},U={title:"",className:`gb-dashboard-trigger-modal ${f}`,isFullScreen:!0,isDismissible:!1,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,showHeader:!1,...m};return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{onClick:()=>E(!0),role:"button",tabIndex:0,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),E(!0))}},t),w&&(0,e.createElement)(a.Modal,{...U,onRequestClose:()=>{},ref:D},(0,e.createElement)("div",{className:"gb-dashboard-custom-header",ref:T,"data-item-type":n},(0,e.createElement)("div",{className:"gb-dashboard-header-left"},"editor"===k&&(0,e.createElement)(a.Button,{icon:"arrow-left-alt2",size:"compact",variant:"tertiary",onClick:q,label:_.backButton}),(0,e.createElement)("h2",{className:"gb-dashboard-custom-title"},(()=>{if("editor"===k){const e="new"===S?_.createNew:_.edit;return O&&"new"!==S?`${e}: ${O}`:e}return _.dashboard})())),(0,e.createElement)("div",{className:"gb-dashboard-header-actions"},x&&"editor"===k&&(0,e.createElement)("span",{className:"gb-dashboard-unsaved-indicator"},_.unsavedChanges),"editor"===k&&u&&(0,e.createElement)(a.Button,{icon:g,size:"compact",variant:"tertiary",onClick:A,label:_.openInNewTab}),(0,e.createElement)(a.Button,{icon:b,size:"compact",variant:"tertiary",onClick:L,label:_.close}))),(0,e.createElement)("div",{className:"gb-dashboard-content-wrapper",style:{height:C>0?`${C}px`:"auto",minHeight:C>0?`${C}px`:"auto"}},(0,e.createElement)(y,{currentView:k,views:B,className:"gb-dashboard-navigator",minHeight:0,viewOrder:["dashboard","editor"]}))))}const _=window.wp.url;function w(e="",t={}){const r=`${function(){if("undefined"==typeof window)return"/wp-admin/";if(window.ajaxurl)try{const e=new URL(window.ajaxurl,window.location.origin),t=e.pathname.replace(/admin-ajax\.php$/,"");return`${e.origin}${t}`}catch(e){}const{origin:e,pathname:t}=window.location,r=t.indexOf("/wp-admin");return-1!==r?`${e}${t.substring(0,r)}/wp-admin/`:`${e}/wp-admin/`}().replace(/\/+$/,"/")}${e.replace(/^\/+/,"")}`;return t&&0!==Object.keys(t).length?(0,_.addQueryArgs)(r,t):r}const E=window.wp.date,k=(0,s.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},(0,s.createElement)(f.Path,{d:"M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"})),C=(0,s.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,s.createElement)(f.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})),S=window.gbp.components;var O=r(4848),R=e.createContext(void 0),x=t=>{const r=e.useContext(R);if(t)return t;if(!r)throw new Error("No QueryClient set, use QueryClientProvider to set one");return r},P=({client:t,children:r})=>(e.useEffect((()=>(t.mount(),()=>{t.unmount()})),[t]),(0,O.jsx)(R.Provider,{value:t,children:r})),I="undefined"==typeof window||"Deno"in globalThis;function N(){}function F(e){return"number"==typeof e&&e>=0&&e!==1/0}function T(e,t){return Math.max(e+(t||0)-Date.now(),0)}function D(e,t){return"function"==typeof e?e(t):e}function M(e,t){return"function"==typeof e?e(t):e}function q(e,t){const{type:r="all",exact:s,fetchStatus:n,predicate:a,queryKey:o,stale:i}=e;if(o)if(s){if(t.queryHash!==A(o,t.options))return!1}else if(!B(t.queryKey,o))return!1;if("all"!==r){const e=t.isActive();if("active"===r&&!e)return!1;if("inactive"===r&&e)return!1}return!("boolean"==typeof i&&t.isStale()!==i||n&&n!==t.state.fetchStatus||a&&!a(t))}function Q(e,t){const{exact:r,status:s,predicate:n,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(r){if(L(t.options.mutationKey)!==L(a))return!1}else if(!B(t.options.mutationKey,a))return!1}return!(s&&t.state.status!==s||n&&!n(t))}function A(e,t){return(t?.queryKeyHashFn||L)(e)}function L(e){return JSON.stringify(e,((e,t)=>K(t)?Object.keys(t).sort().reduce(((e,r)=>(e[r]=t[r],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((r=>B(e[r],t[r])))}function U(e,t){if(e===t)return e;const r=$(e)&&$(t);if(r||K(e)&&K(t)){const s=r?e:Object.keys(e),n=s.length,a=r?t:Object.keys(t),o=a.length,i=r?[]:{};let l=0;for(let n=0;nr?s.slice(1):s}function W(e,t,r=0){const s=[t,...e];return r&&s.length>r?s.slice(0,-1):s}var Z=Symbol();function Y(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:e.queryFn&&e.queryFn!==Z?e.queryFn:()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`))}function J(e,t){return"function"==typeof e?e(...t):!!e}var X=e=>setTimeout(e,0),ee=function(){let e=[],t=0,r=e=>{e()},s=e=>{e()},n=X;const a=s=>{t?e.push(s):n((()=>{r(s)}))};return{batch:a=>{let o;t++;try{o=a()}finally{t--,t||(()=>{const t=e;e=[],t.length&&n((()=>{s((()=>{t.forEach((e=>{r(e)}))}))}))})()}return o},batchCalls:e=>(...t)=>{a((()=>{e(...t)}))},schedule:a,setNotifyFunction:e=>{r=e},setBatchNotifyFunction:e=>{s=e},setScheduler:e=>{n=e}}}(),te=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(){}},re=new class extends te{#e;#t;#r;constructor(){super(),this.#r=e=>{if(!I&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=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}},se=new class extends te{#s=!0;#t;#r;constructor(){super(),this.#r=e=>{if(!I&&window.addEventListener){const t=()=>e(!0),r=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#s!==e&&(this.#s=e,this.listeners.forEach((t=>{t(e)})))}isOnline(){return this.#s}};function ne(){let e,t;const r=new Promise(((r,s)=>{e=r,t=s}));function s(e){Object.assign(r,e),delete r.resolve,delete r.reject}return r.status="pending",r.catch((()=>{})),r.resolve=t=>{s({status:"fulfilled",value:t}),e(t)},r.reject=e=>{s({status:"rejected",reason:e}),t(e)},r}function ae(e){return Math.min(1e3*2**e,3e4)}function oe(e){return"online"!==(e??"online")||se.isOnline()}var ie=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function le(e){return e instanceof ie}function ce(e){let t,r=!1,s=0,n=!1;const a=ne(),o=()=>re.isFocused()&&("always"===e.networkMode||se.isOnline())&&e.canRun(),i=()=>oe(e.networkMode)&&e.canRun(),l=r=>{n||(n=!0,e.onSuccess?.(r),t?.(),a.resolve(r))},c=r=>{n||(n=!0,e.onError?.(r),t?.(),a.reject(r))},u=()=>new Promise((r=>{t=e=>{(n||o())&&r(e)},e.onPause?.()})).then((()=>{t=void 0,n||e.onContinue?.()})),d=()=>{if(n)return;let t;const a=0===s?e.initialPromise:void 0;try{t=a??e.fn()}catch(e){t=Promise.reject(e)}Promise.resolve(t).then(l).catch((t=>{if(n)return;const a=e.retry??(I?0:3),i=e.retryDelay??ae,l="function"==typeof i?i(s,t):i,h=!0===a||"number"==typeof a&&s{setTimeout(e,m)}))).then((()=>o()?void 0:u())).then((()=>{r?c(t):d()}))):c(t)}))};return{promise:a,cancel:t=>{n||(c(new ie(t)),e.abort?.())},continue:()=>(t?.(),a),cancelRetry:()=>{r=!0},continueRetry:()=>{r=!1},canStart:i,start:()=>(i()?d():u().then(d),a)}}var ue=class{#n;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),F(this.gcTime)&&(this.#n=setTimeout((()=>{this.optionalRemove()}),this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(I?1/0:3e5))}clearGcTimeout(){this.#n&&(clearTimeout(this.#n),this.#n=void 0)}},de=class extends ue{#a;#o;#i;#l;#c;#u;#d;constructor(e){super(),this.#d=!1,this.#u=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#l=e.client,this.#i=this.#l.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#a=function(e){const t="function"==typeof e.initialData?e.initialData():e.initialData,r=void 0!==t,s=r?"function"==typeof e.initialDataUpdatedAt?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?s??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}(this.options),this.state=e.state??this.#a,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#c?.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 r=z(this.state.data,e,this.options);return this.#h({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#h({type:"setState",state:e,setStateOptions:t})}cancel(e){const t=this.#c?.promise;return this.#c?.cancel(e),t?t.then(N).catch(N):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#a)}isActive(){return this.observers.some((e=>!1!==M(e.options.enabled,this)))}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Z||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||!T(this.state.dataUpdatedAt,e)}onFocus(){const e=this.observers.find((e=>e.shouldFetchOnWindowFocus()));e?.refetch({cancelRefetch:!1}),this.#c?.continue()}onOnline(){const e=this.observers.find((e=>e.shouldFetchOnReconnect()));e?.refetch({cancelRefetch:!1}),this.#c?.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.#c&&(this.#d?this.#c.cancel({revert:!0}):this.#c.cancelRetry()),this.scheduleGc()),this.#i.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#h({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.#c)return this.#c.continueRetry(),this.#c.promise;if(e&&this.setOptions(e),!this.options.queryFn){const e=this.observers.find((e=>e.options.queryFn));e&&this.setOptions(e.options)}const r=new AbortController,s=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#d=!0,r.signal)})},n={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#l,state:this.state,fetchFn:()=>{const e=Y(this.options,t),r={client:this.#l,queryKey:this.queryKey,meta:this.meta};return s(r),this.#d=!1,this.options.persister?this.options.persister(e,r,this):e(r)}};s(n),this.options.behavior?.onFetch(n,this),this.#o=this.state,"idle"!==this.state.fetchStatus&&this.state.fetchMeta===n.fetchOptions?.meta||this.#h({type:"fetch",meta:n.fetchOptions?.meta});const a=e=>{le(e)&&e.silent||this.#h({type:"error",error:e}),le(e)||(this.#i.config.onError?.(e,this),this.#i.config.onSettled?.(this.state.data,e,this)),this.scheduleGc()};return this.#c=ce({initialPromise:t?.initialPromise,fn:n.fetchFn,abort:r.abort.bind(r),onSuccess:e=>{if(void 0!==e){try{this.setData(e)}catch(e){return void a(e)}this.#i.config.onSuccess?.(e,this),this.#i.config.onSettled?.(e,this.state.error,this),this.scheduleGc()}else a(new Error(`${this.queryHash} data is undefined`))},onError:a,onFail:(e,t)=>{this.#h({type:"failed",failureCount:e,error:t})},onPause:()=>{this.#h({type:"pause"})},onContinue:()=>{this.#h({type:"continue"})},retry:n.options.retry,retryDelay:n.options.retryDelay,networkMode:n.options.networkMode,canRun:()=>!0}),this.#c.start()}#h(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,...he(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 r=e.error;return le(r)&&r.revert&&this.#o?{...this.#o,fetchStatus:"idle"}:{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error"};case"invalidate":return{...t,isInvalidated:!0};case"setState":return{...t,...e.state}}})(this.state),ee.batch((()=>{this.observers.forEach((e=>{e.onQueryUpdate()})),this.#i.notify({query:this,type:"updated",action:e})}))}};function he(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:oe(t.networkMode)?"fetching":"paused",...void 0===e&&{error:null,status:"pending"}}}var me=class extends te{constructor(e={}){super(),this.config=e,this.#m=new Map}#m;build(e,t,r){const s=t.queryKey,n=t.queryHash??A(s,t);let a=this.get(n);return a||(a=new de({client:e,queryKey:s,queryHash:n,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(s)}),this.add(a)),a}add(e){this.#m.has(e.queryHash)||(this.#m.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const t=this.#m.get(e.queryHash);t&&(e.destroy(),t===e&&this.#m.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){ee.batch((()=>{this.getAll().forEach((e=>{this.remove(e)}))}))}get(e){return this.#m.get(e)}getAll(){return[...this.#m.values()]}find(e){const t={exact:!0,...e};return this.getAll().find((e=>q(t,e)))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter((t=>q(e,t))):t}notify(e){ee.batch((()=>{this.listeners.forEach((t=>{t(e)}))}))}onFocus(){ee.batch((()=>{this.getAll().forEach((e=>{e.onFocus()}))}))}onOnline(){ee.batch((()=>{this.getAll().forEach((e=>{e.onOnline()}))}))}},pe=class extends ue{#p;#f;#c;constructor(e){super(),this.mutationId=e.mutationId,this.#f=e.mutationCache,this.#p=[],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.#p.includes(e)||(this.#p.push(e),this.clearGcTimeout(),this.#f.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#p=this.#p.filter((t=>t!==e)),this.scheduleGc(),this.#f.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#p.length||("pending"===this.state.status?this.scheduleGc():this.#f.remove(this))}continue(){return this.#c?.continue()??this.execute(this.state.variables)}async execute(e){const t=()=>{this.#h({type:"continue"})};this.#c=ce({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(e,t)=>{this.#h({type:"failed",failureCount:e,error:t})},onPause:()=>{this.#h({type:"pause"})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#f.canRun(this)});const r="pending"===this.state.status,s=!this.#c.canStart();try{if(r)t();else{this.#h({type:"pending",variables:e,isPaused:s}),await(this.#f.config.onMutate?.(e,this));const t=await(this.options.onMutate?.(e));t!==this.state.context&&this.#h({type:"pending",context:t,variables:e,isPaused:s})}const n=await this.#c.start();return await(this.#f.config.onSuccess?.(n,e,this.state.context,this)),await(this.options.onSuccess?.(n,e,this.state.context)),await(this.#f.config.onSettled?.(n,null,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(n,null,e,this.state.context)),this.#h({type:"success",data:n}),n}catch(t){try{throw await(this.#f.config.onError?.(t,e,this.state.context,this)),await(this.options.onError?.(t,e,this.state.context)),await(this.#f.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.#h({type:"error",error:t})}}finally{this.#f.runNext(this)}}#h(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),ee.batch((()=>{this.#p.forEach((t=>{t.onMutationUpdate(e)})),this.#f.notify({mutation:this,type:"updated",action:e})}))}},fe=class extends te{constructor(e={}){super(),this.config=e,this.#g=new Set,this.#b=new Map,this.#y=0}#g;#b;#y;build(e,t,r){const s=new pe({mutationCache:this,mutationId:++this.#y,options:e.defaultMutationOptions(t),state:r});return this.add(s),s}add(e){this.#g.add(e);const t=ge(e);if("string"==typeof t){const r=this.#b.get(t);r?r.push(e):this.#b.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#g.delete(e)){const t=ge(e);if("string"==typeof t){const r=this.#b.get(t);if(r)if(r.length>1){const t=r.indexOf(e);-1!==t&&r.splice(t,1)}else r[0]===e&&this.#b.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){const t=ge(e);if("string"==typeof t){const r=this.#b.get(t),s=r?.find((e=>"pending"===e.state.status));return!s||s===e}return!0}runNext(e){const t=ge(e);if("string"==typeof t){const r=this.#b.get(t)?.find((t=>t!==e&&t.state.isPaused));return r?.continue()??Promise.resolve()}return Promise.resolve()}clear(){ee.batch((()=>{this.#g.forEach((e=>{this.notify({type:"removed",mutation:e})})),this.#g.clear(),this.#b.clear()}))}getAll(){return Array.from(this.#g)}find(e){const t={exact:!0,...e};return this.getAll().find((e=>Q(t,e)))}findAll(e={}){return this.getAll().filter((t=>Q(e,t)))}notify(e){ee.batch((()=>{this.listeners.forEach((t=>{t(e)}))}))}resumePausedMutations(){const e=this.getAll().filter((e=>e.state.isPaused));return ee.batch((()=>Promise.all(e.map((e=>e.continue().catch(N))))))}};function ge(e){return e.options.scope?.id}function be(e){return{onFetch:(t,r)=>{const s=t.options,n=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[];let i={pages:[],pageParams:[]},l=0;const c=async()=>{let r=!1;const c=Y(t.options,t.fetchOptions),u=async(e,s,n)=>{if(r)return Promise.reject();if(null==s&&e.pages.length)return Promise.resolve(e);const a={client:t.client,queryKey:t.queryKey,pageParam:s,direction:n?"backward":"forward",meta:t.options.meta};var o;o=a,Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(t.signal.aborted?r=!0:t.signal.addEventListener("abort",(()=>{r=!0})),t.signal)});const i=await c(a),{maxPages:l}=t.options,u=n?W:G;return{pages:u(e.pages,i,l),pageParams:u(e.pageParams,s,l)}};if(n&&a.length){const e="backward"===n,t={pages:a,pageParams:o},r=(e?ve:ye)(s,t);i=await u(t,r,e)}else{const t=e??a.length;do{const e=0===l?o[0]??s.initialPageParam:ye(s,i);if(l>0&&null==e)break;i=await u(i,e),l++}while(lt.options.persister?.(c,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=c}}}function ye(e,{pages:t,pageParams:r}){const s=t.length-1;return t.length>0?e.getNextPageParam(t[s],t,r[s],r):void 0}function ve(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var _e=class{#v;#f;#u;#_;#w;#E;#k;#C;constructor(e={}){this.#v=e.queryCache||new me,this.#f=e.mutationCache||new fe,this.#u=e.defaultOptions||{},this.#_=new Map,this.#w=new Map,this.#E=0}mount(){this.#E++,1===this.#E&&(this.#k=re.subscribe((async e=>{e&&(await this.resumePausedMutations(),this.#v.onFocus())})),this.#C=se.subscribe((async e=>{e&&(await this.resumePausedMutations(),this.#v.onOnline())})))}unmount(){this.#E--,0===this.#E&&(this.#k?.(),this.#k=void 0,this.#C?.(),this.#C=void 0)}isFetching(e){return this.#v.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#f.findAll({...e,status:"pending"}).length}getQueryData(e){const t=this.defaultQueryOptions({queryKey:e});return this.#v.get(t.queryHash)?.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),r=this.#v.build(this,t),s=r.state.data;return void 0===s?this.fetchQuery(e):(e.revalidateIfStale&&r.isStaleByTime(D(t.staleTime,r))&&this.prefetchQuery(t),Promise.resolve(s))}getQueriesData(e){return this.#v.findAll(e).map((({queryKey:e,state:t})=>[e,t.data]))}setQueryData(e,t,r){const s=this.defaultQueryOptions({queryKey:e}),n=this.#v.get(s.queryHash),a=n?.state.data,o=function(e,t){return"function"==typeof e?e(t):e}(t,a);if(void 0!==o)return this.#v.build(this,s).setData(o,{...r,manual:!0})}setQueriesData(e,t,r){return ee.batch((()=>this.#v.findAll(e).map((({queryKey:e})=>[e,this.setQueryData(e,t,r)]))))}getQueryState(e){const t=this.defaultQueryOptions({queryKey:e});return this.#v.get(t.queryHash)?.state}removeQueries(e){const t=this.#v;ee.batch((()=>{t.findAll(e).forEach((e=>{t.remove(e)}))}))}resetQueries(e,t){const r=this.#v;return ee.batch((()=>(r.findAll(e).forEach((e=>{e.reset()})),this.refetchQueries({type:"active",...e},t))))}cancelQueries(e,t={}){const r={revert:!0,...t},s=ee.batch((()=>this.#v.findAll(e).map((e=>e.cancel(r)))));return Promise.all(s).then(N).catch(N)}invalidateQueries(e,t={}){return ee.batch((()=>(this.#v.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 r={...t,cancelRefetch:t.cancelRefetch??!0},s=ee.batch((()=>this.#v.findAll(e).filter((e=>!e.isDisabled())).map((e=>{let t=e.fetch(void 0,r);return r.throwOnError||(t=t.catch(N)),"paused"===e.state.fetchStatus?Promise.resolve():t}))));return Promise.all(s).then(N)}fetchQuery(e){const t=this.defaultQueryOptions(e);void 0===t.retry&&(t.retry=!1);const r=this.#v.build(this,t);return r.isStaleByTime(D(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(N).catch(N)}fetchInfiniteQuery(e){return e.behavior=be(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(N).catch(N)}ensureInfiniteQueryData(e){return e.behavior=be(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return se.isOnline()?this.#f.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#v}getMutationCache(){return this.#f}getDefaultOptions(){return this.#u}setDefaultOptions(e){this.#u=e}setQueryDefaults(e,t){this.#_.set(L(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#_.values()],r={};return t.forEach((t=>{B(e,t.queryKey)&&Object.assign(r,t.defaultOptions)})),r}setMutationDefaults(e,t){this.#w.set(L(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#w.values()],r={};return t.forEach((t=>{B(e,t.mutationKey)&&Object.assign(r,t.defaultOptions)})),r}defaultQueryOptions(e){if(e._defaulted)return e;const t={...this.#u.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=A(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===Z&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#u.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#v.clear(),this.#f.clear()}};let we=null;function Ee(){return we||(we=new _e({defaultOptions:{queries:{staleTime:3e4,gcTime:3e5,retry:1,refetchOnWindowFocus:!0}}})),we}var ke=class extends te{constructor(e,t){super(),this.options=t,this.#l=e,this.#S=null,this.#O=ne(),this.options.experimental_prefetchInRender||this.#O.reject(new Error("experimental_prefetchInRender feature flag is not enabled")),this.bindMethods(),this.setOptions(t)}#l;#R=void 0;#x=void 0;#P=void 0;#I;#N;#O;#S;#F;#T;#D;#M;#q;#Q;#A=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#R.addObserver(this),Ce(this.#R,this.options)?this.#L():this.updateResult(),this.#B())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Se(this.#R,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Se(this.#R,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#U(),this.#j(),this.#R.removeObserver(this)}setOptions(e){const t=this.options,r=this.#R;if(this.options=this.#l.defaultQueryOptions(e),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled&&"function"!=typeof this.options.enabled&&"boolean"!=typeof M(this.options.enabled,this.#R))throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#$(),this.#R.setOptions(this.options),t._defaulted&&!j(this.options,t)&&this.#l.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#R,observer:this});const s=this.hasListeners();s&&Oe(this.#R,r,this.options,t)&&this.#L(),this.updateResult(),!s||this.#R===r&&M(this.options.enabled,this.#R)===M(t.enabled,this.#R)&&D(this.options.staleTime,this.#R)===D(t.staleTime,this.#R)||this.#K();const n=this.#H();!s||this.#R===r&&M(this.options.enabled,this.#R)===M(t.enabled,this.#R)&&n===this.#Q||this.#z(n)}getOptimisticResult(e){const t=this.#l.getQueryCache().build(this.#l,e),r=this.createResult(t,e);return s=r,!j(this.getCurrentResult(),s)&&(this.#P=r,this.#N=this.options,this.#I=this.#R.state),r;var s}getCurrentResult(){return this.#P}trackResult(e,t){return new Proxy(e,{get:(e,r)=>(this.trackProp(r),t?.(r),Reflect.get(e,r))})}trackProp(e){this.#A.add(e)}getCurrentQuery(){return this.#R}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){const t=this.#l.defaultQueryOptions(e),r=this.#l.getQueryCache().build(this.#l,t);return r.fetch().then((()=>this.createResult(r,t)))}fetch(e){return this.#L({...e,cancelRefetch:e.cancelRefetch??!0}).then((()=>(this.updateResult(),this.#P)))}#L(e){this.#$();let t=this.#R.fetch(this.options,e);return e?.throwOnError||(t=t.catch(N)),t}#K(){this.#U();const e=D(this.options.staleTime,this.#R);if(I||this.#P.isStale||!F(e))return;const t=T(this.#P.dataUpdatedAt,e)+1;this.#M=setTimeout((()=>{this.#P.isStale||this.updateResult()}),t)}#H(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#R):this.options.refetchInterval)??!1}#z(e){this.#j(),this.#Q=e,!I&&!1!==M(this.options.enabled,this.#R)&&F(this.#Q)&&0!==this.#Q&&(this.#q=setInterval((()=>{(this.options.refetchIntervalInBackground||re.isFocused())&&this.#L()}),this.#Q))}#B(){this.#K(),this.#z(this.#H())}#U(){this.#M&&(clearTimeout(this.#M),this.#M=void 0)}#j(){this.#q&&(clearInterval(this.#q),this.#q=void 0)}createResult(e,t){const r=this.#R,s=this.options,n=this.#P,a=this.#I,o=this.#N,i=e!==r?e.state:this.#x,{state:l}=e;let c,u={...l},d=!1;if(t._optimisticResults){const n=this.hasListeners(),a=!n&&Ce(e,t),o=n&&Oe(e,r,t,s);(a||o)&&(u={...u,...he(l.data,e.options)}),"isRestoring"===t._optimisticResults&&(u.fetchStatus="idle")}let{error:h,errorUpdatedAt:m,status:p}=u;c=u.data;let f=!1;if(void 0!==t.placeholderData&&void 0===c&&"pending"===p){let e;n?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=n.data,f=!0):e="function"==typeof t.placeholderData?t.placeholderData(this.#D?.state.data,this.#D):t.placeholderData,void 0!==e&&(p="success",c=z(n?.data,e,t),d=!0)}if(t.select&&void 0!==c&&!f)if(n&&c===a?.data&&t.select===this.#F)c=this.#T;else try{this.#F=t.select,c=t.select(c),c=z(n?.data,c,t),this.#T=c,this.#S=null}catch(e){this.#S=e}this.#S&&(h=this.#S,c=this.#T,m=Date.now(),p="error");const g="fetching"===u.fetchStatus,b="pending"===p,y="error"===p,v=b&&g,_=void 0!==c,w={status:p,fetchStatus:u.fetchStatus,isPending:b,isSuccess:"success"===p,isError:y,isInitialLoading:v,isLoading:v,data:c,dataUpdatedAt:u.dataUpdatedAt,error:h,errorUpdatedAt:m,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:g,isRefetching:g&&!b,isLoadingError:y&&!_,isPaused:"paused"===u.fetchStatus,isPlaceholderData:d,isRefetchError:y&&_,isStale:Re(e,t),refetch:this.refetch,promise:this.#O};if(this.options.experimental_prefetchInRender){const t=e=>{"error"===w.status?e.reject(w.error):void 0!==w.data&&e.resolve(w.data)},s=()=>{const e=this.#O=w.promise=ne();t(e)},n=this.#O;switch(n.status){case"pending":e.queryHash===r.queryHash&&t(n);break;case"fulfilled":"error"!==w.status&&w.data===n.value||s();break;case"rejected":"error"===w.status&&w.error===n.reason||s()}}return w}updateResult(){const e=this.#P,t=this.createResult(this.#R,this.options);this.#I=this.#R.state,this.#N=this.options,void 0!==this.#I.data&&(this.#D=this.#R),j(t,e)||(this.#P=t,this.#V({listeners:(()=>{if(!e)return!0;const{notifyOnChangeProps:t}=this.options,r="function"==typeof t?t():t;if("all"===r||!r&&!this.#A.size)return!0;const s=new Set(r??this.#A);return this.options.throwOnError&&s.add("error"),Object.keys(this.#P).some((t=>{const r=t;return this.#P[r]!==e[r]&&s.has(r)}))})()}))}#$(){const e=this.#l.getQueryCache().build(this.#l,this.options);if(e===this.#R)return;const t=this.#R;this.#R=e,this.#x=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#B()}#V(e){ee.batch((()=>{e.listeners&&this.listeners.forEach((e=>{e(this.#P)})),this.#l.getQueryCache().notify({query:this.#R,type:"observerResultsUpdated"})}))}};function Ce(e,t){return function(e,t){return!1!==M(t.enabled,e)&&void 0===e.state.data&&!("error"===e.state.status&&!1===t.retryOnMount)}(e,t)||void 0!==e.state.data&&Se(e,t,t.refetchOnMount)}function Se(e,t,r){if(!1!==M(t.enabled,e)){const s="function"==typeof r?r(e):r;return"always"===s||!1!==s&&Re(e,t)}return!1}function Oe(e,t,r,s){return(e!==t||!1===M(s.enabled,e))&&(!r.suspense||"error"!==e.state.status)&&Re(e,r)}function Re(e,t){return!1!==M(t.enabled,e)&&e.isStaleByTime(D(t.staleTime,e))}var xe=e.createContext(function(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}()),Pe=e.createContext(!1),Ie=(Pe.Provider,(e,t,r)=>t.fetchOptimistic(e).catch((()=>{r.clearReset()})));function Ne(t,r){return function(t,r,s){const n=x(s),a=e.useContext(Pe),o=e.useContext(xe),i=n.defaultQueryOptions(t);n.getDefaultOptions().queries?._experimental_beforeQuery?.(i),i._optimisticResults=a?"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)))})(i),((e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))})(i,o),(t=>{e.useEffect((()=>{t.clearReset()}),[t])})(o);const l=!n.getQueryCache().get(i.queryHash),[c]=e.useState((()=>new r(n,i))),u=c.getOptimisticResult(i),d=!a&&!1!==t.subscribed;if(e.useSyncExternalStore(e.useCallback((e=>{const t=d?c.subscribe(ee.batchCalls(e)):N;return c.updateResult(),t}),[c,d]),(()=>c.getCurrentResult()),(()=>c.getCurrentResult())),e.useEffect((()=>{c.setOptions(i)}),[i,c]),((e,t)=>e?.suspense&&t.isPending)(i,u))throw Ie(i,c,o);if((({result:e,errorResetBoundary:t,throwOnError:r,query:s,suspense:n})=>e.isError&&!t.isReset()&&!e.isFetching&&s&&(n&&void 0===e.data||J(r,[e.error,s])))({result:u,errorResetBoundary:o,throwOnError:i.throwOnError,query:n.getQueryCache().get(i.queryHash),suspense:i.suspense}))throw u.error;if(n.getDefaultOptions().queries?._experimental_afterQuery?.(i,u),i.experimental_prefetchInRender&&!I&&((e,t)=>e.isLoading&&e.isFetching&&!t)(u,a)){const e=l?Ie(i,c,o):n.getQueryCache().get(i.queryHash)?.promise;e?.catch(N).finally((()=>{c.updateResult()}))}return i.notifyOnChangeProps?u:c.trackResult(u)}(t,ke,r)}var Fe=class extends te{#l;#P=void 0;#G;#W;constructor(e,t){super(),this.#l=e,this.setOptions(t),this.bindMethods(),this.#Z()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){const t=this.options;this.options=this.#l.defaultMutationOptions(e),j(this.options,t)||this.#l.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#G,observer:this}),t?.mutationKey&&this.options.mutationKey&&L(t.mutationKey)!==L(this.options.mutationKey)?this.reset():"pending"===this.#G?.state.status&&this.#G.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#G?.removeObserver(this)}onMutationUpdate(e){this.#Z(),this.#V(e)}getCurrentResult(){return this.#P}reset(){this.#G?.removeObserver(this),this.#G=void 0,this.#Z(),this.#V()}mutate(e,t){return this.#W=t,this.#G?.removeObserver(this),this.#G=this.#l.getMutationCache().build(this.#l,this.options),this.#G.addObserver(this),this.#G.execute(e)}#Z(){const e=this.#G?.state??{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0};this.#P={...e,isPending:"pending"===e.status,isSuccess:"success"===e.status,isError:"error"===e.status,isIdle:"idle"===e.status,mutate:this.mutate,reset:this.reset}}#V(e){ee.batch((()=>{if(this.#W&&this.hasListeners()){const t=this.#P.variables,r=this.#P.context;"success"===e?.type?(this.#W.onSuccess?.(e.data,t,r),this.#W.onSettled?.(e.data,null,t,r)):"error"===e?.type&&(this.#W.onError?.(e.error,t,r),this.#W.onSettled?.(void 0,e.error,t,r))}this.listeners.forEach((e=>{e(this.#P)}))}))}};function Te(t,r){const s=x(r),[n]=e.useState((()=>new Fe(s,t)));e.useEffect((()=>{n.setOptions(t)}),[n,t]);const a=e.useSyncExternalStore(e.useCallback((e=>n.subscribe(ee.batchCalls(e))),[n]),(()=>n.getCurrentResult()),(()=>n.getCurrentResult())),o=e.useCallback(((e,t)=>{n.mutate(e,t).catch(N)}),[n]);if(a.error&&J(n.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:o,mutateAsync:a.mutate}}const De="gb-submissions",Me="gb-forms";function qe(e,t){return`/wp/v2/gblocks-forms?${new URLSearchParams({per_page:String(t),page:String(e),status:"publish,draft,private",orderby:"modified",order:"desc",_fields:"id,title,status,modified_gmt,_gb_form_meta"}).toString()}`}function Qe(e,t,r){return`/generateblocks-pro/v1/admin/forms/${e}/submissions?${new URLSearchParams({page:String(t),per_page:String(r)}).toString()}`}function Ae({form:t,onClose:r}){const[n,o]=(0,s.useState)(!1),[c,d]=(0,s.useState)(""),[h,m]=(0,s.useState)(1),p=t?.id,f=(0,l.decodeEntities)(t?.title?.rendered||(0,i.__)("(untitled)","generateblocks-pro")),{data:g,isLoading:y,isFetching:v,isPlaceholderData:_,error:w}=function(e,{page:t=1,perPage:r=25}={}){return Ne({enabled:!!e,queryKey:[De,e,{page:t,perPage:r}],queryFn:async()=>{const s=await u()({path:Qe(e,t,r)});return{items:s.items||[],total:s.total||0,totalPages:s.totalPages||1,page:s.page||t,perPage:s.perPage||r,storageEnabled:!!s.storageEnabled,storageError:s.storageError||"",maxRecords:s.maxRecords||0,retentionDays:s.retentionDays||0}},placeholderData:V})}(p,{page:h,perPage:25}),k=function(){const e=x();return Te({mutationFn:async({formId:e,submissionId:t})=>u()({path:`/generateblocks-pro/v1/admin/forms/${e}/submissions/${t}`,method:"DELETE"}),onSuccess:(t,r)=>{e.invalidateQueries({queryKey:[De,r.formId]}),e.invalidateQueries({queryKey:[Me]})}})}(),C=function(){const e=x();return Te({mutationFn:async e=>u()({path:`/generateblocks-pro/v1/admin/forms/${e}/submissions`,method:"DELETE"}),onSuccess:(t,r)=>{e.invalidateQueries({queryKey:[De,r]}),e.invalidateQueries({queryKey:[Me]})}})}(),S=function(){const e=x();return Te({mutationFn:async({id:e,enabled:t})=>u()({path:`/generateblocks-pro/v1/admin/forms/${e}/storage`,method:"POST",data:{enabled:t}}),onSuccess:()=>{e.invalidateQueries({queryKey:[Me]}),e.invalidateQueries({queryKey:[De]})}})}(),O=g?.items||[],R=g?.total||0,P=g?.page||h,I=g?.totalPages||1,N=g?.maxRecords||0,F=g?.retentionDays||0,T=function({data:e,isLoading:t,items:r,total:s}){const n=!!e&&!t,a=!!e?.storageEnabled,o=(Number(s)||0)>0||Array.isArray(r)&&r.length>0,i=n&&!a;return{storageEnabled:a,isStorageOff:i,hasStoredSubmissions:o,showStorageOffPanel:i,showSubmissionsBody:!i||o}}({data:g,isLoading:y,items:O,total:R}),{storageEnabled:D}=T,M=t?._gb_form_meta?.health||{},q="failing"===M.status,Q=M.last_failure_gmt?(0,E.dateI18n)((0,i.__)("M j, Y @ g:i a","generateblocks-pro"),M.last_failure_gmt+"Z"):"",A=M.last_error_code||"",L=F?(0,i.sprintf)(/* translators: %d: number of days stored submissions are retained */ /* translators: %d: number of days stored submissions are retained */ (0,i._n)("%d day","%d days",F,"generateblocks-pro"),F):"",B=(0,i.sprintf)(/* translators: %s: form name */ /* translators: %s: form name */ (0,i.__)("Submissions — %s","generateblocks-pro"),f),U=(0,s.useRef)(null),j=(0,s.useRef)(null);return(0,s.useEffect)((()=>(j.current="undefined"!=typeof document?document.activeElement:null,U.current&&"function"==typeof U.current.focus&&U.current.focus(),()=>{const e=j.current;e&&"function"==typeof e.focus&&document.contains(e)&&e.focus()})),[]),(0,s.useEffect)((()=>{m(1),o(!1),d("")}),[p]),(0,s.useEffect)((()=>{!_&&g?.page&&g.page!==h&&m(g.page)}),[g?.page,_,h]),(0,e.createElement)("aside",{className:"gb-forms-dashboard__drawer",role:"dialog","aria-modal":"false","aria-label":B,onKeyDown:function(e){"Escape"===e.key&&(e.preventDefault(),r())}},(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-header"},(0,e.createElement)("div",null,(0,e.createElement)("h2",{className:"gb-forms-dashboard__drawer-title"},(0,i.__)("Submissions","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-subtitle"},f)),(0,e.createElement)("button",{ref:U,type:"button",className:"gb-forms-dashboard__drawer-close",onClick:r,"aria-label":(0,i.__)("Close","generateblocks-pro")},(0,e.createElement)(a.Icon,{icon:b,size:16}))),(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-body"},D&&(0,e.createElement)("p",{className:"gb-forms-dashboard__drawer-help"},N&&L?(0,i.sprintf)(/* translators: 1: maximum number of stored submissions, 2: retention period such as "30 days" */ /* translators: 1: maximum number of stored submissions, 2: retention period such as "30 days" */ (0,i.__)("Stores up to %1$d submissions per form. Submissions older than %2$s are automatically removed.","generateblocks-pro"),N,L):(0,i.__)("Recent submissions stored for this form. Successful and failed delivery attempts appear here while the form keeps submission storage enabled.","generateblocks-pro")),c&&(0,e.createElement)(a.Notice,{status:"error",isDismissible:!0,onRemove:()=>d("")},c),w&&(0,e.createElement)(a.Notice,{status:"error",isDismissible:!1},(0,i.__)("Failed to load submissions.","generateblocks-pro")),q&&(0,e.createElement)(a.Notice,{status:"warning",isDismissible:!1},Q?(0,i.sprintf)(/* translators: %s: failure date */ /* translators: %s: failure date */ (0,i.__)("Last delivery failed %s.","generateblocks-pro"),Q):(0,i.__)("Recent deliveries have been failing.","generateblocks-pro"),A?" "+(0,i.sprintf)(/* translators: %s: non-PII error code */ /* translators: %s: non-PII error code */ (0,i.__)("Error code: %s.","generateblocks-pro"),A):""),g?.storageError&&(0,e.createElement)(a.Notice,{status:"warning",isDismissible:!1},g.storageError),T.showStorageOffPanel&&(0,e.createElement)(Ue,{failing:q,hasStoredSubmissions:T.hasStoredSubmissions,isEnabling:S.isPending||v,onEnable:async function(){d("");try{await S.mutateAsync({id:p,enabled:!0})}catch(e){d(e?.message||(0,i.__)("Could not enable storage. Try again.","generateblocks-pro"))}}}),T.showSubmissionsBody?function({isLoading:t,isFetching:r,items:s,total:n,currentPage:o,totalPages:l,onPageChange:c,onClearAll:u,onDeleteRow:d}){return t?(0,e.createElement)(a.Spinner,null):0===s.length?(0,e.createElement)("p",{className:"gb-forms-dashboard__drawer-empty"},(0,i.__)("No stored submissions for this form.","generateblocks-pro")):(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-actions"},(0,e.createElement)(a.Button,{variant:"secondary",isDestructive:!0,onClick:u},(0,i.__)("Clear all","generateblocks-pro"))),(0,e.createElement)(Le,{currentPage:o,totalPages:l,total:n,isFetching:r,onPageChange:c}),(0,e.createElement)("ul",{className:"gb-forms-dashboard__drawer-list"},s.map((t=>(0,e.createElement)(Be,{key:t.id,item:t,onDelete:()=>d(t)})))),(0,e.createElement)(Le,{currentPage:o,totalPages:l,total:n,isFetching:r,onPageChange:c}))}({isLoading:y,isFetching:v,items:O,total:R,currentPage:P,totalPages:I,onPageChange:m,onClearAll:()=>{o(!0),d("")},onDeleteRow:async e=>{d("");try{await k.mutateAsync({formId:p,submissionId:e.id})}catch(e){d(e?.message||(0,i.__)("Could not delete record. Try again.","generateblocks-pro"))}}}):null),n&&(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-confirm"},(0,e.createElement)("p",null,(0,i.sprintf)(/* translators: %d: number of records that will be cleared */ /* translators: %d: number of records that will be cleared */ (0,i.__)("Permanently clear all %d stored submissions for this form?","generateblocks-pro"),R)),(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-confirm-actions"},(0,e.createElement)(a.Button,{variant:"primary",isDestructive:!0,isBusy:C.isPending,onClick:async()=>{d("");try{await C.mutateAsync(p),m(1),o(!1)}catch(e){d(e?.message||(0,i.__)("Could not clear records. Try again.","generateblocks-pro")),o(!1)}}},(0,i.__)("I'm sure","generateblocks-pro")),(0,e.createElement)(a.Button,{variant:"tertiary",onClick:()=>o(!1)},(0,i.__)("Cancel","generateblocks-pro")))))}function Le({currentPage:t,totalPages:r,total:s,isFetching:n,onPageChange:o}){return r<=1?null:(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-pagination"},(0,e.createElement)(a.Button,{variant:"secondary",disabled:t<=1||n,onClick:()=>o(t-1)},(0,i.__)("Previous","generateblocks-pro")),(0,e.createElement)("span",null,(0,i.sprintf)(/* translators: 1: current page, 2: total pages, 3: total submissions */ /* translators: 1: current page, 2: total pages, 3: total submissions */ (0,i.__)("Page %1$d of %2$d (%3$d total)","generateblocks-pro"),t,r,s)),(0,e.createElement)(a.Button,{variant:"secondary",disabled:t>=r||n,onClick:()=>o(t+1)},(0,i.__)("Next","generateblocks-pro")))}function Be({item:t,onDelete:r}){const[n,o]=(0,s.useState)(!1),l=t.submittedAtGmt,c=l?(0,E.dateI18n)((0,i.__)("M j, Y @ g:i a","generateblocks-pro"),l+"Z"):"",u=function(e){switch(e){case"processed":return(0,i.__)("Processed","generateblocks-pro");case"failed":return(0,i.__)("Failed","generateblocks-pro");default:return(0,i.__)("Received","generateblocks-pro")}}(t.status),d=t.errors?.[0]||"",h=t.fields||{},m=Object.values(h),p=m.find((e=>"email"===e?.type&&e?.value)),f=p?.value||m.find((e=>{var t;return e&&""!==(null!==(t=e.value)&&void 0!==t?t:"")}))?.value||"",g=String(f||""),b=g.length>50?g.slice(0,50)+"…":g;return(0,e.createElement)("li",{className:"gb-forms-dashboard__drawer-row"},(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-row-summary"},(0,e.createElement)("div",null,(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-row-date"},c),(0,e.createElement)("div",{className:`gb-forms-dashboard__drawer-row-status gb-forms-dashboard__drawer-row-status--${t.status}`},d?(0,i.sprintf)(/* translators: 1: submission status, 2: error message */ /* translators: 1: submission status, 2: error message */ (0,i.__)("%1$s: %2$s","generateblocks-pro"),u,d):u),b&&(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-row-preview"},b)),(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-row-actions"},(0,e.createElement)(a.Button,{variant:"link",onClick:()=>o((e=>!e))},n?(0,i.__)("Hide","generateblocks-pro"):(0,i.__)("View","generateblocks-pro")),(0,e.createElement)(a.Button,{variant:"link",isDestructive:!0,onClick:r},(0,i.__)("Delete","generateblocks-pro")))),n&&(0,e.createElement)("dl",{className:"gb-forms-dashboard__drawer-row-detail"},Object.entries(h).map((([t,r])=>{var s;return(0,e.createElement)("div",{key:t},(0,e.createElement)("dt",null,r?.label||t),(0,e.createElement)("dd",null,String(null!==(s=r?.value)&&void 0!==s?s:"")||(0,e.createElement)("em",null,(0,i.__)("(empty)","generateblocks-pro"))))})),(t.errors||[]).length>0&&(0,e.createElement)("div",null,(0,e.createElement)("dt",null,(0,i.__)("Errors","generateblocks-pro")),(0,e.createElement)("dd",null,(0,e.createElement)("ul",null,t.errors.map(((t,r)=>(0,e.createElement)("li",{key:r},t))))))))}function Ue({failing:t,hasStoredSubmissions:r,isEnabling:s,onEnable:n}){let o=(0,i.__)("Submission storage is off for this form. Nothing is being recorded.","generateblocks-pro");return r?o=(0,i.__)("Submission storage is off for this form. Existing stored submissions are still available below, but new submissions will not be recorded until storage is turned back on.","generateblocks-pro"):t&&(o=(0,i.__)("Submission storage is off for this form, so the submitted data wasn’t kept and can’t be recovered.","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-forms-dashboard__drawer-storage-off"},(0,e.createElement)("p",{className:"gb-forms-dashboard__drawer-empty"},o),(0,e.createElement)(a.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Store future submissions","generateblocks-pro"),help:(0,i.__)("Keep new submissions — including failed deliveries — in this dashboard as a recovery safety net. Submissions already lost can’t be recovered.","generateblocks-pro"),checked:!1,disabled:s,onChange:()=>n()}))}const je=(0,s.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,s.createElement)(f.Path,{d:"m11.3 17.2-5-5c-.1-.1-.1-.3 0-.4l2.3-2.3-1.1-1-2.3 2.3c-.7.7-.7 1.8 0 2.5l5 5H7.5v1.5h5.3v-5.2h-1.5v2.6zm7.5-6.4-5-5h2.7V4.2h-5.2v5.2h1.5V6.8l5 5c.1.1.1.3 0 .4l-2.3 2.3 1.1 1.1 2.3-2.3c.6-.7.6-1.9-.1-2.5z"})),$e=(0,s.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,s.createElement)(f.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"}));function Ke({usageData:t,loading:r,error:s,emptyMessage:n,onRetry:o,formatUsageType:l}){const c=l||(e=>({global_style_usage:(0,i.__)("Global Style Usage","generateblocks-pro"),manual_class_usage:(0,i.__)("Manual Class Usage","generateblocks-pro"),overlay_display_condition:(0,i.__)("Overlay Display Condition","generateblocks-pro"),block_conditions:(0,i.__)("Block Conditions","generateblocks-pro"),menu_item_conditions:(0,i.__)("Menu Item Conditions","generateblocks-pro")}[e]||e)),u=t&&t.usage&&0d.scanned_posts?(0,i.sprintf)(/* translators: 1: number of posts scanned, 2: total eligible posts */ /* translators: 1: number of posts scanned, 2: total eligible posts */ (0,i.__)("Only the most recent %1$d of %2$d eligible posts were scanned. Older content may still reference this item — verify before deleting.","generateblocks-pro"),d.scanned_posts,d.total_posts):(0,i.__)("Usage search was limited for performance. Older content may still reference this item — verify before deleting.","generateblocks-pro"))):(0,e.createElement)("p",{style:{fontSize:"14px",textAlign:"center",color:"#999"}},(0,i.__)("You can safely delete it, or keep it for future use.","generateblocks-pro"))),u&&(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,i.__)("Found usage in","generateblocks-pro")," ",(0,e.createElement)("strong",null,t.total),t.has_more&&"+"," ",1===t.total?(0,i.__)("location","generateblocks-pro"):(0,i.__)("locations","generateblocks-pro"))),t.cached&&t.cached_at&&(0,e.createElement)("div",{style:{background:"#f0f6fc",border:"1px solid #0969da",padding:"12px 16px",borderRadius:"4px",marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"5px"}},(0,e.createElement)("span",{style:{fontSize:"13px",color:"#0969da"}},(0,i.sprintf)(/* translators: %s: time ago (e.g., "5 minutes") */ /* translators: %s: time ago (e.g., "5 minutes") */ (0,i.__)("Showing cached results from %s ago.","generateblocks-pro"),(e=>{const t=Math.floor(Date.now()/1e3)-e;if(t<60)return(0,i.__)("less than a minute","generateblocks-pro");if(t<3600){const e=Math.max(1,Math.floor(t/60));return(0,i.sprintf)(/* translators: %d: number of minutes */ /* translators: %d: number of minutes */ (0,i._n)("%d minute","%d minutes",e,"generateblocks-pro"),e)}const r=Math.max(1,Math.floor(t/3600));return(0,i.sprintf)(/* translators: %d: number of hours */ /* translators: %d: number of hours */ (0,i._n)("%d hour","%d hours",r,"generateblocks-pro"),r)})(t.cached_at))),(0,e.createElement)(a.Button,{variant:"secondary",size:"compact",onClick:o,icon:je},(0,i.__)("Refresh","generateblocks-pro"))),h&&(0,e.createElement)("div",{style:{background:"#f0f6fc",border:"1px solid #0969da",padding:"12px",borderRadius:"4px",marginBottom:"16px"}},(0,e.createElement)("p",{style:{margin:"0",fontSize:"13px",color:"#0969da"}},(0,e.createElement)("strong",null,(0,i.__)("Heads up:","generateblocks-pro"))," ",d.total_posts&&d.total_posts>d.scanned_posts?(0,i.sprintf)(/* translators: 1: number of posts scanned, 2: total eligible posts */ /* translators: 1: number of posts scanned, 2: total eligible posts */ (0,i.__)("For performance, only the most recent %1$d of %2$d eligible posts were scanned. Older content may still reference this item.","generateblocks-pro"),d.scanned_posts,d.total_posts):(0,i.sprintf)(/* translators: %d: number of posts scanned */ /* translators: %d: number of posts scanned */ (0,i.__)("For performance, the search was limited to the most recent %d posts. Older content may still reference this item.","generateblocks-pro"),d.scanned_posts||d.max_posts))),m&&(0,e.createElement)("div",{style:{background:"#f0f6fc",border:"1px solid #0969da",padding:"12px",borderRadius:"4px",marginBottom:"16px"}},(0,e.createElement)("p",{style:{margin:"0",fontSize:"13px",color:"#0969da"}},(0,e.createElement)("strong",null,(0,i.__)("Note:","generateblocks-pro"))," ",(0,i.__)("Results limited to most recent posts for performance. There may be additional usage in older content.","generateblocks-pro"))),(0,e.createElement)("div",{className:"gb-modal-usage-sections"},Object.entries(t.usage).map((([t,r])=>(0,e.createElement)("div",{key:t,className:"gb-modal-usage-section"},(0,e.createElement)("h4",{className:"gb-modal-usage-section-title"},r.label,(0,e.createElement)("span",{className:"gb-modal-usage-count"},"(",r.items.length,r.has_more&&"+",")")),(0,e.createElement)("div",{className:"gb-modal-usage-items"},r.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.status&&(t=>{const r={publish:(0,i.__)("Published","generateblocks-pro"),draft:(0,i.__)("Draft","generateblocks-pro"),private:(0,i.__)("Private","generateblocks-pro")},s={publish:{bg:"#d1fae5",color:"#065f46",border:"#a7f3d0"},draft:{bg:"#fef3c7",color:"#92400e",border:"#fcd34d"},private:{bg:"#e0e7ff",color:"#3730a3",border:"#c7d2fe"}},n=s[t]||s.draft;return(0,e.createElement)("span",{style:{background:n.bg,color:n.color,border:`1px solid ${n.border}`,padding:"2px 6px",borderRadius:"4px",fontSize:"11px",fontWeight:"500",textTransform:"uppercase"}},r[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"},c(t.usage_type),t.block_count>1&&(0,e.createElement)("span",{style:{marginLeft:"5px",opacity:.7}},"(",t.block_count," ",(0,i.__)("blocks","generateblocks-pro"),")")))),(0,e.createElement)("div",{className:"gb-modal-usage-item-actions"},t.edit_url&&(0,e.createElement)(a.Button,{variant:"secondary",size:"compact",icon:$e,href:t.edit_url,target:"_blank",iconSize:"14"},(0,i.__)("Edit","generateblocks-pro")),t.view_url&&(0,e.createElement)(a.Button,{variant:"tertiary",size:"compact",icon:g,href:t.view_url,target:"_blank",iconSize:"14"},(0,i.__)("View","generateblocks-pro"))))))))))))))}function He(e){return"string"==typeof e?e:e&&"object"==typeof e?"string"==typeof e.rendered?e.rendered:"string"==typeof e.raw?e.raw:"":""}function ze(e){if(!e||!e.id)return null;const t=Number(e.id);if(!Number.isFinite(t)||t<=0)return null;const r={...e,id:t,title:{rendered:He(e.title)}};return"string"!=typeof r.status&&(r.status=""),r}const Ve=e=>({form_render_block:(0,i.__)("Form embed","generateblocks-pro")}[e]||e);function Ge({form:t,onClose:r}){const n=(0,l.decodeEntities)(He(t?.title)||(0,i.__)("Untitled Form","generateblocks-pro")),{usageData:o,loading:c,error:d,reload:h}=function(e,t=50){const[r,n]=(0,s.useState)(null),[a,o]=(0,s.useState)(!0),[l,c]=(0,s.useState)(null),d=(0,s.useRef)(null),h=(0,s.useCallback)((async(r=!1)=>{d.current&&d.current.abort(),d.current=new AbortController;const s=d.current;try{o(!0),c(null);const a=e.includes("?")?"&":"?",l=r?"&refresh=true":"",d=await u()({path:`${e}${a}limit=${t}${l}`,signal:s.signal});if(!d.success)return void c(d.response||(0,i.__)("Failed to load usage data","generateblocks-pro"));const h=d.response.data||d.response;n(h)}catch(e){if("AbortError"===e.name)return;console.error("Error loading usage data:",e);const t=e?.message||(0,i.__)("Error loading usage data. Please try again.","generateblocks-pro");c(t)}finally{o(!1)}}),[e,t]);return(0,s.useEffect)((()=>(h(!1),()=>{d.current&&d.current.abort()})),[h]),{usageData:r,loading:a,error:l,reload:(0,s.useCallback)((()=>{h(!0)}),[h])}}(`/generateblocks-pro/v1/admin/forms/${t.id}/usage`);return(0,e.createElement)(a.Modal,{title:n,onRequestClose:r,className:"gb-modal-form-usage",size:"medium"},(0,e.createElement)(Ke,{usageData:o,loading:c,error:d,emptyMessage:(0,i.__)("This form is not currently embedded anywhere on your site.","generateblocks-pro"),onRetry:h,formatUsageType:Ve}))}function We({isModalMode:t=!1,onItemSelect:r=null,onCreateItem:n=null}){const[o,c]=(0,s.useState)(1),[d,h]=(0,s.useState)(null),[m,p]=(0,s.useState)(null),[f,g]=(0,s.useState)(null),[b,y]=(0,s.useState)(!1),[v,_]=(0,s.useState)(!1),[O,R]=(0,s.useState)(null),[P,I]=(0,s.useState)(null),[N,F]=(0,s.useState)(null),T=(0,s.useRef)(0),D=(0,s.useRef)(null),{data:M,isLoading:q,error:Q}=function({page:e=1,perPage:t=50}={}){return Ne({queryKey:[Me,{page:e,perPage:t}],queryFn:async()=>{const r=await async function(e){const t={...e,parse:!1};try{return await u()(t)}catch(e){if(!await async function(e){if("rest_cookie_invalid_nonce"===e?.code)return!0;if(403!==e?.status||"function"!=typeof e.clone)return!1;try{const t=await e.clone().json();return"rest_cookie_invalid_nonce"===t?.code}catch{return!1}}(e))throw e;if(!await async function(){if(!u()?.nonceEndpoint||!u()?.nonceMiddleware||"undefined"==typeof window||"function"!=typeof window.fetch)return!1;let e,t;try{e=await window.fetch(u().nonceEndpoint,{credentials:"include"})}catch{return!1}if(!e?.ok||"function"!=typeof e.text)return!1;try{t=await e.text()}catch{return!1}return!!t&&(u().nonceMiddleware.nonce=t,"object"==typeof window.wpApiSettings&&window.wpApiSettings&&(window.wpApiSettings.nonce=t),!0)}())throw e;return u()(t)}}({path:qe(e,t)}),s=await r.json(),n=parseInt(r.headers.get("X-WP-TotalPages"),10)||1;return{forms:Array.isArray(s)?s:[],totalPages:n}},placeholderData:V})}({page:o}),A=function(){const e=x();return Te({mutationFn:async e=>{const{id:t,force:r=!1}="object"==typeof e&&null!==e?e:{id:e},s=r?`/generateblocks-pro/v1/admin/forms/${t}?force=true`:`/generateblocks-pro/v1/admin/forms/${t}`;try{return await u()({path:s,method:"DELETE"})}catch(e){if(e&&"form_in_use"===e.code){const t=new Error(e.message);throw t.code="form_in_use",t.usage=e.data?.usage||null,t}throw e}},onSuccess:()=>{e.invalidateQueries({queryKey:[Me]})}})}(),L=function(){const e=x();return Te({mutationFn:async({id:e,status:t})=>u()({path:`/wp/v2/gblocks-forms/${e}`,method:"POST",data:{status:t}}),onSuccess:()=>{e.invalidateQueries({queryKey:[Me]})}})}(),B=function(){const e=x();return Te({mutationFn:async e=>u()({path:`/generateblocks-pro/v1/admin/forms/${e}/duplicate`,method:"POST"}),onSuccess:()=>{e.invalidateQueries({queryKey:[Me]})}})}(),U=M?.forms||[],j=M?.totalPages||1,$=()=>{D.current&&(D.current.abort(),D.current=null),T.current++,h(null),p(null),g(null),y(!1),R(null)},K=(0,s.useMemo)((()=>{const s=[];return s.push({id:"name",header:(0,i.__)("Form","generateblocks-pro"),cell:s=>{const n=s.row.original,o=(0,l.decodeEntities)(n?.title?.rendered||(0,i.__)("(untitled)","generateblocks-pro")),c="draft"===n?.status,u=t&&r?(0,e.createElement)(a.Button,{variant:"link",onClick:()=>r(n),style:{padding:0,minHeight:"auto",textDecoration:"none"}},o):(0,e.createElement)("a",{href:w("post.php",{post:n.id,action:"edit"})},o);return(0,e.createElement)("div",{style:{display:"flex",alignItems:"center",gap:"8px"}},u,c&&(0,e.createElement)("span",{style:{color:"#999",fontSize:"0.9em"}},"(",(0,i.__)("draft","generateblocks-pro"),")"))}}),t||s.push({id:"submissions",header:(0,i.__)("Submissions","generateblocks-pro"),cell:t=>{var r,s;const n=t.row.original,o=n?._gb_form_meta||{},l=null!==(r=o.submission_count)&&void 0!==r?r:0,c=null!==(s=o.failed_submission_count)&&void 0!==s?s:0,u=!!o.storage_enabled;if("failing"===o.health?.status||c>0){const t=c>0?(0,i.sprintf)(/* translators: %d: number of failed submissions */ /* translators: %d: number of failed submissions */ (0,i._n)("%d failed","%d failed",c,"generateblocks-pro"),c):(0,i.__)("Delivery failing","generateblocks-pro"),r=c>0?(0,i.sprintf)(/* translators: %d: number of failed submissions */ /* translators: %d: number of failed submissions */ (0,i._n)("View %d failed submission","View %d failed submissions",c,"generateblocks-pro"),c):(0,i.__)("A delivery failed. Open for details.","generateblocks-pro");return(0,e.createElement)(a.Button,{className:"gb-form-submissions-pill gb-form-submissions-pill--failure",onClick:()=>F(n),label:r,showTooltip:!0},(0,e.createElement)(a.Icon,{icon:k,size:16}),t)}if(l>0){const t=(0,i.sprintf)(/* translators: %d: number of stored submissions */ /* translators: %d: number of stored submissions */ (0,i._n)("View %d stored submission","View %d stored submissions",l,"generateblocks-pro"),l);return(0,e.createElement)(a.Button,{className:"gb-form-submissions-pill gb-form-submissions-pill--ok",onClick:()=>F(n),label:t,showTooltip:!0},(0,i.sprintf)(/* translators: %d: number of stored submissions */ /* translators: %d: number of stored submissions */ (0,i._n)("%d submission","%d submissions",l,"generateblocks-pro"),l))}return u?(0,e.createElement)(a.Button,{className:"gb-form-submissions-pill gb-form-submissions-pill--ok",onClick:()=>F(n),label:(0,i.__)("View stored submissions","generateblocks-pro"),showTooltip:!0},(0,i.__)("No submissions yet","generateblocks-pro")):(0,e.createElement)(a.Button,{className:"gb-form-submissions-pill gb-form-submissions-pill--off",onClick:()=>F(n),label:(0,i.__)("Submission storage is off. Open to enable.","generateblocks-pro"),showTooltip:!0},(0,i.__)("Storage off","generateblocks-pro"))}}),s.push({id:"modified",header:(0,i.__)("Modified","generateblocks-pro"),cell:e=>{const t=e.row.original.modified_gmt;return t?(0,E.dateI18n)((0,i.__)("M j, Y @ g:i a","generateblocks-pro"),t+"Z"):""}}),t&&r?(s.push({id:"actions",header:null,cell:t=>(0,e.createElement)(a.Button,{variant:"link",onClick:()=>r(t.row.original)},(0,i.__)("Edit","generateblocks-pro"))}),s):(s.push({id:"actions",header:null,cell:t=>{const r=t.row.original,{id:s,status:n}=r;return(0,e.createElement)(a.DropdownMenu,{icon:C,label:(0,i.__)("More options","generateblocks-pro")},(({onClose:t})=>(0,e.createElement)(e.Fragment,null,(0,e.createElement)(a.MenuGroup,null,(0,e.createElement)(a.MenuItem,{href:w("post.php",{post:s,action:"edit"})},(0,i.__)("Edit Form","generateblocks-pro")),(0,e.createElement)(a.MenuItem,{onClick:()=>{B.mutateAsync(s).catch((()=>{})),t()}},(0,i.__)("Duplicate","generateblocks-pro"))),(0,e.createElement)(a.MenuGroup,null,(0,e.createElement)(a.MenuItem,{onClick:()=>{I(r),t()}},(0,i.__)("Check Usage","generateblocks-pro"))),(0,e.createElement)(a.MenuGroup,null,(0,e.createElement)(a.MenuItem,{onClick:()=>{const e="publish"===n?"draft":"publish";L.mutateAsync({id:s,status:e}).catch((()=>{})),t()}},"publish"===n?(0,i.__)("Set as Draft","generateblocks-pro"):(0,i.__)("Publish","generateblocks-pro")),(0,e.createElement)(a.MenuItem,{isDestructive:!0,onClick:()=>{(e=>{h(e),p(null),g(null),y(!1),R(null),(async e=>{D.current&&D.current.abort();const t=++T.current,r=new AbortController;D.current=r,_(!0),y(!1);try{const s=await u()({path:`/generateblocks-pro/v1/admin/forms/${e}/usage?refresh=true`,signal:r.signal});if(t!==T.current)return;s?.success?g(s.response):y(!0)}catch(e){if("AbortError"===e?.name)return;if(t!==T.current)return;y(!0)}finally{t===T.current&&_(!1)}})(e.id)})(r),t()}},(0,i.__)("Delete Form","generateblocks-pro"))))))}}),s)}),[t,r,B,L,F]);return q?(0,e.createElement)("div",{className:"gb-dashboard-admin"},(0,e.createElement)(a.Spinner,null)):(0,e.createElement)("div",{className:"gb-dashboard-admin gb-forms-dashboard"},(0,e.createElement)("div",{className:"gb-dashboard-admin__header"},(0,e.createElement)(a.Button,{variant:"primary",onClick:()=>{t&&n?n():window.location.href=w("post-new.php",{post_type:"gblocks_form"})}},(0,i.__)("Add New","generateblocks-pro"))),Q&&(0,e.createElement)(a.Notice,{status:"error",isDismissible:!1},(0,i.__)("Failed to load forms.","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-dashboard-admin__inner"},0===U.length?(0,e.createElement)("div",{className:"gb-forms-dashboard__empty"},(0,e.createElement)("p",null,(0,e.createElement)("strong",null,(0,i.__)("No forms yet.","generateblocks-pro"))),(0,e.createElement)("p",null,(0,i.__)("Add a Form block to a page to create your first one, or click Add New above.","generateblocks-pro"))):(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"gb-dashboard-table-wrapper"},(0,e.createElement)(S.Table,{className:"gb-dashboard-table table-view-list gb-forms-table",columns:K,data:U,"aria-label":(0,i.__)("Forms","generateblocks-pro")})),j>1&&(0,e.createElement)("div",{className:"gb-dashboard__pagination"},(0,e.createElement)(a.Button,{disabled:1===o,onClick:()=>c(o-1),variant:"secondary"},(0,i.__)("Previous","generateblocks-pro")),(0,e.createElement)("span",null,(0,i.sprintf)(/* translators: %1$s: current; %2$s: total */ /* translators: %1$s: current; %2$s: total */ (0,i.__)("Page %1$s of %2$s","generateblocks-pro"),o,j)),(0,e.createElement)(a.Button,{disabled:o>=j,onClick:()=>c(o+1),variant:"secondary"},(0,i.__)("Next","generateblocks-pro"))))),N&&!t&&(0,e.createElement)(Ae,{form:N,onClose:()=>F(null)}),!!d&&(0,e.createElement)(a.Modal,{title:(0,i.__)("Confirm Delete","generateblocks-pro"),onRequestClose:$,className:"gb-styles-table-modal",size:"small",focusOnMount:"firstContentElement"},(()=>{const t=O||f,r=!!t&&t.total>0,s=t?.limited||!!t?.limitations?.recent_post_scan,n=!!t?.has_more,o=O||r||b||s||n?(0,i.__)("Delete anyway","generateblocks-pro"):(0,i.__)("I'm sure","generateblocks-pro"),c=!!O||r;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"gb-styles-table-modal__content"},v&&(0,e.createElement)("p",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"16px"}},(0,e.createElement)(a.Spinner,null),(0,i.__)("Checking usage…","generateblocks-pro")),!v&&r&&(0,e.createElement)("div",{style:{background:"#fee",border:"1px solid #dc3232",padding:"12px",borderRadius:"4px",marginBottom:"16px"}},(0,e.createElement)("p",{style:{margin:"0 0 8px 0"}},(0,e.createElement)("strong",null,(0,i.__)("Warning:","generateblocks-pro"))," ",t.has_more?(0,i.sprintf)(/* translators: %s: number of locations where the form is used */ /* translators: %s: number of locations where the form is used */ (0,i.__)("This form is currently embedded in at least %s locations:","generateblocks-pro"),t.total):(0,i.sprintf)(/* translators: %s: number of locations where the form is used */ /* translators: %s: number of locations where the form is used */ (0,i.__)("This form is currently embedded in %s locations:","generateblocks-pro"),t.total)),Object.entries(t.usage).slice(0,2).map((([t,r])=>(0,e.createElement)("div",{key:t,style:{marginTop:"8px"}},(0,e.createElement)("strong",null,r.label,":"),(0,e.createElement)("ul",{style:{margin:"4px 0 0 20px",padding:0}},r.items.slice(0,3).map((t=>(0,e.createElement)("li",{key:t.id},t.title))),r.items.length>3&&(0,e.createElement)("li",null,(0,i.sprintf)(/* translators: %s: number of additional items */ /* translators: %s: number of additional items */ (0,i.__)("…and %s more","generateblocks-pro"),r.items.length-3)))))),(0,e.createElement)("p",{style:{margin:"8px 0 0 0",fontSize:"13px"}},(0,i.__)("Deleting this form removes the submission UI — pages that embed it will render nothing on the frontend until the embed is removed.","generateblocks-pro"))),!v&&!r&&s&&(0,e.createElement)("div",{style:{background:"#fff8e1",border:"1px solid #f0b849",padding:"12px",borderRadius:"4px",marginBottom:"16px"}},(0,e.createElement)("p",{style:{margin:0,fontSize:"13px"}},(0,e.createElement)("strong",null,(0,i.__)("Heads up:","generateblocks-pro"))," ",(0,i.__)("Usage search was limited for performance and may not have checked every post. This form may still be embedded in older content.","generateblocks-pro"))),!v&&!r&&!s&&n&&(0,e.createElement)("div",{style:{background:"#fff8e1",border:"1px solid #f0b849",padding:"12px",borderRadius:"4px",marginBottom:"16px"}},(0,e.createElement)("p",{style:{margin:0,fontSize:"13px"}},(0,e.createElement)("strong",null,(0,i.__)("Heads up:","generateblocks-pro"))," ",(0,i.__)("Additional usage may exist beyond what was returned. Proceed with caution.","generateblocks-pro"))),!v&&b&&(0,e.createElement)("div",{style:{background:"#fff8e1",border:"1px solid #f0b849",padding:"12px",borderRadius:"4px",marginBottom:"16px"}},(0,e.createElement)("p",{style:{margin:0,fontSize:"13px"}},(0,e.createElement)("strong",null,(0,i.__)("Heads up:","generateblocks-pro"))," ",(0,i.__)("Could not verify whether this form is in use. Deletion will still be checked server-side before it is removed.","generateblocks-pro"))),(0,e.createElement)("p",null,(0,i.sprintf)(/* translators: %s: form title being deleted */ /* translators: %s: form title being deleted */ (0,i.__)("Are you sure you want to delete %s?","generateblocks-pro"),`"${(0,l.decodeEntities)(d?.title?.rendered||(0,i.__)("this form","generateblocks-pro"))}"`)),(0,e.createElement)("p",null,(0,i.__)("Any stored submissions attached to this form will also be removed.","generateblocks-pro")," ",(0,e.createElement)("strong",null,(0,i.__)("This cannot be undone","generateblocks-pro")),"."),!!m&&(0,e.createElement)("p",{style:{color:"#d63638"}},m)),(0,e.createElement)("div",{className:"gb-styles-table-modal__actions"},(0,e.createElement)(a.Button,{variant:"tertiary",onClick:$,disabled:A.isPending},(0,i.__)("Cancel","generateblocks-pro")),(0,e.createElement)(a.Button,{variant:"primary",isDestructive:!0,disabled:v||A.isPending,onClick:async()=>{p(null);try{await A.mutateAsync({id:d.id,force:c}),$()}catch(e){if(e&&"form_in_use"===e.code&&e.usage)return void R(e.usage);p(e?.message||(0,i.__)("Failed to delete form.","generateblocks-pro"))}}},o)))})()),!!P&&(0,e.createElement)(Ge,{form:P,onClose:()=>I(null)}))}function Ze(t){return(0,e.createElement)(P,{client:Ee()},(0,e.createElement)(We,{...t}))}function Ye({formId:t,embedded:r=!1,onUnsavedChanges:n=null,onSave:a=null}){const[o,l]=(0,s.useState)(!0),[c,u]=(0,s.useState)(!1),d=(0,s.useRef)(null);if((0,s.useEffect)((()=>{l(!0),u(!1)}),[t]),(0,s.useEffect)((()=>{r&&n&&n(c)}),[r,c,n]),(0,s.useEffect)((()=>{const e=e=>{if(e.origin===window.location.origin&&(!d.current?.contentWindow||e.source===d.current.contentWindow)&&e.data&&"object"==typeof e.data)if("gb_unsaved_changes"!==e.data.type){if("gb_form_saved"===e.data.type&&a){const t=ze({id:Number(e.data.formId),title:e.data.formTitle||"",status:e.data.formStatus||"draft"});t&&a({...t,isNew:!!e.data.isNew})}}else u(!!e.data.hasChanges)};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[a]),!t)return null;const h={gb_form_context:1};r&&(h.gb_embedded_form=1);const m="new"===t?w("post-new.php",{post_type:"gblocks_form",...h}):w("post.php",{post:t,action:"edit",...h});return(0,e.createElement)("div",{className:"gb-modal-container gb-modal-embedded"},o&&(0,e.createElement)("div",{className:"gb-modal-loading"},(0,e.createElement)("div",{className:"gb-loading-content"},(0,e.createElement)("div",{className:"gb-loading-title"},(0,i.__)("Loading editor…","generateblocks-pro")),(0,e.createElement)("div",{className:"gb-loading-subtitle"},(0,i.__)("Please wait while the form editor loads.","generateblocks-pro")))),(0,e.createElement)("div",{className:"gb-modal-iframe-container "+(o?"gb-modal-iframe-hidden":"gb-modal-iframe-visible")},(0,e.createElement)("iframe",{ref:d,src:m,onLoad:()=>l(!1),title:(0,i.__)("Form Editor","generateblocks-pro")})))}function Je({trigger:t,formId:r=null,onFormSave:n=null,modalProps:a={}}){const o=!!window.generateBlocksPro?.canManageForms,l=(0,s.useCallback)((e=>{Ee().invalidateQueries({queryKey:[Me]}),n&&n(e)}),[n]),c=(0,s.useCallback)((e=>"new"===e?w("post-new.php",{post_type:"gblocks_form"}):w("post.php",{post:e,action:"edit"})),[]);return o?(0,e.createElement)(v,{trigger:t,itemId:r,itemType:"form",dashboardView:(0,e.createElement)(Ze,null),editorView:(0,e.createElement)(Ye,null),onEditorSave:l,modalProps:a,labels:{backButton:(0,i.__)("Back to Forms","generateblocks-pro"),createNew:(0,i.__)("Create New Form","generateblocks-pro"),edit:(0,i.__)("Edit Form","generateblocks-pro"),dashboard:(0,i.__)("Forms","generateblocks-pro")},className:"gb-forms-dashboard-fullscreen",getNewTabUrl:c}):null}const Xe="id,title,status,modified";function et(e){return e?"edit":"view"}const tt="gblocks_form",rt=[];function st(e){return(0,l.decodeEntities)(He(e?.title)||(0,i.__)("(untitled)","generateblocks-pro"))+(e?.status&&"publish"!==e.status?` (${e.status})`:"")}function nt({onSelect:t,forms:r,loading:n,canCreate:o,createAction:l,onSearchChange:c}){const u=(0,s.useMemo)((()=>(r||[]).map((e=>({label:st(e),value:String(e.id)})))),[r]);return(0,e.createElement)(a.Placeholder,{label:(0,i.__)("Form","generateblocks-pro"),instructions:o?(0,i.__)("Select a form to embed, or create a new one.","generateblocks-pro"):(0,i.__)("Select a published form to embed.","generateblocks-pro"),isColumnLayout:!0},n?(0,e.createElement)(a.Spinner,null):(0,e.createElement)(e.Fragment,null,(0,e.createElement)(a.ComboboxControl,{label:(0,i.__)("Select a form","generateblocks-pro"),value:"",options:u,onChange:e=>{const r=parseInt(e,10);r>0&&t(r)},onFilterValueChange:c,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),!o&&0===(r||[]).length&&(0,e.createElement)(a.Notice,{status:"info",isDismissible:!1},(0,i.__)("No published forms are available yet.","generateblocks-pro"))),o&&l&&(0,e.createElement)("div",{style:{marginTop:"1em"}},l))}function at({formId:t,refreshKey:r,onReplace:n}){const[o,l]=(0,s.useState)(""),[c,d]=(0,s.useState)(""),[h,m]=(0,s.useState)(!0),p=(0,s.useRef)(null);return(0,s.useEffect)((()=>{if(!t)return;p.current&&p.current.abort();const e=new AbortController;return p.current=e,m(!0),d(""),u()({path:`/generateblocks-pro/v1/forms/${t}/preview`,signal:e.signal}).then((e=>{e.success?l(e.html||""):d(e.message||(0,i.__)("Failed to load form preview.","generateblocks-pro"))})).catch((e=>{"AbortError"!==e.name&&d((0,i.__)("Failed to load form preview.","generateblocks-pro"))})).finally((()=>{p.current===e&&m(!1)})),()=>{p.current&&p.current.abort()}}),[t,r]),h?(0,e.createElement)("div",{className:"gb-form-render gb-form-render--loading"},(0,e.createElement)(a.Spinner,null)):c?(0,e.createElement)(a.Notice,{status:"error",isDismissible:!1},c," ",(0,e.createElement)(a.Button,{variant:"link",onClick:n},(0,i.__)("Choose a different form","generateblocks-pro"))):(0,e.createElement)("div",{className:"gb-form-render"},(0,e.createElement)(s.RawHTML,null,o))}const ot=JSON.parse('{"UU":"generateblocks-pro/form-render"}');(0,t.registerBlockType)(ot.UU,{edit:function({attributes:t,setAttributes:r,clientId:l,name:c}){const{formId:u}=t,d=!!window.generateBlocksPro?.canManageForms,[h,m]=(0,s.useState)(0),[f,g]=(0,s.useState)(null),[b,y]=(0,s.useState)(""),v=(0,s.useMemo)((()=>function(e,t=""){const r={per_page:100,status:e?["publish","draft","private"]:["publish"],context:et(e),orderby:"modified",order:"desc",_fields:Xe};return t&&(r.search=t),r}(d,b)),[d,b]),_=(0,s.useMemo)((()=>function(e){return{context:et(e),_fields:Xe}}(d)),[d]),{forms:w,currentFormRecord:E,isLoadingForms:k}=(0,o.useSelect)((e=>{const{getEntityRecords:t,getEntityRecord:r,isResolving:s}=e("core");return{forms:t("postType",tt,v)||rt,currentFormRecord:u?r("postType",tt,u,_):null,isLoadingForms:s("core","getEntityRecords",["postType",tt,v])}}),[u,v,_]),C=(0,s.useMemo)((()=>function(e=[],...t){const r=Array.isArray(e)?[...e]:[];return t.forEach((e=>{const t=ze(e);if(!t)return;const s=r.findIndex((e=>Number(e.id)===t.id));-1!==s?r[s]={...r[s],...t,title:t.title}:r.unshift(t)})),r}(w,E,f)),[w,E,f]),S=(0,s.useMemo)((()=>C.find((e=>Number(e.id)===Number(u)))||null),[C,u]),O=(0,s.useMemo)((()=>C.map((e=>({label:st(e),value:String(e.id)})))),[C]),R=(0,n.useBlockProps)(),x=(0,s.useCallback)((()=>{r({formId:void 0})}),[r]),P=(0,s.useCallback)((e=>{const t=ze(e);if(!function(e){const t=ze(e);return!!t&&"auto-draft"!==t.status}(t))return;const s=Number(t.id);g(t),m((e=>e+1)),s!==Number(u)&&r({formId:s})}),[u,r]),I=d?(0,e.createElement)(Je,{trigger:(0,e.createElement)(a.Button,{variant:"primary"},(0,i.__)("+ Create new form","generateblocks-pro")),formId:"new",onFormSave:P}):null,N=d?(0,e.createElement)(Je,{trigger:(0,e.createElement)(a.Button,{variant:"secondary"},(0,i.__)("New form","generateblocks-pro")),formId:"new",onFormSave:P}):null,F=d&&u?(0,e.createElement)(Je,{trigger:(0,e.createElement)(a.Button,{variant:"secondary"},(0,i.__)("Edit form","generateblocks-pro")),formId:u,onFormSave:P}):null;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n.InspectorControls,null,(0,e.createElement)(a.PanelBody,{title:(0,i.__)("Form","generateblocks-pro"),initialOpen:!0},(0,e.createElement)(a.ComboboxControl,{label:(0,i.__)("Form","generateblocks-pro"),value:u?String(u):"",options:O,onChange:e=>r({formId:e?parseInt(e,10):void 0}),onFilterValueChange:y,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),S?.status&&"publish"!==S.status&&(0,e.createElement)(a.Notice,{status:"warning",isDismissible:!1},(0,i.sprintf)(/* translators: %s: form status */ /* translators: %s: form status */ (0,i.__)("This form is %s — it will not accept submissions until published.","generateblocks-pro"),S.status)),u>0&&(0,e.createElement)("div",{style:{marginTop:"1em",display:"flex",gap:"8px",flexWrap:"wrap"}},F,N,(0,e.createElement)(a.Button,{variant:"tertiary",onClick:x},(0,i.__)("Clear","generateblocks-pro"))),!u&&N&&(0,e.createElement)("div",{style:{marginTop:"1em"}},N))),(0,e.createElement)(p,{name:c,clientId:l},(0,e.createElement)("div",{...R},u?(0,e.createElement)(at,{formId:u,refreshKey:h,onReplace:x}):(0,e.createElement)(nt,{onSelect:e=>r({formId:e}),forms:C,loading:k,canCreate:d,createAction:I,onSearchChange:y}))))},save:function(){return null},icon:(0,e.createElement)((function(){return(0,e.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",className:"gblocks-block-icon","aria-hidden":"true",focusable:"false"},(0,e.createElement)("rect",{x:"0",y:"0",width:"24",height:"24",style:{fill:"none"}}),(0,e.createElement)("path",{d:"M21.375,22L2.625,22C2.282,22 2,21.718 2,21.375L2,2.625C2,2.28 2.28,2 2.625,2L21.375,2C21.72,2 22,2.28 22,2.625L22,21.375C22,21.72 21.72,22 21.375,22ZM3.25,20.75L20.75,20.75L20.75,3.25L3.25,3.25L3.25,20.75Z",style:{fillRule:"nonzero"}}),(0,e.createElement)("path",{d:"M5,11.375L5,7.808C5,7.463 5.28,7.183 5.625,7.183L18.375,7.183C18.72,7.183 19,7.463 19,7.808L19,11.375C19,11.72 18.72,12 18.375,12L5.625,12C5.28,12 5,11.72 5,11.375ZM17.75,10.75L17.75,8.433L6.25,8.433L6.25,10.75L17.75,10.75Z"}),(0,e.createElement)("path",{d:"M12,18.497L12,17.103C12,16.825 12.28,16.6 12.625,16.6L18.375,16.6C18.72,16.6 19,16.825 19,17.103L19,18.497C19,18.775 18.72,19 18.375,19L12.625,19C12.28,19 12,18.775 12,18.497Z"}),(0,e.createElement)("path",{d:"M9.075,5.621L9.075,5.629C9.075,5.972 8.797,6.25 8.455,6.25L5.621,6.25C5.278,6.25 5,5.972 5,5.629L5,5.621C5,5.278 5.278,5 5.621,5L8.455,5C8.797,5 9.075,5.278 9.075,5.621Z",style:{fillRule:"nonzero"}}),(0,e.createElement)("circle",{cx:"5.6",cy:"13.817",r:"0.6"}),(0,e.createElement)("path",{d:"M19,13.785C19,14.116 18.731,14.385 18.4,14.385L9.1,14.385C8.769,14.385 8.5,14.116 8.5,13.785C8.5,13.454 8.769,13.185 9.1,13.185L18.4,13.185C18.731,13.185 19,13.454 19,13.785Z",style:{fillRule:"nonzero"}}))}),null)})})()})();