import{c as x,_ as B,r as E,a as y,o as I,b as z,d as v,e as l,f as _,g as s,t as b,w as R,h as g,v as Y,F as C,i as O,j as k,k as f,u as h,l as L,m as Z,n as j,G as ee,p as D,q as M,I as te,C as H,s as se,x as ne,R as ae,y as N,A as oe,z as le,B as T,D as ie,E as re}from"./index-oAtpp-VZ.js";import{A as q}from"./AccordionComp-D0eDAM6d.js";import{I as ce,a as ue,b as de}from"./IconTrash-DtIpQ-M_.js";/** * @license @tabler/icons-vue v3.31.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */var ve=x("outline","arrow-left","IconArrowLeft",[["path",{d:"M5 12l14 0",key:"svg-0"}],["path",{d:"M5 12l6 6",key:"svg-1"}],["path",{d:"M5 12l6 -6",key:"svg-2"}]]);/** * @license @tabler/icons-vue v3.31.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */var pe=x("outline","eye","IconEye",[["path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0",key:"svg-0"}],["path",{d:"M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6",key:"svg-1"}]]);/** * @license @tabler/icons-vue v3.31.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */var me=x("outline","search-off","IconSearchOff",[["path",{d:"M5.039 5.062a7 7 0 0 0 9.91 9.89m1.584 -2.434a7 7 0 0 0 -9.038 -9.057",key:"svg-0"}],["path",{d:"M3 3l18 18",key:"svg-1"}]]);/** * @license @tabler/icons-vue v3.31.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */var _e=x("outline","search","IconSearch",[["path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M21 21l-6 -6",key:"svg-1"}]]);const F=a=>{const n=document.createElement("style");n.setAttribute("custom_panel_style",!0),n.innerHTML=a,document.head.appendChild(n)},U=()=>{const a=document.querySelector("style[custom_panel_style]");a&&a.remove()},G=(a,n)=>{const t=new DOMParser().parseFromString(a,"text/html");let e=[];if(t.querySelectorAll("script").length>0){const S=fe(t);t.body=S.body,e=S.scripts}const r=t.body.innerHTML,c=document.createElement("div");return c.id="panel-html__body",c.style=`aspect-ratio: ${n}`,c.innerHTML=r,e.length>0&&he(e),c.outerHTML},fe=a=>{const n=a.querySelectorAll("script"),i=[];return n.forEach(t=>{t.getAttribute("no-compile")!=""&&i.push(t.innerHTML),t.remove()}),{body:a.body,scripts:i}},he=a=>{a.forEach(n=>{const i=document.createElement("script");i.setAttribute("custom_panel_script",!0),i.innerHTML=n,document.body.appendChild(i)})},ge=()=>{document.querySelectorAll("script[custom_panel_script]").forEach(n=>{n.remove()})},J=(a,n)=>{a.querySelectorAll("[mcrm__button]").forEach(i=>{i.addEventListener("click",()=>{n(i)})})},K=a=>{a.querySelectorAll("[mcrm__dialog-trigger]").forEach(n=>{const i=document.querySelector(n.getAttribute("dialog-trigger"));i&&n.addEventListener("click",()=>{i.show()})}),document.querySelectorAll("dialog, dialog .dialog__close").forEach(n=>{n.addEventListener("click",i=>{(i.target.classList.contains("dialog__close")||i.target.closest(".dialog__close")||i.target.tagName=="DIALOG")&&n.closest("dialog").close()})})},ye={class:"input-group form-select"},ke={key:0},be={class:"select__container"},we={key:0,class:"select__search-bar"},Se=["list","disabled"],$e=["id"],Le=["value"],Me=["name"],Ae={value:"",disabled:""},Pe=["value"],Ee={__name:"FormSelect",props:{label:String,name:String,options:[Array,Object],search:Boolean,value:String},emits:["change"],setup(a,{emit:n}){const i=n,t=a,e=E({options:[],search:"",searchActive:!1,changed:!1,value:""}),d=y(null),r=y(null);I(()=>{c(),typeof t.options=="object"&&(e.options=Object.values(t.options))}),z(()=>{c()});const c=()=>{(e.value==""&&t.value||!e.changed&&t.value!=e.value)&&(e.value=t.value),e.changed=!1},S=()=>{e.searchActive=!0,e.search="",d.value.classList="search__is-active",setTimeout(()=>{r.value.focus()},50)},P=()=>{e.search="",e.searchActive=!1,d.value.classList=""},V=A=>{u(A),P()},u=A=>{e.changed=!0,e.value=A.target.value,i("change",e.value)};return(A,w)=>(l(),v("div",ye,[a.label?(l(),v("label",ke,b(a.label),1)):_("",!0),s("div",be,[a.search?(l(),v("div",we,[R(s("input",{type:"search",ref_key:"selectSearch",ref:r,list:`${a.name}-search__options`,"onUpdate:modelValue":w[0]||(w[0]=p=>e.search=p),onChange:w[1]||(w[1]=p=>V(p)),disabled:!e.searchActive,autocomplete:"on"},null,40,Se),[[Y,e.search]]),s("datalist",{id:`${a.name}-search__options`},[(l(!0),v(C,null,O(e.options,p=>(l(),v("option",{key:p.value,value:p.value},b(p.label),9,Le))),128))],8,$e),e.searchActive?(l(),g(L,{key:1,variant:"ghost",size:"sm",onClick:P},{default:k(()=>[f(h(me))]),_:1})):(l(),g(L,{key:0,variant:"ghost",size:"sm",onClick:S},{default:k(()=>[f(h(_e))]),_:1}))])):_("",!0),R(s("select",{name:a.name,ref_key:"selectEl",ref:d,"onUpdate:modelValue":w[2]||(w[2]=p=>e.value=p),onChange:w[3]||(w[3]=p=>u(p))},[s("option",Ae,"- Select "+b(a.label.toLocaleLowerCase())+" -",1),(l(!0),v(C,null,O(e.options,p=>(l(),v("option",{key:p.value,value:p.value},b(p.label),9,Pe))),128))],40,Me),[[Z,e.value]])])]))}},Ce=B(Ee,[["__scopeId","data-v-a2e76de3"]]),Ie={key:0,id:"panel-edit",class:"mcrm-block block__dark !p-0 !gap-0"},xe={class:"panel-preview"},Be=["innerHTML"],Ve={class:"panel-settings"},Te={class:"grid grid-cols-[auto_1fr] gap-2 p-4"},Oe={class:"text-right"},je={class:"text-right"},Re={class:"text-right"},He={class:"grid gap-4 p-4"},qe={class:"grid grid-cols-[auto_1fr] gap-2"},ze={class:"text-right"},De={class:"grid"},Ne={class:"grid grid-cols-2 mt-4"},Fe={class:"flex items-end justify-end h-full p-4"},Ue={__name:"PanelEdit",props:{dirname:String},setup(a){const n=a,i=j(),t=y(!1),e=y({}),d=E({old:{},changed:!1}),r=y({}),c=y(!1),S=y(!1),P=y(null),V=y(null),u=E({id:"",macro:"",newMacro:"",changed:!1});I(async()=>{const m=await i.get(n.dirname);e.value=m,e.value.dir=n.dirname,e.value.html=G(e.value.html,e.value.aspectRatio),d.old=JSON.stringify(m.macros),c.value.toggleAccordion(!0);const o=await ee();r.value=Object.assign({},...Object.keys(o).map($=>({[$]:{value:o[$].macroname,label:o[$].name}}))),F(e.value.style),A()}),D(()=>{U()});function A(){const m=o=>{c.value.toggleAccordion(!1),w(o.id)};J(t.value,m),K(t.value)}function w(m){u.id=m,u.macro=e.value.macros[m]?e.value.macros[m]:""}function p(m,o){u.changed=e.value.macros[m]!=o,u.newMacro=o}function Q(m){e.value.macros[m]=u.newMacro,u.macro=u.newMacro,u.newMacro="",d.changed=H(d.old,e.value.macros)}function W(m){delete e.value.macros[m],S.value.toggleAccordion(!1),d.changed=H(d.old,e.value.macros)}function X(){const m={dir:e.value.dir,name:e.value.name,description:e.value.description,aspectRatio:e.value.aspectRatio,macros:e.value.macros};se.post(ne()+"/panel/save/json",m)}return(m,o)=>e.value?(l(),v("div",Ie,[s("div",xe,[s("div",{class:"panel-preview__content",ref_key:"panelPreview",ref:t,innerHTML:e.value.html},null,8,Be)]),s("div",Ve,[f(q,{title:"Panel info",ref_key:"infoAccordion",ref:c},{default:k(()=>[s("div",Te,[o[5]||(o[5]=s("span",null,"Name:",-1)),s("strong",Oe,b(e.value.name),1),o[6]||(o[6]=s("span",null,"Aspect ratio:",-1)),s("strong",je,b(e.value.aspectRatio),1),e.value.macros?(l(),v(C,{key:0},[o[4]||(o[4]=s("span",null,"Linked Macros:",-1)),s("strong",Re,b(Object.keys(e.value.macros).length),1)],64)):_("",!0)])]),_:1},512),s("div",null,[u.id?(l(),g(q,{key:0,title:"Button",ref_key:"buttonAccordion",ref:S,open:u.id!=""},{default:k(()=>[s("div",He,[s("div",qe,[o[7]||(o[7]=s("span",null,"Button ID:",-1)),s("strong",ze,b(u.id),1)]),s("div",De,[f(Ce,{name:"button_macro",label:"Button macro",search:!0,options:r.value,value:u.macro,onChange:o[0]||(o[0]=$=>p(u.id,$))},null,8,["options","value"]),s("div",Ne,[u.macro!=""?(l(),g(L,{key:0,class:"col-start-1 w-fit",size:"sm",variant:"danger",onClick:o[1]||(o[1]=$=>W(u.id)),ref_key:"unlinkButton",ref:P},{default:k(()=>[f(h(ce)),o[8]||(o[8]=M(" Unlink "))]),_:1},512)):_("",!0),u.changed?(l(),g(L,{key:1,class:"col-start-2 w-fit justify-self-end",size:"sm",variant:"primary",onClick:o[2]||(o[2]=$=>Q(u.id)),ref_key:"linkButton",ref:V},{default:k(()=>[f(h(te)),o[9]||(o[9]=M(" Link "))]),_:1},512)):_("",!0)])])])]),_:1},8,["open"])):_("",!0)]),s("footer",Fe,[d.changed?(l(),g(L,{key:0,variant:"success",onClick:o[3]||(o[3]=$=>X())},{default:k(()=>[f(h(ue)),o[10]||(o[10]=M(" Save changes "))]),_:1})):_("",!0)])])])):_("",!0)}},Ge={id:"panel-view"},Je=["innerHTML"],Ke={__name:"PanelView",props:{dirname:String},setup(a){const n=j(),i=a,t=y(null),e=y({});I(async()=>{const r=await n.get(i.dirname);e.value=r,e.value.html=G(e.value.html,e.value.aspectRatio),F(e.value.style),setTimeout(()=>{d(),typeof window.onPanelLoaded=="function"&&window.onPanelLoaded()},50)}),D(()=>{U(),ge()});const d=()=>{const r=c=>{ae(e.value.macros[c.id])};J(t.value,r),K(t.value)};return(r,c)=>(l(),v("div",Ge,[s("div",{class:"panel-preview__content",ref_key:"panelView",ref:t,innerHTML:e.value.html},null,8,Je)]))}},Qe=B(Ke,[["__scopeId","data-v-30e319d1"]]),We={id:"panels-overview"},Xe={class:"panel-list"},Ye=["onClick"],Ze={class:"thumb"},et=["src"],tt={key:0,class:"description"},st={class:"content"},nt={class:"block mb-1 text-slate-400"},at={key:0,class:"text-slate-200"},ot={__name:"PanelsOverview",setup(a){const n=j(),i=E({list:{}}),t=N();I(async()=>{const d=await n.getList();i.list=d});function e(d){T()||t.push(`/panel/view/${d}`)}return(d,r)=>(l(),v("div",We,[Object.keys(i.list).length==0?(l(),g(oe,{key:0,variant:"info"},{default:k(()=>r[0]||(r[0]=[M(" No panels found ")])),_:1})):_("",!0),s("div",Xe,[(l(!0),v(C,null,O(i.list,(c,S)=>(l(),v("div",{class:"panel-item mcrm-block block__dark",key:S},[s("div",{class:"panel-item__content",onClick:P=>e(c.dir)},[s("div",Ze,[c.thumb?(l(),v("img",{key:0,src:`data:image/jpeg;base64,${c.thumb}`,alt:""},null,8,et)):(l(),g(h(le),{key:1}))]),s("h4",null,b(c.name),1),h(T)()?(l(),v("div",tt,[s("div",st,[s("strong",nt,b(c.name),1),r[1]||(r[1]=s("hr",{class:"mb-2 border-slate-600"},null,-1)),c.description!="null"?(l(),v("p",at,b(c.description),1)):_("",!0)]),s("footer",null,[f(L,{variant:"subtle",size:"sm",href:`/panel/view/${c.dir}`},{default:k(()=>[f(h(pe)),r[2]||(r[2]=M(" Preview "))]),_:2},1032,["href"]),f(L,{variant:"primary",size:"sm",href:`/panel/edit/${c.dir}`},{default:k(()=>[f(h(de)),r[3]||(r[3]=M(" Edit "))]),_:2},1032,["href"])])])):_("",!0)],8,Ye),h(T)()?_("",!0):(l(),v(C,{key:0},[],64))]))),128))])]))}},lt=B(ot,[["__scopeId","data-v-a6f4d943"]]),it={id:"panels",class:"panel"},rt={class:"flex items-end justify-between !w-full panel__title"},ct={__name:"PanelsView",setup(a){const n=ie(),i=N(),t=E({function:"",dirname:""});I(()=>{e()}),z(()=>{e()});const e=()=>{n.name.includes("panel-")?t.function=n.name=="panel-edit"?"edit":"preview":t.function="overview",t.dirname=n.params.dirname};return(d,r)=>(l(),v("div",it,[s("h1",rt,[r[2]||(r[2]=s("div",null,"Panels",-1)),t.function!="overview"?(l(),g(L,{key:0,variant:"subtle",size:"sm",onClick:r[0]||(r[0]=c=>h(i).push("/panels"))},{default:k(()=>[f(h(ve)),r[1]||(r[1]=M(" Overview "))]),_:1})):_("",!0)]),s("div",{class:re(`panel__content !p-0 !pt-4 ${t.function=="overview"}`)},[t.function=="overview"?(l(),g(lt,{key:0})):_("",!0),t.function=="edit"?(l(),g(Ue,{key:1,dirname:t.dirname},null,8,["dirname"])):_("",!0),t.function=="preview"?(l(),g(Qe,{key:2,dirname:t.dirname},null,8,["dirname"])):_("",!0)],2)]))}},pt=B(ct,[["__scopeId","data-v-4fa76eeb"]]);export{pt as default}; //# sourceMappingURL=PanelsView-Bnnsxhnr.js.map