import{w as z,O as y,L as w,J as t,G as o,P as I,V as M,W as R,R as b,F as U,S as m,r as l,b as W,T as j,I as n,U as D,Z as _,N as g,Q as k,$ as G,M as h,K as V,e as L}from"./index-iCRehgtD.js";import{u as H,Q as q}from"./useSetupWs-P74ozpSr.js";import{u as J}from"./use-quasar-WBpoPdWP.js";import{u as K}from"./setup-B2WhYkmc.js";const Z={class:"row justify-between"},O={class:"row q-gutter-sm"},te={__name:"PasswordPage",setup(X){const x=J(),C=j(),a=K(),{send:Q,messages:B,clearMessages:P}=H(),p=l(!1),u=l(!1),i=l(!1),v=l(!1),d=l(0),c=l([]),f=l(null),S=W(()=>!!a.adminUser.username&&a.adminUser.password.length>=8);function F(){const r="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789!@#$%^&*",e=new Uint8Array(24);crypto.getRandomValues(e),a.adminUser.password=Array.from(e,s=>r[s%r.length]).join("")}async function N(){if(a.adminUser.password)try{await navigator.clipboard.writeText(a.adminUser.password),x.notify({type:"positive",message:"Password copied to clipboard."})}catch(r){x.notify({type:"negative",message:r instanceof Error?`Failed to copy password: ${r.message}`:"Failed to copy password to the clipboard."})}}z(B,r=>{const e=r[r.length-1];!e||!u.value||(e.type==="output"?(c.value.push({text:e.line,cls:e.stream==="stderr"?"output-line-err":"output-line-out"}),L(()=>{f.value&&(f.value.scrollTop=f.value.scrollHeight)})):e.type==="done"?(u.value=!1,i.value=!0,d.value=e.exit_code,e.exit_code===0&&(v.value=!0)):e.type==="error"&&(u.value=!1,i.value=!0,d.value=1,c.value.push({text:e.message||"Failed to create admin user.",cls:"output-line-err"})))},{deep:!0});function T(){P(),c.value=[],i.value=!1,v.value=!1,u.value=!0,Q({action:"run_step",id:"create_admin_user",sudo:!0,username:a.adminUser.username,password:a.adminUser.password})}function A(){a.prevStep(),C.push("/database")}function E(){a.nextStep(),C.push("/summary")}return(r,e)=>(n(),y("div",null,[e[4]||(e[4]=w("div",{class:"step-header"},"Administrative User",-1)),e[5]||(e[5]=w("p",{class:"text-body2 q-mb-md"}," Create an administrative user for the Bareos WebUI and bconsole. ",-1)),t(I,{flat:"",bordered:"",class:"q-mb-lg"},{default:o(()=>[t(D,{class:"q-gutter-md"},{default:o(()=>[t(_,{modelValue:g(a).adminUser.username,"onUpdate:modelValue":e[0]||(e[0]=s=>g(a).adminUser.username=s),label:"Username",dense:"",outlined:"",rules:[s=>!!s||"Username is required"]},null,8,["modelValue","rules"]),t(_,{modelValue:g(a).adminUser.password,"onUpdate:modelValue":e[2]||(e[2]=s=>g(a).adminUser.password=s),label:"Password",type:p.value?"text":"password",dense:"",outlined:"",rules:[s=>s.length>=8||"Minimum 8 characters"]},{append:o(()=>[t(m,{flat:"",round:"",dense:"",icon:"content_copy",size:"sm",onClick:N,title:"Copy password"}),t(k,{name:p.value?"visibility_off":"visibility",class:"cursor-pointer",onClick:e[1]||(e[1]=s=>p.value=!p.value)},null,8,["name"]),t(m,{flat:"",round:"",dense:"",icon:"casino",size:"sm",onClick:F,title:"Generate password"})]),_:1},8,["modelValue","type","rules"])]),_:1})]),_:1}),c.value.length?(n(),y("div",{key:0,class:"output-console q-mb-md",ref_key:"consoleEl",ref:f},[(n(!0),y(M,null,R(c.value,(s,$)=>(n(),y("div",{key:$,class:G(s.cls)},h(s.text),3))),128))],512)):b("",!0),i.value&&d.value!==0?(n(),U(q,{key:1,class:"bg-negative text-white q-mb-md",rounded:""},{avatar:o(()=>[t(k,{name:"error"})]),default:o(()=>[V(" Failed to create admin user (exit code "+h(d.value)+"). ",1)]),_:1})):b("",!0),i.value&&d.value===0?(n(),U(q,{key:2,class:"bg-positive text-white q-mb-md",rounded:""},{avatar:o(()=>[t(k,{name:"check_circle"})]),default:o(()=>[e[3]||(e[3]=V(" Admin user created successfully. ",-1))]),_:1})):b("",!0),w("div",Z,[t(m,{flat:"",label:"Back",icon:"arrow_back",disable:u.value,onClick:A},null,8,["disable"]),w("div",O,[v.value?b("",!0):(n(),U(m,{key:0,label:"Create User",color:"secondary",icon:"person_add",loading:u.value,disable:!S.value,onClick:T},null,8,["loading","disable"])),t(m,{label:"Continue",color:"primary","icon-right":"arrow_forward",disable:!v.value,onClick:E},null,8,["disable"])])])]))}};export{te as default};
