/**
 * 默认状态适配器
 * 
 * 这是 Secra Framework 内置的默认状态适配器实现
 * 不依赖任何外部状态管理库，提供基础的状态管理能力
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "DefaultAdapter", {
    enumerable: true,
    get: function() {
        return DefaultAdapter;
    }
});
const _StateInstance = require("../core/StateInstance");
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
let DefaultAdapter = class DefaultAdapter {
    /**
   * 创建状态实例
   */ createInstance(initialValue, options) {
        if (this.destroyed) {
            throw new Error('Adapter has been destroyed');
        }
        const instance = new _StateInstance.StateInstance(initialValue, {
            id: options?.id,
            scope: options?.scope,
            devMode: options?.devMode,
            middleware: options?.middleware
        });
        this.instances.add(instance);
        return instance;
    }
    /**
   * 销毁适配器
   */ destroy() {
        if (this.destroyed) {
            return;
        }
        // 销毁所有创建的状态实例
        for (const instance of this.instances){
            instance.destroy();
        }
        this.instances.clear();
        this.destroyed = true;
    }
    /**
   * 获取适配器名称
   */ getName() {
        return this.name;
    }
    constructor(){
        /**
   * 适配器名称
   */ _define_property(this, "name", 'DefaultAdapter');
        /**
   * 是否已销毁
   */ _define_property(this, "destroyed", false);
        /**
   * 创建的状态实例集合（用于销毁时清理）
   */ _define_property(this, "instances", new Set());
    }
};

//# sourceMappingURL=DefaultAdapter.js.map