/**
 * 搜尋相關工具函式
 */

import type { Supplier } from "../types/vendor";

/**
 * 過濾廠商列表
 * @param suppliers 廠商列表
 * @param query 搜尋關鍵字
 * @returns 過濾後的廠商列表
 */
export function filterSuppliers(suppliers: Supplier[], query: string): Supplier[] {
  if (!query.trim()) {
    return suppliers;
  }

  const lowerQuery = query.toLowerCase();
  
  return suppliers.filter(
    (supplier) =>
      supplier.name.toLowerCase().includes(lowerQuery) ||
      supplier.contact?.toLowerCase().includes(lowerQuery) ||
      supplier.email?.toLowerCase().includes(lowerQuery)
  );
}
