"use strict";(self.webpackChunkcode_snippets=self.webpackChunkcode_snippets||[]).push([[6472],{2065:function(e,t,n){const o=(e,t,n)=>{e.querySelector(".nav-tab-active")?.classList.remove("nav-tab-active"),t.classList.add("nav-tab-active"),e.closest(".wrap")?.setAttribute("data-active-tab",n)},s=e=>{"editor"===e&&window.code_snippets_editor_preview?.codemirror.refresh()},i=e=>{const t=document.querySelector("input[name=_wp_http_referer]");if(!t)return void console.error("could not find http referer");const n=t.value.replace(/(?<base>[&?]section=)[^&]+/,`$1${e}`);t.value=n+(n===t.value?`&section=${e}`:"")};n(3099);const r=e=>document.getElementById(e),c=(e,t)=>{var n;return null!==(n=window.__code_snippets_i18n?.[e])&&void 0!==n?n:t},a=async(e,t)=>{var n;const o=new URLSearchParams;Object.keys(e).forEach((t=>o.append(t,e[t])));const s=await fetch(null!==(n=t.ajaxurl)&&void 0!==n?n:"/wp-admin/admin-ajax.php",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:o.toString(),credentials:"same-origin"});return await s.json()};(()=>{const e=document.getElementById("settings-sections-tabs");if(!e)return void console.error("Could not find snippets tabs");const t=e.querySelectorAll(".nav-tab");for(const n of t)n.addEventListener("click",(t=>{t.preventDefault();const r=n.getAttribute("data-section");r&&(o(e,n,r),s(r),i(r))}))})(),(()=>{const e=(()=>{const{codeEditor:e}=window.wp,t=document.getElementById("code_snippets_editor_preview");if(t)return window.code_snippets_editor_preview=e.initialize(t),window.code_snippets_editor_preview.codemirror;console.error("Could not initialise CodeMirror on textarea.",t)})(),t=window.code_snippets_editor_settings;for(const n of t){const t=document.querySelector(`[name="code_snippets_settings[editor][${n.name}]"]`);t?.addEventListener("change",(()=>{const o=n.codemirror,s=(()=>{switch(n.type){case"select":return(e=t).options[e.selectedIndex].value;case"checkbox":return t.checked;case"number":return parseInt(t.value,10);default:return null}var e})();if(null!==s)if("font_size"===n.name){const e=document.querySelector(".CodeMirror-code");e&&e instanceof HTMLElement&&(e.style.fontSize=`${s}px`)}else e?.setOption(o,s)}))}})(),(()=>{const e=null!==(t=window.code_snippets_version_switch)&&void 0!==t?t:{};var t;const n=(null!==(o=document.querySelector(".current-version")?.textContent)&&void 0!==o?o:"").trim();var o;const s=r("switch-version-btn"),i=r("target_version"),d=r("version-switch-result"),l=r("refresh-versions-btn");i&&((e,t,n)=>{e.addEventListener("change",(()=>{const o=e.value;if(t)if(o&&o!==n){t.disabled=!1;const e=r("version-switch-warning");e&&e.setAttribute("style","")}else{t.disabled=!0;const e=r("version-switch-warning");e&&e.setAttribute("style","display: none;")}}))})(i,s,n),s&&i&&d&&((e,t,n,o,s)=>{e.addEventListener("click",(()=>{(async i=>{const r=t.value;if(!r||r===s)return n.className="notice notice-warning",n.innerHTML=`<p>${c("selectDifferent","Please select a different version to switch to.")}</p>`,void(n.style.display="");e.disabled=!0;const d=null!==(i=e.textContent)&&void 0!==i?i:"";e.textContent=c("switching","Switching..."),n.className="notice notice-info",n.innerHTML=`<p>${c("processing","Processing version switch. Please wait...")}</p>`,n.style.display="";try{var l,u;const t=await a({action:"code_snippets_switch_version",target_version:r,nonce:null!==(l=o.nonce_switch)&&void 0!==l?l:""},o);var p;if(t.success)return n.className="notice notice-success",n.innerHTML=`<p>${null!==(p=t.data?.message)&&void 0!==p?p:""}</p>`,void setTimeout((()=>window.location.reload()),3e3);n.className="notice notice-error",n.innerHTML=`<p>${null!==(u=t.data?.message)&&void 0!==u?u:c("error","An error occurred.")}</p>`,e.disabled=!1,e.textContent=d}catch(t){n.className="notice notice-error",n.innerHTML=`<p>${c("errorSwitch","An error occurred while switching versions. Please try again.")}</p>`,e.disabled=!1,e.textContent=d}})()}))})(s,i,d,e,n),l&&((e,t)=>{e.addEventListener("click",(()=>{(async n=>{const o=null!==(n=e.textContent)&&void 0!==n?n:"";e.disabled=!0,e.textContent=c("refreshing","Refreshing...");try{var s;await a({action:"code_snippets_refresh_versions",nonce:null!==(s=t.nonce_refresh)&&void 0!==s?s:""},t),e.textContent=c("refreshed","Refreshed!"),setTimeout((()=>{e.disabled=!1,e.textContent=o,window.location.reload()}),1e3)}catch{e.disabled=!1,e.textContent=o}})()}))})(l,e)})()}},function(e){e(e.s=2065)}]);