import { defineStore } from 'pinia' import { ref } from 'vue' import { invoke } from '@tauri-apps/api/core' export interface Favorite { id?: number project_id: number task_id?: number | null description?: string | null sort_order: number } export const useFavoritesStore = defineStore('favorites', () => { const favorites = ref([]) async function fetchFavorites() { try { favorites.value = await invoke('get_favorites') } catch (error) { console.error('Failed to fetch favorites:', error) } } async function createFavorite(fav: Favorite): Promise { try { const id = await invoke('create_favorite', { fav }) favorites.value.push({ ...fav, id: Number(id) }) return Number(id) } catch (error) { console.error('Failed to create favorite:', error) return null } } async function deleteFavorite(id: number): Promise { try { await invoke('delete_favorite', { id }) favorites.value = favorites.value.filter(f => f.id !== id) return true } catch (error) { console.error('Failed to delete favorite:', error) return false } } async function reorderFavorites(ids: number[]): Promise { try { await invoke('reorder_favorites', { ids }) return true } catch (error) { console.error('Failed to reorder favorites:', error) return false } } return { favorites, fetchFavorites, createFavorite, deleteFavorite, reorderFavorites } })