{-# LANGUAGE PatternSynonyms #-}
-- For HasCallStack compatibility
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module JSDOM.Generated.History
       (back, forward, go, pushState, replaceState, getLength,
        setScrollRestoration, getScrollRestoration, getState, History(..),
        gTypeHistory)
       where
import Prelude ((.), (==), (>>=), return, IO, Int, Float, Double, Bool(..), Maybe, maybe, fromIntegral, round, realToFrac, fmap, Show, Read, Eq, Ord, Maybe(..))
import qualified Prelude (error)
import Data.Typeable (Typeable)
import Data.Traversable (mapM)
import Language.Javascript.JSaddle (JSM(..), JSVal(..), JSString, strictEqual, toJSVal, valToStr, valToNumber, valToBool, js, jss, jsf, jsg, function, asyncFunction, new, array, jsUndefined, (!), (!!))
import Data.Int (Int64)
import Data.Word (Word, Word64)
import JSDOM.Types
import Control.Applicative ((<$>))
import Control.Monad (void)
import Control.Lens.Operators ((^.))
import JSDOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import JSDOM.Enums

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.back Mozilla History.back documentation> 
back :: (MonadDOM m) => History -> m ()
back :: forall (m :: * -> *). MonadDOM m => History -> m ()
back History
self = DOM () -> m ()
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM (JSM JSVal -> DOM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> () -> JSF
forall name args.
(ToJSString name, MakeArgs args) =>
name -> args -> JSF
jsf String
"back" ()))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.forward Mozilla History.forward documentation> 
forward :: (MonadDOM m) => History -> m ()
forward :: forall (m :: * -> *). MonadDOM m => History -> m ()
forward History
self = DOM () -> m ()
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM (JSM JSVal -> DOM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> () -> JSF
forall name args.
(ToJSString name, MakeArgs args) =>
name -> args -> JSF
jsf String
"forward" ()))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.go Mozilla History.go documentation> 
go :: (MonadDOM m) => History -> Maybe Int -> m ()
go :: forall (m :: * -> *). MonadDOM m => History -> Maybe Int -> m ()
go History
self Maybe Int
distance
  = DOM () -> m ()
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM (JSM JSVal -> DOM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> [JSM JSVal] -> JSF
forall name args.
(ToJSString name, MakeArgs args) =>
name -> args -> JSF
jsf String
"go" [Maybe Int -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal Maybe Int
distance]))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.pushState Mozilla History.pushState documentation> 
pushState ::
          (MonadDOM m, ToJSVal data', ToJSString title, ToJSString url) =>
            History -> data' -> title -> Maybe url -> m ()
pushState :: forall (m :: * -> *) data' title url.
(MonadDOM m, ToJSVal data', ToJSString title, ToJSString url) =>
History -> data' -> title -> Maybe url -> m ()
pushState History
self data'
data' title
title Maybe url
url
  = DOM () -> m ()
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM
      (JSM JSVal -> DOM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void
         (History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> [JSM JSVal] -> JSF
forall name args.
(ToJSString name, MakeArgs args) =>
name -> args -> JSF
jsf String
"pushState"
            [data' -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal data'
data', title -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal title
title, Maybe url -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal Maybe url
url]))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.replaceState Mozilla History.replaceState documentation> 
replaceState ::
             (MonadDOM m, ToJSVal data', ToJSString title, ToJSString url) =>
               History -> data' -> title -> Maybe url -> m ()
replaceState :: forall (m :: * -> *) data' title url.
(MonadDOM m, ToJSVal data', ToJSString title, ToJSString url) =>
History -> data' -> title -> Maybe url -> m ()
replaceState History
self data'
data' title
title Maybe url
url
  = DOM () -> m ()
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM
      (JSM JSVal -> DOM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void
         (History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> [JSM JSVal] -> JSF
forall name args.
(ToJSString name, MakeArgs args) =>
name -> args -> JSF
jsf String
"replaceState"
            [data' -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal data'
data', title -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal title
title, Maybe url -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal Maybe url
url]))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.length Mozilla History.length documentation> 
getLength :: (MonadDOM m) => History -> m Word
getLength :: forall (m :: * -> *). MonadDOM m => History -> m Word
getLength History
self
  = DOM Word -> m Word
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM (Double -> Word
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Word) -> JSM Double -> DOM Word
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> IndexPreservingGetter History (JSM JSVal)
forall s name.
(MakeObject s, ToJSString name) =>
name -> IndexPreservingGetter s (JSM JSVal)
js String
"length") JSM JSVal -> (JSVal -> JSM Double) -> JSM Double
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= JSVal -> JSM Double
forall value. ToJSVal value => value -> JSM Double
valToNumber))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.scrollRestoration Mozilla History.scrollRestoration documentation> 
setScrollRestoration ::
                     (MonadDOM m) => History -> ScrollRestoration -> m ()
setScrollRestoration :: forall (m :: * -> *).
MonadDOM m =>
History -> ScrollRestoration -> m ()
setScrollRestoration History
self ScrollRestoration
val
  = DOM () -> m ()
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM (History
self History -> Getting (DOM ()) History (DOM ()) -> DOM ()
forall s a. s -> Getting a s a -> a
^. String
-> JSM JSVal
-> forall o. MakeObject o => IndexPreservingGetter o (DOM ())
forall name val.
(ToJSString name, ToJSVal val) =>
name
-> val
-> forall o. MakeObject o => IndexPreservingGetter o (DOM ())
jss String
"scrollRestoration" (ScrollRestoration -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal ScrollRestoration
val))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.scrollRestoration Mozilla History.scrollRestoration documentation> 
getScrollRestoration ::
                     (MonadDOM m) => History -> m ScrollRestoration
getScrollRestoration :: forall (m :: * -> *). MonadDOM m => History -> m ScrollRestoration
getScrollRestoration History
self
  = DOM ScrollRestoration -> m ScrollRestoration
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM ((History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> IndexPreservingGetter History (JSM JSVal)
forall s name.
(MakeObject s, ToJSString name) =>
name -> IndexPreservingGetter s (JSM JSVal)
js String
"scrollRestoration") JSM JSVal
-> (JSVal -> DOM ScrollRestoration) -> DOM ScrollRestoration
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= JSVal -> DOM ScrollRestoration
forall a. FromJSVal a => JSVal -> JSM a
fromJSValUnchecked)

-- | <https://developer.mozilla.org/en-US/docs/Web/API/History.state Mozilla History.state documentation> 
getState :: (MonadDOM m) => History -> m SerializedScriptValue
getState :: forall (m :: * -> *).
MonadDOM m =>
History -> m SerializedScriptValue
getState History
self
  = DOM SerializedScriptValue -> m SerializedScriptValue
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM ((History
self History -> Getting (JSM JSVal) History (JSM JSVal) -> JSM JSVal
forall s a. s -> Getting a s a -> a
^. String -> IndexPreservingGetter History (JSM JSVal)
forall s name.
(MakeObject s, ToJSString name) =>
name -> IndexPreservingGetter s (JSM JSVal)
js String
"state") JSM JSVal
-> (JSVal -> DOM SerializedScriptValue)
-> DOM SerializedScriptValue
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= JSVal -> DOM SerializedScriptValue
forall a. FromJSVal a => JSVal -> JSM a
fromJSValUnchecked)