System.register(["src/client/vivide/utils.js"], function (_export, _context) {
  "use strict";

  var scriptFolder, stepFolder, applicationFolder;
  return {
    setters: [function (_srcClientVivideUtilsJs) {
      scriptFolder = _srcClientVivideUtilsJs.scriptFolder;
      stepFolder = _srcClientVivideUtilsJs.stepFolder;
      applicationFolder = _srcClientVivideUtilsJs.applicationFolder;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_client_vivide_scripts_saving_js = _recorder_._src_client_vivide_scripts_saving_js || {};
      Object.defineProperty(_recorder_._src_client_vivide_scripts_saving_js, "writeFile", {
        get() {
          return writeFile;
        },

        set(thisIsVererySecretVariableName) {
          _export("writeFile", writeFile = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_vivide_scripts_saving_js, "getName", {
        get() {
          return getName;
        },

        set(thisIsVererySecretVariableName) {
          _export("getName", getName = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_vivide_scripts_saving_js, "applicationFolder", {
        get() {
          return applicationFolder;
        },

        set(thisIsVererySecretVariableName) {
          applicationFolder = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_vivide_scripts_saving_js, "stepFolder", {
        get() {
          return stepFolder;
        },

        set(thisIsVererySecretVariableName) {
          stepFolder = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_vivide_scripts_saving_js, "scriptFolder", {
        get() {
          return scriptFolder;
        },

        set(thisIsVererySecretVariableName) {
          scriptFolder = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      async function getName(saveTarget, type, noNameProvided) {
        let name, description;
        if (noNameProvided || !saveTarget[`${type}Name`]) {
          name = await lively.prompt("Please attach a name", `vivide-${type}-name`);

          // bad UI
          description = ""; // await lively.prompt("You may add a short description", "");
        } else {
          name = saveTarget[`${type}Name`];
          description = saveTarget[`${type}Description`];
        }
        saveTarget[`${type}Name`] = name;
        saveTarget[`${type}Description`] = description;
        if (name === undefined) return { name };
        const url = `${type === "script" ? scriptFolder : applicationFolder}${name}.json`;
        const exists = await lively.files.exists(url);
        if (exists) {
          const confirm = await lively.confirm(`Are you sure you want to overwrite ${name}?`);
          if (!confirm) {
            return getName(saveTarget, type, true);
          }
        }
        return { name, description, url };
      }

      _export("getName", getName);

      async function writeFile(url, content) {
        const res = await lively.files.saveFile(url, content);
        if (res.ok) {
          lively.success("Saved");
        } else {
          lively.error((await res.text()));
        }
      }

      _export("writeFile", writeFile);
    }
  };
});