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