"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const ora = require("ora");
const publisher_1 = require("../../server/publish/publisher");
const util_1 = require("../../server/util");
const options_1 = require("../options");
const writer_1 = require("../writer");
function default_1(options) {
    return __awaiter(this, void 0, void 0, function* () {
        const [name, version] = options.package.split('@');
        if (!version) {
            throw new Error(`--package must be given in the form "name@version"`);
        }
        const confirmation = `You about to unpublish version ${version} of your interactive` +
            `controls. This WILL BREAK the experience of anyone who is using this version.`;
        if (!options.force && !(yield writer_1.default.confirm(confirmation, false))) {
            writer_1.default.write('Aborted.');
            return;
        }
        const spinner = ora('Unpublishing from Mixer...').start();
        const fetcher = new util_1.Fetcher().with(yield options.project.profile.tokens());
        yield new publisher_1.Publisher(fetcher).unpublish(name, version).catch(options_1.failSpiner(spinner));
        spinner.succeed(`Successfully unpublished ${name}@${version}`);
    });
}
exports.default = default_1;
