import resource from '@/utils/resource'
import { getApp } from '@/app'

export default {
    namespaced: true,
    state() {
        return {
            tags: [],
            floors: [],
            metadata: {}
        }
    },
    getters: {
        tags: state => {
            return state.tags
        },
        floors: state => {
            return state.floors
        },
        metadata: state => {
            return state.metadata
        },
        
        musicURL: (state, getters, rootState, rootGetters) => {
            let metadata = getters.metadata
            if (metadata.music) {
                if (/^0\d$/.test(metadata.music)) {
                    return resource.getStaticURL(`static/music/${metadata.music}.mp3`)
                } else {
                    return getApp().resource.getUserResourceURL(metadata.musicFile.replace(/(.+)\.(.+)/, 'music-user.$2'))
                }
            }
            return null
        },
        loadingLogoFile: (state, getters, rootState, rootGetters) => {
            if (state.metadata.loadingLogo == 'user') {
                return getApp().resource.getUserResourceURL(state.metadata.loadingLogoFile)
            }
            return null
        },
    },
    mutations: {
       
        load(state, payload) {
            state.metadata = payload
            document.title = payload.title
        },
        loadFloorData(state, floor) {
            state.floors = floor.floors.map(item => {
                return { id: item.subgroup, name: item.name }
            })
        },
    },
}
