import { defineStore } from 'pinia' import { ref } from 'vue' import { useApi } from '../composables/useApi.js' import { useAsyncAction } from '../composables/useAsyncAction.js' import { toast } from '../utils/toast.js' // Backs the creator/membership review queue (#388 E4). Confirm-only: accepting // ADDS A SOURCE to the artist that already has the other channel — it never // merges two artists. Adding a source is trivially undone; a wrong merge // silently mixes two creators' work with nothing left to separate them by. export const useMembershipSuggestionsStore = defineStore('membershipSuggestions', () => { const api = useApi() const suggestions = ref([]) const { loading, error, run } = useAsyncAction({ errorAs: 'message' }) async function load () { await run(async () => { const body = await api.get('/api/sources/membership-suggestions') suggestions.value = body.items || [] }) } async function accept (id) { try { const res = await api.post(`/api/sources/membership-suggestions/${id}/accept`, {}) suggestions.value = suggestions.value.filter(s => s.id !== id) toast({ text: res.already_linked ? 'Already linked' : 'Channel added to this creator', type: 'success' }) } catch (e) { toast({ text: `Link failed: ${e.message}`, type: 'error' }) } } async function dismiss (id) { try { await api.post(`/api/sources/membership-suggestions/${id}/dismiss`, {}) suggestions.value = suggestions.value.filter(s => s.id !== id) } catch (e) { toast({ text: `Dismiss failed: ${e.message}`, type: 'error' }) } } async function rescan () { await api.post('/api/sources/membership-suggestions/rescan', {}) await load() } return { suggestions, loading, error, load, accept, dismiss, rescan } })