var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import RNAsyncStorage from '@react-native-async-storage/async-storage';
export class AsyncStorage {
    get(key) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                return yield RNAsyncStorage.getItem(key);
            }
            catch (error) {
                console.warn('Error retrieving stored item:', error);
                return null;
            }
        });
    }
    set(key, value) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                yield RNAsyncStorage.setItem(key, value);
            }
            catch (error) {
                console.warn(`Error storing key ${key}:`, error);
            }
        });
    }
    removeItem(key) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                yield RNAsyncStorage.removeItem(key);
            }
            catch (error) {
                console.warn(`Error removing key ${key}:`, error);
            }
        });
    }
    clear(prefix) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                const keys = yield RNAsyncStorage.getAllKeys();
                for (const key of keys) {
                    if (key.startsWith(prefix)) {
                        try {
                            yield RNAsyncStorage.removeItem(key);
                        }
                        catch (error) {
                            console.warn(`Error clearing key ${key}:`, error);
                        }
                    }
                }
            }
            catch (error) {
                console.warn(`Error getting keys for prefix ${prefix}:`, error);
            }
        });
    }
}
