/**
 * 倉庫篩選 Hook
 * 處理倉庫的搜尋和類別篩選邏輯
 */

import { useMemo } from "react";
import { Warehouse } from "../types/warehouse";

export const useWarehouseFilter = (
  warehouses: Warehouse[],
  searchTerm: string,
  typeFilter: string
) => {
  return useMemo(() => {
    return warehouses.filter((warehouse) => {
      const matchesSearch = warehouse.name
        .toLowerCase()
        .includes(searchTerm.toLowerCase());
      const matchesType = typeFilter === "all" || warehouse.type === typeFilter;
      return matchesSearch && matchesType;
    });
  }, [warehouses, searchTerm, typeFilter]);
};
