"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../Class/Functional");
const spec_1 = require("../../../../client/spec");
const cloneUnitClass_1 = require("../../../../cloneUnitClass");
const weakMerge_1 = require("../../../../weakMerge");
const _ids_1 = require("../../../_ids");
class UnsetPin extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['unit', 'type', 'name', 'data'],
            o: ['unit'],
        }, {}, system, _ids_1.ID_UNSET_PIN);
    }
    f({ unit, type, name }, done) {
        const { unit: { id }, specs, } = unit.__bundle;
        const spec = (0, spec_1.getSpec)((0, weakMerge_1.weakMerge)(specs, this.__system.specs), id);
        if (!spec[`${type}s`][name]) {
            done(undefined, `${type} not found`);
            return;
        }
        const NewBundle = (0, cloneUnitClass_1.cloneUnitBundle)(unit);
        NewBundle.__bundle.unit.input = NewBundle.__bundle.unit.input || {};
        NewBundle.__bundle.unit.input[name] =
            NewBundle.__bundle.unit.input[name] || {};
        delete NewBundle.__bundle.unit.input[name].data;
        done({ unit: NewBundle });
    }
}
exports.default = UnsetPin;
//# sourceMappingURL=index.js.map