import{provide as J,ref as c,watch as K,resolveComponent as u,createElementBlock as C,openBlock as i,Fragment as B,createElementVNode as p,createBlock as j,createVNode as s,createCommentVNode as x,unref as o,Teleport as Q,withDirectives as X,isRef as k,vShow as Y,withCtx as b,createTextVNode as D,renderList as Z,normalizeClass as ee,toDisplayString as ne,withModifiers as te}from"/vue.js";import{b as oe,A as h,n as le,p as S,r as U}from"./nc-main.DEgIQeOo.js";import"./service-worker.DGZzV4eE.js";const se={key:0},ae={class:"list-group"},re=["onClick"],ce={class:"content"},ue={class:"ms-auto"},me=Object.assign({name:"nc-help-manager"},{__name:"nc-help-manager",setup(ie){const d=oe("nc-help",{rec:{help_array:""},arr:{help_array:[]}});J("state",d);const f=d.arr,r=c(!1),v=c(null),_=c(null),y=c(!1),E=c(!0),w=c([]),m=c({});function H(){if(!r.value){r.value=!0,O();return}r.value=!1}function N(n){const{steps:e,...a}=n;w.value=e,m.value=a,v.value=n,_.value=0,r.value=!1}function L(n){const e=le.recordArrayRecord(f.help_array,"value",n);N(e)}function $(n){const e=f.help_array[n];N(e)}function z(){v.value=void 0,_.value=void 0}function O(){U.callServer(d,"query",{name:"form/nc/nc-help/init.json"},n=>{if(n.arr?.help_topic){let e;const a=n.arr.help_topic.map(l=>(e=n.arr[l]||{show:(n.hdr?.nc_help?.missing_help_topic||"missing help topic: ")+l,steps:[]},e.value=e.name,e)).filter(l=>l.url==null||l.url===""||S.startsWith(h.value,l.url));d.arr.help_array=a}})}function M(){const n={show:h.value.charAt(1).toUpperCase()+h.value.slice(2),url:h.value,parameter:{},steps:[]};f.help_array.push(n),$(f.help_array.indexOf(n))}function P(n){confirm(`delete help ${n.show}?`)&&console.log("delete",n)}function R(){m.value.value=null,V()}function V(){const n=Object.assign({},m.value);let e=n.name?.toLowerCase()||n.show.toLowerCase();if(e=S.parseAfter(e,"form/nc/nc-help/help-content/"),e=S.replace(e," ","-"),!e){alert("you must give the help a name");return}S.endsWith(e,".json")||(e=e+".json"),delete n.value,n.name=`form/nc/nc-help/help-content/${e}`,n.steps=w.value;const a={save:[{table:"preference",data:[n],save_preference:"form/nc/nc-help/save-help.json"}]};U.checkUndefinedAndNull(d,a.save,"save",!1),U.callServer(d,"save",a,l=>{console.log("🚀 ~ file: nc-help-manager.vue ~ save ~ ret:",l)})}function T(){console.debug("nc-help-manager ~ urlChange ~ currentPath.value:",h.value),y.value&&O()}return K(h,T),(n,e)=>{const a=u("nc-menu-item"),l=u("nc-dropdown"),W=u("nc-help"),g=u("nc-icon"),A=u("nc-col"),F=u("nc-row"),G=u("nc-button");return i(),C(B,null,[p("span",null,[s(a,{icon:"question-circle",onClick:H}),o(r)?(i(),j(l,{key:0,id:"nc-help-menu",model:"rec.help_array",selected:o(r),onChange:L},null,8,["selected"])):x("",!0)]),(i(),j(Q,{to:"body"},[o(r)?(i(),C("div",se,[X(s(W,{current:o(_),"onUpdate:current":e[0]||(e[0]=t=>k(_)?_.value=t:null),edit:o(y),"onUpdate:edit":e[1]||(e[1]=t=>k(y)?y.value=t:null),steps:o(w),"onUpdate:steps":e[2]||(e[2]=t=>k(w)?w.value=t:null),option:o(m),"onUpdate:option":e[3]||(e[3]=t=>k(m)?m.value=t:null),selected:o(v),"show-admin":o(E),onSave:V,onSaveClone:R,onDeselect:z},null,8,["current","edit","steps","option","selected","show-admin"]),[[Y,o(v)]]),s(F,{style:{gap:"0.1em"}},{default:b(()=>[s(A,null,{default:b(()=>[p("div",{class:"btn btn-sm btn-secondary",onClick:M},[s(g,{icon:"plus",class:"me-0"}),e[5]||(e[5]=D(" Add ",-1))])]),_:1}),s(A,{width:"auto"}),s(A,null,{default:b(()=>[p("div",{class:"btn btn-sm btn-secondary",onClick:e[4]||(e[4]=t=>y.value=!1)},[s(g,{icon:"times",class:"me-0"})])]),_:1})]),_:1}),e[6]||(e[6]=p("div",{class:"ui divider"},null,-1)),p("div",ae,[(i(!0),C(B,null,Z(o(f).help_array,(t,q)=>(i(),C("div",{key:""+t.text+t.type+t.query+q,class:ee(["list-group-item d-flex",{active:t===o(v),selected:t===o(v)}]),role:"option",onClick:I=>$(q)},[p("div",ce,[t.icon?(i(),j(g,{key:0,icon:t.icon},null,8,["icon"])):x("",!0),D(" "+ne(t.show),1)]),p("div",ue,[s(G,{size:"tiny",onClick:te(I=>P(t),["stop"])},{default:b(()=>[s(g,{icon:"trash"})]),_:1},8,["onClick"])])],10,re))),128))])])):x("",!0)]))],64)}}});export{me as default};
