var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.injectPluginKotlinSync=exports.parseSplashActivitySync=exports.parseMainActivitySync=exports.parseMainApplicationSync=void 0;var _path=_interopRequireDefault(require("path"));
var _os=_interopRequireDefault(require("os"));
var _fs=_interopRequireDefault(require("fs"));
var _net=_interopRequireDefault(require("net"));
var _chalk=_interopRequireDefault(require("chalk"));
var _shelljs=_interopRequireDefault(require("shelljs"));
var _child_process=_interopRequireDefault(require("child_process"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _common=require("../../common");




















var _projectParser=require("../../projectTools/projectParser");
var _fileutils=require("../../systemTools/fileutils");
var _pluginTools=require("../../pluginTools");

var parseMainApplicationSync=function parseMainApplicationSync(c,platform){
var appFolder=(0,_common.getAppFolder)(c,platform);
var applicationPath='app/src/main/java/rnv/MainApplication.kt';
(0,_common.writeCleanFile)((0,_common.getBuildFilePath)(c,platform,applicationPath),_path.default.join(appFolder,applicationPath),[
{pattern:'{{APPLICATION_ID}}',override:(0,_common.getAppId)(c,platform)},
{pattern:'{{ENTRY_FILE}}',override:(0,_common.getEntryFile)(c,platform)},
{pattern:'{{GET_JS_BUNDLE_FILE}}',override:(0,_common.getGetJsBundleFile)(c,platform)},
{pattern:'{{PLUGIN_IMPORTS}}',override:c.pluginConfigAndroid.pluginImports},
{pattern:'{{PLUGIN_PACKAGES}}',override:c.pluginConfigAndroid.pluginPackages},
{pattern:'{{PLUGIN_METHODS}}',override:c.pluginConfigAndroid.mainApplicationMethods}]);

};exports.parseMainApplicationSync=parseMainApplicationSync;

var parseMainActivitySync=function parseMainActivitySync(c,platform){
var appFolder=(0,_common.getAppFolder)(c,platform);
var activityPath='app/src/main/java/rnv/MainActivity.kt';
(0,_common.writeCleanFile)((0,_common.getBuildFilePath)(c,platform,activityPath),_path.default.join(appFolder,activityPath),[
{pattern:'{{APPLICATION_ID}}',override:(0,_common.getAppId)(c,platform)},
{pattern:'{{PLUGIN_ACTIVITY_IMPORTS}}',override:c.pluginConfigAndroid.pluginActivityImports},
{pattern:'{{PLUGIN_ACTIVITY_METHODS}}',override:c.pluginConfigAndroid.pluginActivityMethods},
{pattern:'{{PLUGIN_ON_CREATE}}',override:c.pluginConfigAndroid.pluginActivityCreateMethods},
{pattern:'{{PLUGIN_ON_ACTIVITY_RESULT}}',override:c.pluginConfigAndroid.pluginActivityResultMethods}]);

};exports.parseMainActivitySync=parseMainActivitySync;

var parseSplashActivitySync=function parseSplashActivitySync(c,platform){
var appFolder=(0,_common.getAppFolder)(c,platform);
var splashPath='app/src/main/java/rnv/SplashActivity.kt';



var enableAndroidX=(0,_common.getConfigProp)(c,platform,'enableAndroidX');
if(enableAndroidX===true){
c.pluginConfigAndroid.pluginSplashActivityImports+='import androidx.appcompat.app.AppCompatActivity\n';
}else{
c.pluginConfigAndroid.pluginSplashActivityImports+='import android.support.v7.app.AppCompatActivity\n';
}

(0,_common.writeCleanFile)((0,_common.getBuildFilePath)(c,platform,splashPath),_path.default.join(appFolder,splashPath),[
{pattern:'{{APPLICATION_ID}}',override:(0,_common.getAppId)(c,platform)},
{pattern:'{{PLUGIN_SPLASH_ACTIVITY_IMPORTS}}',override:c.pluginConfigAndroid.pluginSplashActivityImports}]);

};exports.parseSplashActivitySync=parseSplashActivitySync;

var injectPluginKotlinSync=function injectPluginKotlinSync(c,plugin,key,pkg){
var pathFixed=plugin.path?""+plugin.path:"node_modules/"+key+"/android";
var modulePath="../../"+pathFixed;

if(plugin.activityImports instanceof Array){
plugin.activityImports.forEach(function(activityImport){

if(c.pluginConfigAndroid.pluginActivityImports.indexOf(activityImport)===-1){
c.pluginConfigAndroid.pluginActivityImports+="import "+activityImport+"\n";
}
});
}

if(plugin.activityMethods instanceof Array){
c.pluginConfigAndroid.pluginActivityMethods+='\n';
c.pluginConfigAndroid.pluginActivityMethods+=""+plugin.activityMethods.join('\n    ');
}var

mainActivity=plugin.mainActivity;
if(mainActivity){
if(mainActivity.createMethods instanceof Array){
c.pluginConfigAndroid.pluginActivityCreateMethods+='\n';
c.pluginConfigAndroid.pluginActivityCreateMethods+=""+mainActivity.createMethods.join('\n    ');
}

if(mainActivity.resultMethods instanceof Array){
c.pluginConfigAndroid.pluginActivityResultMethods+='\n';
c.pluginConfigAndroid.pluginActivityResultMethods+=""+mainActivity.resultMethods.join('\n    ');
}

if(mainActivity.imports instanceof Array){
mainActivity.imports.forEach(function(v){
c.pluginConfigAndroid.pluginActivityImports+="import "+v+"\n";
});
}

if(mainActivity.methods instanceof Array){
c.pluginConfigAndroid.pluginActivityMethods+='\n';
c.pluginConfigAndroid.pluginActivityMethods+=""+mainActivity.methods.join('\n    ');
}
}

if(plugin.imports){
plugin.imports.forEach(function(v){
c.pluginConfigAndroid.pluginImports+="import "+v+"\n";
});
}

_injectPackage(c,plugin,pkg);

if(plugin.MainApplication){
if(plugin.MainApplication.packages){
plugin.MainApplication.packages.forEach(function(v){
_injectPackage(c,plugin,v);
});
}
}

if(plugin.mainApplicationMethods){
c.pluginConfigAndroid.mainApplicationMethods+="\n"+plugin.mainApplicationMethods+"\n";
}
};exports.injectPluginKotlinSync=injectPluginKotlinSync;

var _injectPackage=function _injectPackage(c,plugin,pkg){
if(pkg)c.pluginConfigAndroid.pluginImports+="import "+pkg+"\n";
var packageParams='';
if(plugin.packageParams){
packageParams=plugin.packageParams.join(',');
}

var className=_extractClassName(pkg);
if(className)c.pluginConfigAndroid.pluginPackages+=className+"("+packageParams+"),\n";
};

var _extractClassName=function _extractClassName(pkg){return pkg?pkg.split('.').pop():null;};