import{api as P,getRecord as w}from"./common-DEIQtiPI.js";import{d as L,aG as S,o as N,g as f,A as v,J as p,B as m,C as y,_ as g,P as R,j as _,az as k,K as E,L as U,O as H,r as n}from"./index-DOFLUERq.js";import{L as M}from"./LinkField-CPzmuCgV.js";import{_ as T}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./iconify-p99pbjf9.js";const j={key:0,class:"roles-editor"},I={class:"copy-from-field"},z={class:"editor-header"},D={class:"checkbox-grid"},G=L({__name:"HTML",props:{df:{},record:{},canEdit:{type:Boolean},ctx:{}},setup(i){const s=i,x=S(),c=n(!1),t=n([]),a=n([]),r=n(!1);function A(){const e=Array.isArray(s.record?.roles)?s.record.roles:[];a.value=e.map(o=>o.role).filter(Boolean)}async function b(){try{const e=await P.call("jingrow.core.pagetype.user.user.get_all_roles");t.value=e.message||[],A(),r.value=a.value.length===t.value.length}catch(e){console.error("Failed to load roles:",e)}}function C(){a.value=r.value?[...t.value]:[],d()}function F(e,o){o?a.value.includes(e)||a.value.push(e):a.value=a.value.filter(l=>l!==e),r.value=a.value.length===t.value.length,d()}function d(){if(!s.record)return;const e=Array.isArray(s.record.roles)?s.record.roles:[],o=e.map(l=>l.role);s.record.roles=e.filter(l=>a.value.includes(l.role)),a.value.forEach(l=>{o.includes(l)||s.record.roles.push({pagetype:"Has Role",role:l,__islocal:1})})}const h=n("");function V(e){e&&B(e)}async function B(e){if(e)try{const o=await w("Role Profile",e);if(o.success&&o.data?.roles){const l=Array.isArray(o.data.roles)?o.data.roles:[];a.value=l.map(u=>u.role).filter(Boolean),r.value=a.value.length===t.value.length,d()}}catch(o){console.error("Failed to copy roles:",o)}}return N(async()=>{try{c.value=await x.hasPermlevelAccess("Role Profile",1,"write")}catch{c.value=!1}b()}),(e,o)=>c.value?(f(),v("div",j,[p("div",I,[m(M,{modelValue:h.value,"onUpdate:modelValue":[o[0]||(o[0]=l=>h.value=l),V],options:"Role Profile",label:i.ctx.t("Copy From"),"enable-create":!1},null,8,["modelValue","label"])]),p("div",z,[m(_(k),{checked:r.value,"onUpdate:checked":[o[1]||(o[1]=l=>r.value=l),C],disabled:!c.value},{default:y(()=>[g(R(i.ctx.t("Select All")),1)]),_:1},8,["checked","disabled"])]),p("div",D,[(f(!0),v(E,null,U(t.value,l=>(f(),v("div",{key:l,class:"checkbox-item"},[m(_(k),{checked:a.value.includes(l),"onUpdate:checked":u=>F(l,u),disabled:!c.value},{default:y(()=>[g(R(i.ctx.t(l)),1)]),_:2},1032,["checked","onUpdate:checked","disabled"])]))),128))])])):H("",!0)}}),W=T(G,[["__scopeId","data-v-f644292c"]]);export{W as default};
