import { type RecipeDashboard } from '@/models/recipe/schema' import { create } from 'zustand' import taoAxios from '@/lib/taoAxios' export interface RecipeDashboardFilterQuery { countryID: string filename: string } interface materialDashboard { lebel: string value: string } interface RecipeDashboardHook { selectedRecipe: string setSelectedRecipe: (recipe: string) => void getRecipesDashboard: (filter?: RecipeDashboardFilterQuery) => Promise getMaterials: (filter?: RecipeDashboardFilterQuery) => Promise getRecipe: (productCode: string) => Promise } const useRecipeDashboard = create(() => ({ selectedRecipe: '', setSelectedRecipe: id => { useRecipeDashboard.setState({ selectedRecipe: id }) }, async getRecipesDashboard(filter) { return taoAxios .get('/v2/recipes/dashboard', { params: filter ? { country_id: filter.countryID, filename: filter.filename } : undefined }) .then(res => { return res.data }) .catch(() => []) }, async getMaterials(filter) { return taoAxios .get('/v2/materials/dashboard', { params: filter ? { country_id: filter.countryID, filename: filter.filename } : undefined }) .then(res => { return res.data }) }, async getRecipe(productCode) { return taoAxios .get(`/v2/recipes/${productCode}`) .then(res => { return res.data }) .catch(() => null) } })) export default useRecipeDashboard