import type { FilterDefinition } from '@/components/shared/filter-bar';
import { EXPENSE_CATEGORIES, formatEnum } from '@/lib/constants';

/**
 * Build the filter-bar definitions. Categories accept the resolved
 * per-port vocabulary list when callers can fetch it; otherwise the
 * shipped defaults are used. Kept as a function so the page can read
 * `/api/v1/vocabularies` on mount and reactively rebuild.
 */
export function buildExpenseFilterDefinitions(
  categories: readonly string[] = EXPENSE_CATEGORIES,
): FilterDefinition[] {
  return [
    {
      key: 'search',
      label: 'Search',
      type: 'text',
      placeholder: 'Search by establishment or description...',
    },
    {
      key: 'category',
      label: 'Category',
      type: 'multi-select',
      options: categories.map((c) => ({ label: formatEnum(c), value: c })),
    },
    {
      key: 'paymentStatus',
      label: 'Payment Status',
      type: 'select',
      options: [
        { label: 'Unpaid', value: 'unpaid' },
        { label: 'Paid', value: 'paid' },
        { label: 'Partial', value: 'partial' },
      ],
    },
    {
      key: 'dateFrom',
      label: 'Date From',
      type: 'date',
    },
    {
      key: 'dateTo',
      label: 'Date To',
      type: 'date',
    },
    {
      key: 'currency',
      label: 'Currency',
      type: 'currency',
    },
    {
      key: 'tripLabel',
      label: 'Trip / event',
      type: 'text',
      placeholder: 'e.g. Palm Beach 2026',
    },
    {
      key: 'includeArchived',
      label: 'Include Archived',
      type: 'boolean',
    },
  ];
}

/** Default list used by SSR / non-vocab-aware consumers. */
export const expenseFilterDefinitions: FilterDefinition[] = buildExpenseFilterDefinitions();
