import { defineStore } from 'pinia'
import { ref } from 'vue'
import { http } from '@/plugins/http'

export const useChannelStore = defineStore('channel', () => {
    const channelOptions = ref([])
    const loading = ref(false)

    async function fetchChannelOptions() {
        if (channelOptions.value.length > 0) return
        
        loading.value = true
        try {
            const response = await http.post('/ocrChannel/names')
            channelOptions.value = response.data || []
        } catch (error) {
            console.error('获取渠道列表失败:', error)
        } finally {
            loading.value = false
        }
    }

    return {
        channelOptions,
        loading,
        fetchChannelOptions
    }
}) 