import{api as V}from"./common-DEIQtiPI.js";import{d as N,w as z,f as U,g as n,A as o,J as s,_ as q,P,O as w,i as D,C,B,j as m,am as j,aP as I,H as S,c,r as v}from"./index-DOFLUERq.js";import{_ as $}from"./_plugin-vue_export-helper-DlAUqK2U.js";const H={class:"field-label"},J={key:0,class:"required"},L={class:"password-input-wrap"},O={key:0,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Z={key:1,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},F={class:"password-validation-message"},G={key:1,class:"password-input-wrap"},K={key:0,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Q={key:1,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},R=N({__name:"Password",props:{df:{},record:{},canEdit:{type:Boolean},ctx:{}},setup(l){const e=l,A=c(()=>e.df.label_layout||"vertical"),i=v(!1),g=v("");let r=null;const h=c(()=>e.df.fieldname==="new_password");z(()=>e.record[e.df.fieldname],a=>{if(!h.value||!a||!e.canEdit){i.value=!1;return}r&&clearTimeout(r),r=setTimeout(()=>{E(a)},300)});function E(a){if(!a||a.length===0){i.value=!1;return}const t=[];a.length<8&&t.push(e.ctx.t("Password must be at least 8 characters")),/[a-z]/.test(a)||t.push(e.ctx.t("Password must contain lowercase letters")),/[A-Z]/.test(a)||t.push(e.ctx.t("Password must contain uppercase letters")),/[0-9]/.test(a)||t.push(e.ctx.t("Password must contain numbers")),/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(a)||t.push(e.ctx.t("Password must contain special characters")),t.length>0?(g.value=e.ctx.t("Password strength insufficient")+"："+t.join("、"),i.value=!0):i.value=!1}const M=()=>{r&&(clearTimeout(r),r=null)};U(()=>{M()});const p=c(()=>{const a=window.jingrow?.boot;return a?.user?.name==="Administrator"||a?.user?.roles?.includes?.("Administrator")}),d=v(!1),f=v(!1),y=c(()=>d.value?"text":"password");function T(a){return a?[...new Set(a)].join("")==="*":!1}const x=c(()=>e.ctx?.entity&&(e.ctx.entity.value??e.ctx.entity)||e.record?.pagetype||""),k=c(()=>e.ctx?.id&&(e.ctx.id.value??e.ctx.id)||e.record?.name||"");async function b(){if(d.value){d.value=!1;return}const a=e.record[e.df.fieldname];if(T(a)&&x.value&&k.value){f.value=!0;try{const t=await V.call("jingrow.client.get_password",{pagetype:x.value,name:k.value,fieldname:e.df.fieldname}),u=t?.message??t;u&&(e.record[e.df.fieldname]=u)}catch{}finally{f.value=!1}}d.value=!0}return(a,t)=>(n(),o("div",{class:S(["field-wrapper",`layout-${A.value}`])},[s("label",H,[q(P(l.ctx.t(l.df.label||l.df.fieldname))+" ",1),l.df.reqd?(n(),o("span",J,"*")):w("",!0)]),h.value?(n(),D(m(I),{key:0,show:i.value,trigger:"manual",placement:"bottom-start","show-arrow":!0,style:{"max-width":"400px"}},{trigger:C(()=>[s("div",L,[B(m(j),{value:l.record[l.df.fieldname],"onUpdate:value":t[0]||(t[0]=u=>l.record[l.df.fieldname]=u),type:y.value,placeholder:"",disabled:!l.canEdit,loading:f.value,status:i.value?"error":void 0},null,8,["value","type","disabled","loading","status"]),l.canEdit&&p.value?(n(),o("button",{key:0,type:"button",class:"password-toggle-btn",onClick:b},[d.value?(n(),o("svg",O,[...t[2]||(t[2]=[s("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"},null,-1),s("path",{d:"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"},null,-1),s("line",{x1:"1",y1:"1",x2:"23",y2:"23"},null,-1)])])):(n(),o("svg",Z,[...t[3]||(t[3]=[s("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"},null,-1),s("circle",{cx:"12",cy:"12",r:"3"},null,-1)])]))])):w("",!0)])]),default:C(()=>[s("div",F,P(g.value),1)]),_:1},8,["show"])):(n(),o("div",G,[B(m(j),{value:l.record[l.df.fieldname],"onUpdate:value":t[1]||(t[1]=u=>l.record[l.df.fieldname]=u),type:y.value,placeholder:"",disabled:!l.canEdit,loading:f.value},null,8,["value","type","disabled","loading"]),l.canEdit&&p.value?(n(),o("button",{key:0,type:"button",class:"password-toggle-btn",onClick:b},[d.value?(n(),o("svg",K,[...t[4]||(t[4]=[s("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"},null,-1),s("path",{d:"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"},null,-1),s("line",{x1:"1",y1:"1",x2:"23",y2:"23"},null,-1)])])):(n(),o("svg",Q,[...t[5]||(t[5]=[s("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"},null,-1),s("circle",{cx:"12",cy:"12",r:"3"},null,-1)])]))])):w("",!0)]))],2))}}),_=$(R,[["__scopeId","data-v-a8d6e910"]]);export{_ as default};
