import{n as e,o as t}from"./chunk-DR8-3Aex.js";import{In as n,Ln as r,Rn as i,b as a,f as o,t as s,x as c}from"./src-Di342QoJ.js";import{t as l}from"./jsx-runtime-D-D469L8.js";import{Ct as u,cn as d}from"./state-sIHsFpDu.js";import{n as f,r as p}from"./analytics-DqMQntaB.js";import{A as m,et as h,j as g}from"./log-DSV4Ht5l.js";import{Ar as _,Fr as v,Ti as y,aS as b,oS as x,yr as S}from"./loadAgentsDir-C_wFhytF.js";import{r as C,t as w}from"./sanitization-Ds6zRQyx.js";function T({tagName:e,onConfirm:t,onCancel:n}){return(0,A.jsx)(o,{title:`Remove tag?`,subtitle:`Current tag: #${e}`,onCancel:n,color:`warning`,children:(0,A.jsxs)(c,{flexDirection:`column`,gap:1,children:[(0,A.jsx)(a,{children:`This will remove the tag from the current session.`}),(0,A.jsx)(b,{onChange:e=>e===`yes`?t():n(),options:[{label:`Yes, remove tag`,value:`yes`},{label:`No, keep tag`,value:`no`}]})]})})}function E({tagName:e,onDone:t}){let[r,i]=k.useState(!1),[a,o]=k.useState(null),s=C(e).trim();return k.useEffect(()=>{let e=u();if(!e){t(`No active session to tag`,{display:`system`});return}if(!s){t(`Tag name cannot be empty`,{display:`system`});return}o(e);let r=S(e);r===s?(p(`tengu_tag_command_remove_prompt`,{}),i(!0)):(p(`tengu_tag_command_add`,{is_replacing:!!r}),(async()=>{await y(e,s,_()),t(`Tagged session with ${n.cyan(`#${s}`)}`,{display:`system`})})())},[s,t]),r&&a?(0,A.jsx)(T,{tagName:s,onConfirm:async()=>{p(`tengu_tag_command_remove_confirmed`,{}),await y(a,``,_()),t(`Removed tag ${n.cyan(`#${s}`)}`,{display:`system`})},onCancel:()=>{p(`tengu_tag_command_remove_cancelled`,{}),t(`Kept tag ${n.cyan(`#${s}`)}`,{display:`system`})}}):null}function D({onDone:e}){return k.useEffect(()=>{e(`Usage: /tag <tag-name>

Toggle a searchable tag on the current session.
Run the same command again to remove the tag.
Tags are displayed after the branch name in /resume and can be searched with /.

Examples:
  /tag bugfix        # Add tag
  /tag bugfix        # Remove tag (toggle)
  /tag feature-auth
  /tag wip`,{display:`system`})},[e]),null}async function O(e,t,n){return n=n?.trim()||``,g.includes(n)||m.includes(n)||!n?(0,A.jsx)(D,{onDone:e}):(0,A.jsx)(E,{tagName:n,onDone:e})}var k,A;e((()=>{r(),k=t(i(),1),d(),x(),s(),h(),f(),w(),v(),A=l()}))();export{O as call};