import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'

const root = process.cwd()

function readProjectFile(path) {
  return readFileSync(join(root, path), 'utf8')
}

function testSharedDropdownStyleOwnsDocumentCenterPattern() {
  const sharedStyles = readProjectFile('web/src/assets/styles/components/document-list-shared.css')
  const documentStyles = readProjectFile('web/src/assets/styles/views/documents-center-view.css')
  const logsStyles = readProjectFile('web/src/assets/styles/views/logs-view.css')

  assert.match(sharedStyles, /\.document-filter-menu\b/)
  assert.match(sharedStyles, /\.date-range-popover\b/)
  assert.match(sharedStyles, /\.status-filter-trigger\b/)
  assert.doesNotMatch(documentStyles, /\.document-filter-menu\b/)
  assert.doesNotMatch(logsStyles, /\.document-filter-menu\b[\s\S]*box-shadow/)
}

function testListViewsUseSharedDropdownFilter() {
  const receiptView = readProjectFile('web/src/views/ReceiptFolderView.vue')
  const budgetView = readProjectFile('web/src/views/BudgetCenterView.vue')
  const budgetScript = readProjectFile('web/src/views/scripts/BudgetCenterView.js')
  const employeeView = readProjectFile('web/src/views/EmployeeManagementView.vue')
  const employeeScript = readProjectFile('web/src/views/scripts/EmployeeManagementView.js')
  const logsView = readProjectFile('web/src/views/LogsView.vue')
  const auditPicker = readProjectFile('web/src/components/audit/AuditPickerFilter.vue')
  const dropdown = readProjectFile('web/src/components/shared/DocumentDropdownFilter.vue')

  assert.match(dropdown, /class="picker-filter document-filter"/)
  assert.match(dropdown, /class="picker-trigger filter-btn"/)
  assert.match(dropdown, /class="picker-popover document-filter-menu"/)
  assert.match(receiptView, /DocumentDropdownFilter/)
  assert.match(budgetView, /DocumentDropdownFilter/)
  assert.match(budgetScript, /DocumentDropdownFilter/)
  assert.doesNotMatch(budgetScript, /EnterpriseSelect/)
  assert.match(employeeView, /DocumentDropdownFilter/)
  assert.match(employeeScript, /DocumentDropdownFilter/)
  assert.match(logsView, /document-list-shared\.css/)
  assert.match(auditPicker, /document-filter-menu/)
  assert.doesNotMatch(auditPicker, /<header>/)
}

function run() {
  testSharedDropdownStyleOwnsDocumentCenterPattern()
  testListViewsUseSharedDropdownFilter()
  console.log('list dropdown filter style tests passed')
}

run()
