"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    SafeStorage: ()=>SafeStorage,
    StorageItems: ()=>StorageItems
});
var StorageItems = /*#__PURE__*/ function(StorageItems) {
    StorageItems["RECENT_QUERIES"] = "coveo-recent-queries";
    StorageItems["STANDALONE_SEARCH_BOX_DATA"] = "coveo-standalone-search-box-data";
    StorageItems["GENERATED_ANSWER_DATA"] = "coveo-generated-answer-data";
    return StorageItems;
}({});
class SafeStorage {
    clear() {
        return this.tryAccessLocalStorageOrWarn(()=>localStorage.clear(), ()=>{});
    }
    getItem(key) {
        return this.tryAccessLocalStorageOrWarn(()=>localStorage.getItem(key), ()=>null);
    }
    getParsedJSON(key, fallback) {
        const item = this.getItem(key);
        if (!item) return fallback;
        return this.tryJSONOrWarn(key, ()=>JSON.parse(item), ()=>fallback);
    }
    key(index) {
        return this.tryAccessLocalStorageOrWarn(()=>localStorage.key(index), ()=>null);
    }
    get length() {
        return this.tryOrElse(()=>localStorage.length, ()=>0);
    }
    removeItem(key) {
        return this.tryAccessLocalStorageOrWarn(()=>localStorage.removeItem(key), ()=>{});
    }
    setItem(key, value) {
        return this.tryAccessLocalStorageOrWarn(()=>localStorage.setItem(key, value), ()=>{});
    }
    setJSON(key, obj) {
        const stringified = this.tryJSONOrWarn(key, ()=>JSON.stringify(obj), ()=>JSON.stringify({}));
        return this.setItem(key, stringified);
    }
    tryAccessLocalStorageOrWarn(tryTo, orElse) {
        return this.tryOrElse(tryTo, ()=>{
            console.warn('Error while trying to read or modify local storage. This can be caused by browser specific settings.');
            return orElse();
        });
    }
    tryJSONOrWarn(key, tryTo, orElse) {
        return this.tryOrElse(tryTo, ()=>{
            console.warn(`Error while trying to do JSON manipulation with local storage entry. ${key}`);
            return orElse();
        });
    }
    tryOrElse(tryTo, orElse) {
        try {
            return tryTo();
        } catch (e) {
            console.warn(e);
            return orElse();
        }
    }
}
exports.SafeStorage = __webpack_exports__.SafeStorage;
exports.StorageItems = __webpack_exports__.StorageItems;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "SafeStorage",
    "StorageItems"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
