import{d,r as c,ad as g,l as f}from"./jwt-decode.esm-C7p7KYmD.js";import{A as u,r as m}from"./router-KqhyGitc.js";import{O as l}from"./organization-C1Ar5sAZ.js";import"./tables-BD2MpLEl.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},o=new Error().stack;o&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[o]="731b0779-54a7-464f-8070-6f4b2ce2c6a2",a._sentryDebugIdIdentifier="sentry-dbid-731b0779-54a7-464f-8070-6f4b2ce2c6a2")}catch{}})();const v=d("organizationSwitcher",()=>{const a=c([]),o=c(!1),i=async()=>{o.value=!0;try{const e=await l.list();a.value=e.sort((n,t)=>n.name.localeCompare(t.name))}finally{o.value=!1}};return{organizations:a,loading:o,fetchOrganizations:i,renameOrganization:async(e,n)=>{const t=a.value.find(r=>r.id===e);if(!t)return!1;const s=t.name;t.name=n;try{return await l.rename(e,n),!0}catch(r){return t.name=s,g.error(f.translate("i18n_breadcrumb_rename_error")),console.error("Failed to rename organization",r),!1}},selectDefaultOrganization:async()=>{await i();const{status:e}=await u.getInfo();if(e!=="active")return{name:"onboarding"};if(a.value.length===0){const r=await l.create("My Organization");return await i(),{name:"organization",params:{organizationId:r.id}}}const n=localStorage.getItem("lastSelectedOrganizationId"),t=n?a.value.find(r=>r.id===n):null;if(t)return{name:"organization",params:{organizationId:t.id}};n&&localStorage.removeItem("lastSelectedOrganizationId");const[s]=a.value;return{name:"organization",params:{organizationId:s.id}}},selectOrganization:e=>{localStorage.setItem("lastSelectedOrganizationId",e),m.push({name:"organization",params:{organizationId:e}})}}});export{v as u};
//# sourceMappingURL=organizationSwitcher-Cqv_Kzfl.js.map
