import{d,r as l,ai as f,l as g}from"./jwt-decode.esm-CuqABuF0.js";import{r as u}from"./router-C-Pd0gHD.js";import{O as c}from"./organization-CFugdneJ.js";import"./tables-BHu5fUrG.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="fadd1ce0-6bdf-4f4b-9c30-cffc5b819773",e._sentryDebugIdIdentifier="sentry-dbid-fadd1ce0-6bdf-4f4b-9c30-cffc5b819773")}catch{}})();const S=d("organizationSwitcher",()=>{const e=l([]),t=l(!1),o=async()=>{t.value=!0;try{const a=await c.list();e.value=a.sort((r,n)=>r.name.localeCompare(n.name))}finally{t.value=!1}};return{organizations:e,loading:t,fetchOrganizations:o,renameOrganization:async(a,r)=>{const n=e.value.find(s=>s.id===a);if(!n)return!1;const i=n.name;n.name=r;try{return await c.rename(a,r),!0}catch(s){return n.name=i,f.error(g.translate("i18n_breadcrumb_rename_error")),console.error("Failed to rename organization",s),!1}},selectDefaultOrganization:async()=>{if(await o(),e.value.length===0)return{name:"onboarding"};const a=localStorage.getItem("lastSelectedOrganizationId"),r=a?e.value.find(i=>i.id===a):null;return r?{name:"organization",params:{organizationId:r.id}}:(a&&localStorage.removeItem("lastSelectedOrganizationId"),{name:"organization",params:{organizationId:e.value[0].id}})},selectOrganization:a=>{localStorage.setItem("lastSelectedOrganizationId",a),u.push({name:"organization",params:{organizationId:a}})}}});export{S as u};
//# sourceMappingURL=organizationSwitcher-C3nwECnr.js.map
