"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.SoundBlocksExecutor = exports.EventBlocksExecutor = void 0;
exports.getConnectedCog = getConnectedCog;
require("core-js/modules/es.promise.js");
var _raft = require("@robotical/webapp-types/dist-types/src/types/raft");
/**
 * A class responsible for executing the appropriate movement when the middle button of Cog is pressed.
 */

class Executor {
  constructor() {}
  async execute() {}
}
exports.default = Executor;
function getConnectedCog() {
  var _window$applicationMa;
  const connectedCog = (_window$applicationMa = window.applicationManager) === null || _window$applicationMa === void 0 ? void 0 : _window$applicationMa.getTheCurrentlySelectedDeviceOrFirstOfItsKind(_raft.RaftTypeE.COG);
  return connectedCog;
}
class EventBlocksExecutor {}
exports.EventBlocksExecutor = EventBlocksExecutor;
class SoundBlocksExecutor {
  static async playSound(sound) {
    const connectedCog = getConnectedCog();
    if (!connectedCog) {
      return false;
    }
    let soundDuration = 0;
    switch (sound) {
      case "disbelief":
        soundDuration = 6000;
        await connectedCog.sendRestMessage('audio/rtttl/Disbelief:d=4,o=5,b=120:g,8d#,8e,8f,8f#,8g,8a,8b,8c6,8p,8c6,8b,8a,8g,8f#,8e,8f,8d#,8p,8g');
        break;
      case "confusion":
        soundDuration = 10000;
        await connectedCog.sendRestMessage('audio/rtttl/Confused:d=4,o=5,b=120:c,e,g,c6,e6,g6,c,e,g,c6,e6,g6,c,e,g,a,a,b,b,c6');
        break;
      case "excitement":
        soundDuration = 5000;
        await connectedCog.sendRestMessage('audio/rtttl/Excitement:d=4,o=5,b=180:c,e,g,8c6,16p,8c6,16p,8c6,16p,c,e,g,8c6,16p,8c6,16p,8c6,16p,c,e,g,8c6');
        break;
      case "noway":
        soundDuration = 6000;
        await connectedCog.sendRestMessage('audio/rtttl/NoWay:d=4,o=5,b=120:p,8g,8p,8c6,8p,8g,8p,8a,8p,8f,8p,8e,8p,8d,8p,8c,8p,8g,8p,8c6,8p,8g');
        break;
      case "no":
        soundDuration = 3000;
        await connectedCog.sendRestMessage('audio/rtttl/No:d=4,o=5,b=100:p,8c,8p,8c,8p,8c,8p,8c');
        break;
      case "whistle":
        soundDuration = 3000;
        await connectedCog.sendRestMessage('audio/rtttl/Whistle:d=4,o=6,b=140:16b5,16p,16b5,16p,16b5,16p,16g,16p,16e,16p,16g,16p,16c7,16p,16c7,16p,16c7,16p,16a,16p,16f,16p,16a,16p,16d7');
        break;
      default:
        break;
    }
    await wait(soundDuration);
    return true;
  }
}
exports.SoundBlocksExecutor = SoundBlocksExecutor;
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));