"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../Class/Holder");
const extractValueInterface_1 = require("../../../extractValueInterface");
const Async_1 = require("../../../types/interface/async/Async");
const clone_1 = require("../../../util/clone");
const weakMerge_1 = require("../../../weakMerge");
const wrap_1 = require("../../../wrap");
const Array_1 = require("../../../wrap/Array");
const Object_1 = require("../../../wrap/Object");
const SharedValue_1 = require("../../../wrap/SharedValue");
const _ids_1 = require("../../_ids");
class State extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['init'],
            fo: ['data'],
            i: [],
            o: [],
        }, {
            output: {
                data: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_STATE);
    }
    f({ init }, done) {
        const sharedRef = { current: (0, clone_1.clone)(init) };
        let api = (0, weakMerge_1.weakMerge)((0, SharedValue_1.wrapSharedValue)(sharedRef, this.__system), {
            raw: function () {
                return sharedRef.current;
            },
        });
        let _ = (0, extractValueInterface_1.extractValueInterface)(init);
        if (_) {
            switch (_) {
                case 'A':
                    {
                        api = (0, weakMerge_1.weakMerge)(api, (0, Array_1.wrapSharedRefArrayInterface)(sharedRef));
                    }
                    break;
                case 'J':
                    {
                        api = (0, weakMerge_1.weakMerge)(api, (0, Object_1.wrapSharedRef)(sharedRef));
                    }
                    break;
            }
        }
        const __ = _ ? ['V', _] : ['V'];
        let data = (0, Async_1.Async)(api, __, this.__system.async);
        data = (0, wrap_1.$wrap)(this.__system, api, __);
        done({
            data,
        });
    }
}
exports.default = State;
//# sourceMappingURL=index.js.map