{-# LANGUAGE AllowAmbiguousTypes #-}
{-|
Module: IHP.ServerSideComponent.ViewFunctions
Copyright: (c) digitally induced GmbH, 2021
-}
module IHP.ServerSideComponent.ViewFunctions where

import IHP.Prelude
import IHP.ViewSupport
import IHP.ServerSideComponent.Types
import IHP.HSX.QQ (hsx)

import qualified Data.Typeable as Typeable

component :: forall component action. (Component component action, Typeable component) => Html
component :: forall component action.
(Component component action, Typeable component) =>
Html
component = component -> Html
forall component action.
(Component component action, Typeable component) =>
component -> Html
componentFromState (forall state action. Component state action => state
initialState @component)

componentFromState :: forall component action. (Component component action, Typeable component) => component -> Html
componentFromState :: forall component action.
(Component component action, Typeable component) =>
component -> Html
componentFromState component
state = [hsx|<div class="ihp-ssc" data-path={path}>{render state}</div>|]
    where
        path :: Text
path = Text
"/SSC/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
typeName
        typeName :: Text
typeName = (component
forall a. HasCallStack => a
undefined :: component)
                component -> (component -> TypeRep) -> TypeRep
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> component -> TypeRep
forall a. Typeable a => a -> TypeRep
Typeable.typeOf
                TypeRep -> (TypeRep -> Text) -> Text
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> TypeRep -> Text
forall a. Show a => a -> Text
show