import { LocalStorage, SessionStorage } from '../../utils/storage';
export class StateStore {
    constructor() {
        /**
         * The key for what is being stored
         */
        this.storeKey = 'anjState';
        /**
         * The type of storage to use.
         * Options are `"local"` or `"sessions"` Defaults to session.
         */
        this.type = 'session';
    }
    componentWillLoad() {
        this.store = this.type === 'local' ? new LocalStorage() : new SessionStorage();
    }
    componentDidLoad() {
        this.anjStateStoreDidLoad.emit();
    }
    async get() {
        return this.store.getItem(this.storeKey);
    }
    async set(data) {
        return this.store.setItem(this.storeKey, data);
    }
    async clear() {
        return this.store.removeItem(this.storeKey);
    }
    static get is() { return "anj-state-store"; }
    static get properties() { return {
        "storeKey": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The key for what is being stored"
            },
            "attribute": "store-key",
            "reflect": false,
            "defaultValue": "'anjState'"
        },
        "type": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "'local' | 'session'",
                "resolved": "\"local\" | \"session\"",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The type of storage to use.\nOptions are `\"local\"` or `\"sessions\"` Defaults to session."
            },
            "attribute": "type",
            "reflect": false,
            "defaultValue": "'session'"
        }
    }; }
    static get events() { return [{
            "method": "anjStateStoreDidLoad",
            "name": "anjStateStoreDidLoad",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": "Emitted when the input has been created."
            },
            "complexType": {
                "original": "void",
                "resolved": "void",
                "references": {}
            }
        }]; }
    static get methods() { return {
        "get": {
            "complexType": {
                "signature": "() => Promise<any>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<any>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "set": {
            "complexType": {
                "signature": "(data: any) => Promise<void>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "clear": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
}
