import m from "mithril"

const SectionQuestion = {
    current: {},
    list: [],
    loading: false,
    fetch: function(sectionId) {
        SectionQuestion.loading = true
        m.request({
            url: "http://api.questionnaire.dev/v1/sections/" + sectionId + "/questions",
            method: "GET"
        })
        .then(function(res) {
            res.data = res.data[0]
            SectionQuestion.current = res
            SectionQuestion.loading = false
        })
    },
    nextOrPrev: function(url) {
        SectionQuestion.loading = true
        m.request({
            url,
            method: "GET"
        })
        .then(function(res) {
            res.data = res.data[0]
            SectionQuestion.current = res
            SectionQuestion.loading = false
        })
    }
}

export default SectionQuestion
