package com.honeydue.storage

import kotlinx.browser.localStorage

/**
 * WASM implementation of TokenManager using browser's localStorage.
 */
actual class TokenManager {
    actual fun saveToken(token: String) {
        localStorage.setItem(KEY_TOKEN, token)
    }

    actual fun getToken(): String? {
        return localStorage.getItem(KEY_TOKEN)
    }

    actual fun clearToken() {
        localStorage.removeItem(KEY_TOKEN)
    }

    companion object {
        private const val KEY_TOKEN = "auth_token"

        private var instance: TokenManager? = null

        fun getInstance(): TokenManager {
            if (instance == null) {
                instance = TokenManager()
            }
            return instance!!
        }
    }
}
