var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.PIPES=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));
var _chalk=_interopRequireDefault(require("chalk"));
var _path=_interopRequireDefault(require("path"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _common=require("../common");



var _setupTools=_interopRequireDefault(require("../setupTools"));
var _constants=require("../constants");
var _tizen=require("../platformTools/tizen");
var _webos=require("../platformTools/webos");
var _android=require("../platformTools/android");
var _apple=require("../platformTools/apple");
var _firefox=require("../platformTools/firefox");

var CREATE='create';
var REMOVE='remove';
var LAUNCH='launch';
var QUIT='quit';
var LIST='list';

var PIPES={
TARGET_CREATE_BEFORE:'target:create:before',
TARGET_CREATE_AFTER:'target:create:after',
TARGET_REMOVE_BEFORE:'target:remove:before',
TARGET_REMOVE_AFTER:'target:remove:after',
TARGET_LAUNCH_BEFORE:'target:launch:before',
TARGET_LAUNCH_AFTER:'target:launch:after',
TARGET_QUIT_BEFORE:'target:quit:before',
TARGET_QUIT_AFTER:'target:quit:after',
TARGET_LIST_BEFORE:'target:list:before',
TARGET_LIST_AFTER:'target:list:after'};exports.PIPES=PIPES;






var run=function run(c){return new Promise(function(resolve,reject){
(0,_common.logTask)('run');

switch(c.subCommand){






case LAUNCH:
(0,_common.isPlatformSupported)(c).
then(function(){return _runLaunch(c);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;



case LIST:
(0,_common.isPlatformSupported)(c).
then(function(){return _runList(c);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;
default:
return Promise.reject("cli:target Sub-Command "+_chalk.default.white.bold(c.subCommand)+" not supported!");}

});};





var _runLaunch=function _runLaunch(c){return new Promise(function(resolve,reject){
(0,_common.logTask)('_runLaunch');var
platform=c.platform,program=c.program;
var target=program.target||c.files.private.config.defaultTargets[platform];

switch(platform){
case _constants.ANDROID:
case _constants.ANDROID_TV:
case _constants.ANDROID_WEAR:
(0,_android.launchAndroidSimulator)(c,platform,target).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;
case _constants.IOS:
case _constants.TVOS:
(0,_apple.launchAppleSimulator)(c,platform,target).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;
case _constants.TIZEN:
(0,_tizen.launchTizenSimulator)(c,target).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;
case _constants.WEBOS:
(0,_webos.launchWebOSimulator)(c,target).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;
case _constants.KAIOS:
(0,_firefox.launchKaiOSSimulator)(c,target).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
return;
default:
reject("\"target launch\" command does not support "+
_chalk.default.white.bold(
platform)+" platform yet. You will have to launch the emulator manually. Working on it!");}



});};

var _runList=function _runList(c){var platform,throwError,setupInstance;return _regenerator.default.async(function _runList$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_common.logTask)('_runLaunch');
platform=c.platform;if(
(0,_common.isPlatformSupportedSync)(platform)){_context.next=4;break;}return _context.abrupt("return");case 4:

throwError=function throwError(err){
throw err;
};_context.t0=

platform;_context.next=_context.t0===
_constants.ANDROID?8:_context.t0===
_constants.ANDROID_TV?8:_context.t0===
_constants.ANDROID_WEAR?8:_context.t0===





_constants.IOS?13:_context.t0===
_constants.TVOS?13:_context.t0===

_constants.WEBOS?14:17;break;case 8:if((0,_common.checkSdk)(c,platform,_common.logError)){_context.next=12;break;}setupInstance=(0,_setupTools.default)(c);_context.next=12;return _regenerator.default.awrap(setupInstance.askToInstallSDK('android'));case 12:return _context.abrupt("return",(0,_android.listAndroidTargets)(c,platform));case 13:return _context.abrupt("return",(0,_apple.listAppleDevices)(c,platform));case 14:if(
(0,_common.checkSdk)(c,platform,throwError)){_context.next=16;break;}return _context.abrupt("return");case 16:return _context.abrupt("return",
(0,_webos.listWebOSTargets)(c));case 17:throw"\"target list\" command does not support "+

_chalk.default.white.bold(platform)+" platform yet. Working on it!";case 18:case"end":return _context.stop();}}});};var _default=





run;exports.default=_default;