import{r as e}from"./core-DcH9fClu.js";import{Cn as t,En as n,Zn as r,zn as i}from"./tauri-CdWwv9tA.js";import{n as a}from"./host-IZNQjG4L.js";var o=`orchestra.mock.source-control-settings`,s=`orchestra`,c=[{key:`role`,label:`Role preview`,role:`architect`,agent:``},{key:`agent`,label:`Agent preview`,role:``,agent:`reviewer`},{key:`no_worker`,label:`No-worker preview`,role:``,agent:``}];function l(){return new Date().toISOString()}function u(e){return e??i()??s}function d(){return r()?.client.settings??null}function f(e){let t=e?.trim()??``;return t.length>0?t:null}function p(){let e=window.localStorage.getItem(o);return e?JSON.parse(e):{}}function m(e){window.localStorage.setItem(o,JSON.stringify(e))}function h(e){switch(e){case`project_override`:return`Project override`;case`global_default`:return`Global default`;default:return`Unset`}}function g(e,t){let n=f(e);if(n)return{template:n,origin:`project_override`};let r=f(t);return r?{template:r,origin:`global_default`}:{template:null,origin:`unset`}}function _(e,t){let n=f(e);if(!n)return null;let r=n.split(`{role}`).join(t.role).split(`{agent}`).join(t.agent).trim();return r.length>0?r:null}function v(e){let t=f(e);if(!t)return[];let n=Array.from(t.matchAll(/\{([^{}]+)\}/g));return[...new Set(n.map(e=>e[1]?.trim()).filter(e=>!!(e&&e!==`role`&&e!==`agent`)).map(e=>`{${e}}`))]}function y(e){return{gitUserNameTemplate:v(e.gitUserNameTemplate),gitEmailTemplate:v(e.gitEmailTemplate)}}function b(e,t){let n=[];return e||n.push(`git user.name resolves to empty`),t?/^.+@.+\..+$/.test(t)||n.push(`git user.email does not look like an email`):n.push(`git user.email resolves to empty`),n}function x(e,t){return c.map(n=>{let r=g(t?.gitUserNameTemplate,e.gitUserNameTemplate),i=g(t?.gitEmailTemplate,e.gitEmailTemplate),a=_(r.template,n),o=_(i.template,n);return{key:n.key,label:n.label,gitUserName:{template:r.template,resolved:a,origin:r.origin},gitEmail:{template:i.template,resolved:o,origin:i.origin},warnings:b(a,o)}})}async function S(){let t=d();return t?t.getSourceControlSettings():a()?e(`get_source_control_settings`):p()}async function C(t,n){let r=d();if(r)return r.updateSourceControlSettings(t,n);if(!a()){let e={gitUserNameTemplate:f(t),gitEmailTemplate:f(n),updatedAt:l()};return m(e),e}return e(`update_source_control_settings`,{gitUserNameTemplate:t,gitEmailTemplate:n})}async function w(n){let r=d();if(r)return r.getProjectSourceControlSettings(n);let i=u(n);if(!a()){let e=t(i);return{projectSlug:i,gitUserNameTemplate:e.gitUserNameTemplate??null,gitEmailTemplate:e.gitEmailTemplate??null,updatedAt:e.updatedAt??null}}return e(`get_project_source_control_settings`,{projectSlug:i})}async function T(t,r,i){let o=d();if(o)return o.updateProjectSourceControlSettings(t,r,i);let s=u(i);return a()?e(`update_project_source_control_settings`,{projectSlug:s,gitUserNameTemplate:t,gitEmailTemplate:r}):(n(s,e=>({...e,gitUserNameTemplate:f(t),gitEmailTemplate:f(r),updatedAt:l()})),w(s))}export{y as a,S as i,w as n,T as o,h as r,C as s,x as t};