import http from '../../../api/fastposter'

const state = {
    items: [],
}
const getters = {}

const actions = {
    search({commit}, playload) {
        return new Promise((resolve) => {
            http.loadMaterial(playload, r => {
                let items = r.data.items
                items.forEach(a => {
                    // 处理路径
                    a.preview = a.path.startsWith('http') ? a.path : http.baseURL + a.path
                });
                commit('setItems', items)
                resolve(r)
            })
        });
    },
    remove({commit}, playload) {
        return new Promise((resolve) => {
            http.removeMaterial(playload, r => {
                resolve(r)
            })
        });
    }
}
const mutations = {
    setItems(state, items) {
        state.items = items;
    }
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
}
