use js_sys::{Function, Promise, Reflect};
use wasm_bindgen::JsCast;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[derive(Clone)]
pub type Clerk;
#[wasm_bindgen(catch, method, js_name = "load")]
pub fn load(this: &Clerk, opts: &JsValue) -> Result<Promise, JsValue>;
#[wasm_bindgen(catch, method, js_name = "signOut")]
pub fn sign_out(this: &Clerk, opts: &JsValue) -> Result<Promise, JsValue>;
#[wasm_bindgen(catch, method, js_name = "addListener")]
pub fn add_listener(this: &Clerk, cb: &Function) -> Result<Function, JsValue>;
#[wasm_bindgen(catch, method, getter)]
pub fn user(this: &Clerk) -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch, method, getter)]
pub fn session(this: &Clerk) -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch, method, js_name = "redirectToSignIn")]
pub fn redirect_to_sign_in(this: &Clerk, opts: &JsValue) -> Result<Promise, JsValue>;
#[wasm_bindgen(catch, method, js_name = "redirectToSignUp")]
pub fn redirect_to_sign_up(this: &Clerk, opts: &JsValue) -> Result<Promise, JsValue>;
#[wasm_bindgen(catch, method, js_name = "openSignIn")]
pub fn open_sign_in(this: &Clerk, opts: &JsValue) -> Result<(), JsValue>;
#[wasm_bindgen(catch, method, js_name = "closeSignIn")]
pub fn close_sign_in(this: &Clerk) -> Result<(), JsValue>;
#[wasm_bindgen(catch, method, js_name = "openSignUp")]
pub fn open_sign_up(this: &Clerk, opts: &JsValue) -> Result<(), JsValue>;
#[wasm_bindgen(catch, method, js_name = "closeSignUp")]
pub fn close_sign_up(this: &Clerk) -> Result<(), JsValue>;
#[wasm_bindgen(catch, method, js_name = "openUserProfile")]
pub fn open_user_profile(this: &Clerk, opts: &JsValue) -> Result<(), JsValue>;
#[wasm_bindgen(catch, method, js_name = "closeUserProfile")]
pub fn close_user_profile(this: &Clerk) -> Result<(), JsValue>;
}
pub fn clerk_singleton() -> Option<Clerk> {
let window = web_sys::window()?;
let clerk = Reflect::get(&window, &JsValue::from_str("Clerk")).ok()?;
if clerk.is_undefined() || clerk.is_null() {
return None;
}
let load = Reflect::get(&clerk, &JsValue::from_str("load")).ok()?;
if !load.is_function() {
return None;
}
Some(clerk.unchecked_into())
}
pub fn clerk_ui_ctor() -> Option<Function> {
let window = web_sys::window()?;
let ctor = Reflect::get(&window, &JsValue::from_str("__internal_ClerkUICtor")).ok()?;
ctor.dyn_into::<Function>().ok()
}