﻿module wizzi.mtree
    kind jsfile

	var loader = require('./lib/loader') 
	+
	var md = module.exports = {}
	#
		#
		# params
		#   function createStore
		#     api-ref wizzi-repo.createStore
		#   { options
		#     boolean useCache
		#     boolean frontMatter
        #     boolean raw
		#     boolean mTreeBuildupScript
		#
	set md.createLoadMTree
		function createLoadMTree
			func createStore
			{ options
				optional
			set options = options || {}
			var useCache = options.useCache || false
			var frontMatter = options.frontMatter || false
            var raw = options.raw || false
			var mTreeBuildupScript = options.mTreeBuildupScript || false
			var ittfDocumentStore
			return
				function loadMTree
					string ittfDocumentUri
					{ loadContext
						{ __productionManager
							{ productionContext
								{ aclstat
						{ mTreeBuildupContext
							optional
					callback

					# loog 'wizzi-mtree.loadMTree.loadContext', loadContext

					if !useCache || !ittfDocumentStore
						_ createStore
							f_cb( store )
								set ittfDocumentStore = store
								set loadContext.__ittfDocumentStore = store
								if frontMatter
									_ loader.loadMTreeFrontMatter
										@ ittfDocumentUri
										@ loadContext
										@ callback
								elif raw
									_ loader.loadMTreeRaw
										@ ittfDocumentUri
										@ loadContext
										@ callback
								elif mTreeBuildupScript
									_ loader.loadMTreeBuildupScript
										@ ittfDocumentUri
										@ loadContext
										@ callback
								else
									_ loader.loadMTree
										@ ittfDocumentUri
										@ loadContext
										@ callback
					else
						set loadContext.__ittfDocumentStore = ittfDocumentStore
                        if frontMatter
                            _ loader.loadMTreeFrontMatter
                                @ ittfDocumentUri
                                @ loadContext
                                @ callback
						elif raw
							_ loader.loadMTreeRaw
								@ ittfDocumentUri
								@ loadContext
								@ callback
						elif mTreeBuildupScript
							_ loader.loadMTreeBuildupScript
								@ ittfDocumentUri
								@ loadContext
								@ callback
						else
							_ loader.loadMTree
								@ ittfDocumentUri
								@ loadContext
								@ callback
