import { createStore } from "vuex";

const store = createStore({
    state () {
        return {
            author: {
                name:  "",
                image: "",
                wiki:  ""
            },
            authors: [],
            autoBookmark: false,
            autoLoadBooks: false,
            book: {
                author: "",
                photo:  "",
                title:  "",
                cover:  "",
                wiki:   ""
            },
            books:        [],
            chapters:     [],
            curChapter:   0,
            darkTheme:    false,
            playbackRate: 1,
        }
    },

    getters: {
        author:        state => { return state.author; },
        authors:       state => { return state.authors; },
        autoBookmark:  state => { return state.autoBookmark; },
        autoLoadBooks: state => { return state.autoLoadBooks; },
        book:          state => { return state.book; },
        books:         state => { return state.books; },
        chapters:      state => { return state.chapters },
        curChapter:    state => { return state.curChapter },
        darkTheme:     state => { return state.darkTheme },
        playbackRate:  state => { return state.playbackRate },
    },

    mutations: {
        setAuthor (state, payload)        { state.author        = payload; },
        setAuthors (state, payload)       { state.authors       = payload; },
        setAutoBookmark (state, payload)  { state.autoBookmark  = payload; },
        setAutoLoadBooks (state, payload) { state.autoLoadBooks = payload; },
        setBook (state, payload)          { state.book          = payload; },
        setBooks (state, payload)         { state.books         = payload; },
        setChapters (state, payload)      { state.chapters      = payload; },
        setCurChapter (state, payload)    { state.curChapter    = payload; },
        setDarkTheme (state, payload)     { state.darkTheme     = payload; },
        setPlaybackRate (state, payload)  { state.playbackRate  = payload; },
    }
});

export default store;
