import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { fileURLToPath } from 'node:url'

function readProjectFile(path) {
  return readFileSync(fileURLToPath(new URL(`../${path.replace(/^web\//, '')}`, import.meta.url)), 'utf8')
}

test('claim previews stay bounded while document review uses the approval task workspace', () => {
  const useRequests = readProjectFile('web/src/composables/useRequests.js')
  const useAppShell = readProjectFile('web/src/composables/useAppShell.js')
  const documentsCenter = readProjectFile('web/src/views/DocumentsCenterView.vue')
  const archiveRowsComposable = readProjectFile('web/src/composables/useDocumentCenterArchiveRows.js')
  const approvalCenter = readProjectFile('web/src/views/scripts/ApprovalCenterView.js')
  const archiveCenter = readProjectFile('web/src/views/scripts/ArchiveCenterView.js')

  assert.match(useRequests, /REIMBURSEMENT_LIST_PREVIEW_PARAMS/)
  assert.match(useRequests, /fetchExpenseClaims\(REIMBURSEMENT_LIST_PREVIEW_PARAMS\)/)
  assert.doesNotMatch(useRequests, /fetchAllExpenseClaims\(\)/)

  assert.match(useAppShell, /REIMBURSEMENT_LIST_PREVIEW_PARAMS/)
  assert.match(useAppShell, /fetchApprovalExpenseClaims\(REIMBURSEMENT_LIST_PREVIEW_PARAMS\)/)
  assert.doesNotMatch(useAppShell, /fetchAllApprovalExpenseClaims\(\)/)

  assert.match(archiveRowsComposable, /fetchArchivedExpenseClaims\(REIMBURSEMENT_LIST_PREVIEW_PARAMS\)/)
  assert.match(documentsCenter, /<ApprovalTaskWorkspace/)
  assert.doesNotMatch(documentsCenter, /fetchApprovalExpenseClaims/)
  assert.doesNotMatch(documentsCenter, /fetchAllApprovalExpenseClaims\(\)/)
  assert.doesNotMatch(documentsCenter, /fetchAllArchivedExpenseClaims\(\)/)

  assert.match(approvalCenter, /fetchApprovalWorkbenchItems\(\{ limit: 100 \}\)/)
  assert.doesNotMatch(approvalCenter, /fetchApprovalExpenseClaims/)

  assert.match(archiveCenter, /fetchArchivedExpenseClaims\(REIMBURSEMENT_LIST_PREVIEW_PARAMS\)/)
  assert.doesNotMatch(archiveCenter, /fetchArchivedExpenseClaims\(\)/)
})
