/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2019 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it. If you have received this file from a source other than Adobe,
* then your use, modification, or distribution of it requires the prior
* written permission of Adobe. 
**************************************************************************/

// time display types

var TIMEDISPLAY_24Timecode				= 100;
var TIMEDISPLAY_25Timecode				= 101;
var TIMEDISPLAY_2997DropTimecode		= 102;
var TIMEDISPLAY_2997NonDropTimecode		= 103;
var TIMEDISPLAY_30Timecode				= 104;
var TIMEDISPLAY_50Timecode				= 105;
var TIMEDISPLAY_5994DropTimecode		= 106;
var TIMEDISPLAY_5994NonDropTimecode		= 107;
var TIMEDISPLAY_60Timecode				= 108;
var TIMEDISPLAY_Frames					= 109;
var TIMEDISPLAY_23976Timecode			= 110;
var TIMEDISPLAY_16mmFeetFrames			= 111;
var TIMEDISPLAY_35mmFeetFrames			= 112;
var TIMEDISPLAY_48Timecode				= 113;
var TIMEDISPLAY_AudioSamplesTimecode	= 200;
var TIMEDISPLAY_AudioMsTimecode			= 201;
 
// field type constants

var FIELDTYPE_Progressive	= 0;
var FIELDTYPE_UpperFirst	= 1;
var FIELDTYPE_LowerFirst	= 2;

// audio channel types

var AUDIOCHANNELTYPE_Mono			= 0;
var AUDIOCHANNELTYPE_Stereo			= 1;
var AUDIOCHANNELTYPE_51				= 2;
var AUDIOCHANNELTYPE_Multichannel	= 3;
var AUDIOCHANNELTYPE_4Channel		= 4;
var AUDIOCHANNELTYPE_8Channel		= 5;
 
// vr projection type

var VRPROJECTIONTYPE_None				= 0;
var VRPROJECTIONTYPE_Equirectangular	= 1;
 
// vr stereoscopic type

var VRSTEREOSCOPICTYPE_Monoscopic		= 0;        
var VRSTEREOSCOPICTYPE_OverUnder		= 1;        
var VRSTEREOSCOPICTYPE_SideBySide		= 2;        

// constants used when clearing cache

var MediaType_VIDEO		= "228CDA18-3625-4d2d-951E-348879E4ED93"; // Magical constants from Premiere Pro's internal automation.
var MediaType_AUDIO		= "80B8E3D5-6DCA-4195-AEFB-CB5F407AB009";
var MediaType_ANY		= "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
		
var MediaType_Audio = 0;	// Constants for working with setting value. 
var MediaType_Video = 1;

var NOT_SET = "-400000";
//---------------------SHIT ABOVE SHOULD BE DELETED
//#include "baseFunc.jsxinc";
//#include "json2.jsxinc";
//$.evalFile("baseFunc.jsxinc");
//$.evalFile("json2.jsxinc");


function getMessageFromCore(path) {
    var packsFld = new Folder (path);
    var packs = [];

    // var fileRef = new File(path + "/Custom Presets.json");
    // var docRef = app.open(fileRef);

    for (var i = 0; i < packsFld.getFiles().length; i++)
    {
        var name = packsFld.getFiles()[i].name;
        var jsonPath = path + "/" + name + "/" + name + ".json";
        var jsonFile = new File(jsonPath);
        if (!jsonFile.exists)
            continue;
        jsonFile.open('r');
        var json = jsonFile.read();
        jsonFile.close();
        packs.push(JSON.parse(json));
    }
	
    return packs
}

var objCore = {};
objCore.getMessage = function () {
    return 'message from objCore.getMessage';
}

$._MOBRO_ = 
{

editObj : null,

dataPath : "",

setParm : function(name, val)
{
	this.editObj.setValue(name, val);
},

loadEditObj : function()
{
	var editFile = new File(new File($.fileName).path + "\\editFunc.jsxbin");
	this.editObj = $.evalFile(editFile);
	this.registerSelectionChanged(this.editObj.selectionChanged_clb);
},

checkMoBro : function(projectItem)
{
	if (ExternalObject.AdobeXMPScript === undefined)
		ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
	
	var xmpBlob = projectItem.getXMPMetadata();
	var xmp = new XMPMeta(xmpBlob);

	return xmp.doesPropertyExist(XMPConst.NS_DM, "MotionBro");
},

registerSelectionChanged : function(clb)
{
	app.unbind("onActiveSequenceSelectionChanged");
	app.bind("onActiveSequenceSelectionChanged", clb);
},

setPacksPath : function(path)
{
	this.dataPath = path;
    return this.dataPath
},

alertMes : function(mes){
	alert(mes);
},

mogrtSeq : function(importSettings, jsxbinToExecute)
{
	if (importSettings.ext == ".jsx" || importSettings.ext == ".jsxbin")
	{
		$.evalFile(importSettings.file_path);
		return;
	}
	
	var files = new Folder(importSettings.assetsFolder).getFiles();

	var f = null;
	for (var i = 0; i < files.length; i++) {
		if (files[i].displayName != "main.jsxbin")
			continue;
		
		var script;
		if (jsxbinToExecute.jsx) {
			script = eval(jsxbinToExecute.jsx)
		} else {
			script = $.evalFile(files[i]);
		}

		script.main(importSettings);
		return;
	}
	
	var freeMain = new File(new File($.fileName).path + "\\main.jsxbin");
	var script = $.evalFile(freeMain);
	
	script.main(importSettings);
},

}

//$._MOBRO_.registerSelectionChanged();
$._MOBRO_.loadEditObj();