import{c as u}from"./index-COpU9qvO.chunk.mjs";import{g as y,f as c,c as f}from"./index-CziSTDUD.chunk.mjs";import{t as o}from"./translation-DoG5ZELJ-CPJIGC2H.chunk.mjs";import{c as h}from"./index-Cogf4PrN.chunk.mjs";import{g as b}from"./dav-CyDaXJUZ.chunk.mjs";const r=y().setApp("systemtags").detectUser().build(),O={userVisible:!0,userAssignable:!0,canAssign:!0},x=Object.freeze({"display-name":"displayName","user-visible":"userVisible","user-assignable":"userAssignable","can-assign":"canAssign"});function p(t){return t.map(({props:s})=>Object.fromEntries(Object.entries(s).map(([e,a])=>(e=x[e]??e,a=e==="displayName"?String(a):a,[e,a]))))}function w(t){const s=t.indexOf("?");s>0&&(t=t.substring(0,s));const e=t.split("/");let a;do a=e[e.length-1],e.pop();while(!a&&e.length>0);return Number(a)}function v(t){if("name"in t&&!("displayName"in t))return{...t};const s={...t};return s.name=s.displayName,delete s.displayName,s}function V(t){const s=t.attributes?.["system-tags"]?.["system-tag"];return s===void 0?[]:[s].flat().map(e=>typeof e=="string"?e:e.text)}function N(t,s){t.attributes["system-tags"]={"system-tag":s},c("files:node:updated",t)}const n=b(),l=` `;async function P(){const t="/systemtags";try{const{data:s}=await n.getDirectoryContents(t,{data:l,details:!0,glob:"/systemtags/*"});return p(s)}catch(s){throw r.error(o("systemtags","Failed to load tags"),{error:s}),new Error(o("systemtags","Failed to load tags"),{cause:s})}}async function D(t){const s="/systemtags/"+t;try{const{data:e}=await n.stat(s,{data:l,details:!0});return p([e])[0]}catch(e){throw r.error(o("systemtags","Failed to load tag"),{error:e}),new Error(o("systemtags","Failed to load tag"),{cause:e})}}async function C(t){const s="/systemtags",e=v(t);try{const{headers:a}=await n.customRequest(s,{method:"POST",data:e}),i=a.get("content-location");if(i)return c("systemtags:tag:created",t),w(i);throw r.error(o("systemtags",'Missing "Content-Location" header')),new Error(o("systemtags",'Missing "Content-Location" header'))}catch(a){throw a?.response?.status===409?(r.error(o("systemtags","A tag with the same name already exists"),{error:a}),new Error(o("systemtags","A tag with the same name already exists"),{cause:a})):(r.error(o("systemtags","Failed to create tag"),{error:a}),new Error(o("systemtags","Failed to create tag"),{cause:a}))}}async function R(t){const s="/systemtags/"+t.id,e=` ${t.displayName} ${t.userVisible} ${t.userAssignable} ${t?.color||null} `;try{await n.customRequest(s,{method:"PROPPATCH",data:e}),c("systemtags:tag:updated",t)}catch(a){throw r.error(o("systemtags","Failed to update tag"),{error:a}),new Error(o("systemtags","Failed to update tag"),{cause:a})}}async function T(t){const s="/systemtags/"+t.id;try{await n.deleteFile(s),c("systemtags:tag:deleted",t)}catch(e){throw r.error(o("systemtags","Failed to delete tag"),{error:e}),new Error(o("systemtags","Failed to delete tag"),{cause:e})}}async function _(t,s){const e=`/systemtags/${t.id}/${s}`,a=await n.stat(e,{data:` `,details:!0}),i=a?.data?.props?.getetag||'""',d=Object.values(a?.data?.props?.["object-ids"]||[]).flat();return{etag:i,objects:d}}async function q(t,s,e,a=""){const i=`/systemtags/${t.id}/${s}`;let d=` ${e.map(({id:m,type:g})=>`${m}${g}`).join("")} `;e.length===0&&(d=` `),await n.customRequest(i,{method:"PROPPATCH",data:d,headers:{"if-match":a}})}async function k(t){const s=t?"1":"0",e=f("/apps/provisioning_api/api/v1/config/apps/{appId}/{key}",{appId:"systemtags",key:"restrict_creation_to_admin"});await h();const{data:a}=await u.post(e,{value:s});return a}export{T as a,k as b,C as c,O as d,V as e,P as f,_ as g,N as h,D as i,r as l,q as s,R as u}; //# sourceMappingURL=api-CnLEK7Ep.chunk.mjs.map