'use client';

import { useMemo } from 'react';
import { Category, SortOption } from '@/domain/entities';
import { CategoryFilter } from '@/domain/services/CatalogDomainService';
import { container } from '@/application/container';
import { useLocaleStore } from '@/infrastructure/persistence/zustand/localeStore';
import { LocalizedProduct } from '@/application/dtos/LocalizedProduct';

export function useCatalogFilter(input: {
  category: CategoryFilter;
  searchQuery: string;
  sortBy: SortOption;
}): LocalizedProduct[] {
  const locale = useLocaleStore((s) => s.locale);

  return useMemo(() => {
    return container.createFilterProducts(locale).execute(input);
  }, [locale, input.category, input.searchQuery, input.sortBy]);
}

export function useLocalizedProduct(
  productId: string
): LocalizedProduct | undefined {
  const locale = useLocaleStore((s) => s.locale);

  return useMemo(() => {
    const product = container.productRepository.findById(productId);
    if (!product) return undefined;
    return container.createLocalizeProduct(locale).execute(product);
  }, [locale, productId]);
}

export { FilterProductsUseCase as CatalogHelpers } from '@/application/use-cases/catalog/FilterProducts';

export type { CategoryFilter };
export type { Category };