import http from './http'
import type { WorkbenchList, WorkbenchNav, SelectionDetail, DetailTab } from '@/types/workbench'
import { mockWorkbenchList, mockSelectionDetail } from '@/mock/data/workbench'

// 与 api/* 其它模块统一走 VITE_USE_MOCK 开关（替代旧的 VITE_PROJECTION_MOCK）。
const MOCK = import.meta.env.VITE_USE_MOCK === 'true'

export async function listWorkbench(nav: WorkbenchNav): Promise<WorkbenchList> {
  if (MOCK) return mockWorkbenchList(nav)
  const { data } = await http.get<WorkbenchList>(`/sl/projection/workbench/${nav}`)
  return data
}

export async function getSelectionDetail(
  objectKind: string,
  objectId: string,
  tab: DetailTab
): Promise<SelectionDetail> {
  if (MOCK) return mockSelectionDetail(objectKind, objectId, tab)
  const { data } = await http.get<SelectionDetail>('/sl/projection/selection/detail', {
    params: { objectKind, objectId, tab }
  })
  return data
}
