import {XmlImportDialog} from "./module/dialog/xmlImportDialog.mjs";
import {initGlobalSettings, initUserSettings} from "./module/settings/global-settings.mjs";
import {setUpActorSheets, setUpItemSheets} from "./module/setup/sheets.mjs";
import {loadPartials} from "./module/setup/partials.mjs";
import {
    initSocketLib,
    initCombat,
    initDataModels,
    initDocumentClasses,
    initGlobalAccess
} from "./module/setup/config.mjs";
import {initHandlebarHelpers} from "./module/handlebar-helpers/index.mjs";

Hooks.once("init", () => {

    console.log("DSA 4.1 is ready for development!")

    game.DSA41 = {
        ...game.DSA41,
        ...initGlobalAccess()
    }
    initDocumentClasses(CONFIG)

    initUserSettings(game.settings)
    initGlobalSettings(game.settings)

    initDataModels(CONFIG)
    initCombat(CONFIG)

    setUpActorSheets(foundry.documents.collections.Actors)
    setUpItemSheets(foundry.documents.collections.Items)

    loadPartials(foundry.applications.handlebars).then(() => {
    })

    initHandlebarHelpers(Handlebars)
})

game.DSA41 = {}
initSocketLib(game.DSA41)

Hooks.on("getActorContextOptions", (application, menuItems) => {
    menuItems.push({
        name: "Import from XML",
        icon: '<i class="fas fa-file"></i>',
        callback: (li) => {
            const actorId = li.getAttribute("data-entry-id")
            const actor = game.actors.get(actorId)
            new XmlImportDialog(actor).render(true)
        }
    })
})