import type { Style } from '@simon_he/vue-tui'

export type LineAction =
  | { type: 'none' }
  | { type: 'selectToolCall'; callId: string }
  | { type: 'openApproval' }
  | {
      type: 'toolApproval'
      requestId: string
      action: 'approve' | 'alwaysApprove' | 'deny'
    }
  | {
      type: 'askUserOption'
      toolCallId: string
      questionIndex: number
      optionIndex: number
    }
  | { type: 'askUserNav'; toolCallId: string; direction: 'prev' | 'next' }
  | { type: 'askUserSubmit'; toolCallId: string }
  | { type: 'askUserCancel'; toolCallId: string }
  | {
      type: 'toggleItem'
      messageId: string
      part: 'todo' | 'plan'
      itemId: string
    }
  | {
      type: 'toggleCollapse'
      messageId: string
      part: 'todo' | 'plan' | 'thinking'
      partId: string
    }
  | { type: 'toggleBashOutput'; toolCallId: string }
  | { type: 'loadMoreBashOutput'; toolCallId: string }
  | { type: 'toggleEditDiffLayout'; toolCallId: string }
  | { type: 'selectToolCallGroup'; groupKey: string }
  | { type: 'showMessageActions'; messageId: string }
  | { type: 'revertFiles'; messageId: string }
  | { type: 'copyText'; text: string }

export interface FileOpenAction {
  type: 'openFile'
  absPath: string
}
export interface UrlOpenAction {
  type: 'openUrl'
  url: string
}
export type SegmentAction = FileOpenAction | UrlOpenAction

export interface LineSegment {
  x: number
  w: number
  text: string
  style?: Style
  action?: SegmentAction
  /**
   * Optional render z-order for overlapping segments.
   * Higher values paint later (on top).
   */
  zIndex?: number
}

export type BlockLine = Readonly<{
  text: string
  style?: Style
  segments: LineSegment[]
  action?: LineAction
}>

export interface Line {
  text: string
  style?: Style
  segments: LineSegment[]
  action?: LineAction
  hasBackground?: boolean // true for user messages (gray bg), false for assistant (black bg)
  messageId?: string // Track which message this line belongs to
}
