import{r as e}from"./core-DcH9fClu.js";import{Zn as t,nr as n}from"./tauri-BdW-vCOV.js";var r=`orchestra.mock.channels`,i=`orchestra.mock.channel-activity`;function a(e){return e?.trim()||null}function o(){return new Date().toISOString()}function s(e){return`${e}-${Math.random().toString(36).slice(2,8)}-${Date.now().toString(36)}`}function c(){let e=window.localStorage.getItem(r);return e?JSON.parse(e):[]}function l(e){window.localStorage.setItem(r,JSON.stringify(e))}function u(){let e=window.localStorage.getItem(i);return e?JSON.parse(e):[]}function d(e){window.localStorage.setItem(i,JSON.stringify(e))}function f(){return t()?.client.channels??null}async function p(){let t=f();return t?t.listChannels():n()?e(`list_channels`):c()}async function m(t){let r=f();if(r)return r.getChannel(t);if(!n()){let e=c().find(e=>e.id===t);if(!e)throw Error(`Channel ${t} was not found.`);return e}return e(`get_channel`,{channelId:t})}async function h(t,r=50){let i=f();return i?i.listChannelActivity(t,r):n()?e(`list_channel_activity`,{channelId:t,limit:r}):u().filter(e=>e.channelId===t).slice(0,r)}async function g(t){let r=f();if(r)return r.createChannel(t);if(!n()){let e=o(),n={id:s(`channel`),kind:t.kind??`telegram`,name:t.name?.trim()||`Telegram`,enabled:!!t.enabled,status:t.telegram?.botToken&&t.telegram?.chatId?`ready`:`needs_setup`,targetAgentId:t.targetAgentId??`agent-supervisor`,defaultProjectId:t.defaultProjectId??`orchestra`,defaultProjectName:t.defaultProjectId??`orchestra`,secretConfigured:!!t.telegram?.botToken,telegram:{botUsername:null,apiBaseUrl:a(t.telegram?.apiBaseUrl),chatId:t.telegram?.chatId??null,chatTitle:t.telegram?.chatTitle??null,chatType:t.telegram?.chatType??null,commandsEnabled:t.telegram?.commandsEnabled??!0,notificationScope:t.telegram?.notificationScope??`all_projects`},lastError:null,lastActivityAt:null,createdAt:e,updatedAt:e};return l([n,...c()]),n}return e(`create_channel`,{input:t})}async function _(t,r){let i=f();if(i)return i.updateChannel(t,r);if(!n()){let e=c(),n=e.find(e=>e.id===t);if(!n)throw Error(`Channel ${t} was not found.`);let i={...n,name:r.name?.trim()||n.name,enabled:r.enabled??n.enabled,defaultProjectId:r.defaultProjectId??n.defaultProjectId,secretConfigured:n.secretConfigured||!!r.telegram?.botToken,telegram:{...n.telegram??{botUsername:null,apiBaseUrl:null,chatId:null,chatTitle:null,chatType:null,commandsEnabled:!0,notificationScope:`all_projects`},apiBaseUrl:a(r.telegram?.apiBaseUrl)??n.telegram?.apiBaseUrl??null,chatId:r.telegram?.chatId??n.telegram?.chatId??null,chatTitle:r.telegram?.chatTitle??n.telegram?.chatTitle??null,chatType:r.telegram?.chatType??n.telegram?.chatType??null,commandsEnabled:r.telegram?.commandsEnabled??n.telegram?.commandsEnabled??!0,notificationScope:r.telegram?.notificationScope??n.telegram?.notificationScope??`all_projects`},status:(n.secretConfigured||r.telegram?.botToken)&&(r.telegram?.chatId??n.telegram?.chatId)?`ready`:`needs_setup`,updatedAt:o()};return l(e.map(e=>e.id===t?i:e)),i}return e(`update_channel`,{channelId:t,input:r})}async function v(t){let r=f();if(r)return r.deleteChannel(t);if(!n()){l(c().filter(e=>e.id!==t)),d(u().filter(e=>e.channelId!==t));return}await e(`delete_channel`,{channelId:t})}async function y(t,r){let i=f();return i?i.validateTelegramBot(t,r):n()?e(`validate_telegram_bot`,{botToken:t,apiBaseUrl:a(r)}):{botId:`mock-bot`,username:`mock_orchestra_bot`,displayName:`Mock Orchestra Bot`}}async function b(t,r){let i=f();return i?i.listTelegramChatCandidates(t,r):n()?e(`list_telegram_chat_candidates`,{botToken:t,apiBaseUrl:a(r)}):[{chatId:`mock-chat`,title:`Mock Telegram Chat`,chatType:`private`,username:`mock-user`,lastMessageText:`/start`,lastMessageAt:o()}]}export{p as a,y as c,h as i,v as n,b as o,m as r,_ as s,g as t};