{-# LANGUAGE OverloadedStrings #-}

module Lucid.Hyperscript (useHyperscript, useHyperscriptVersion, _hs, __) where

import Data.Text ( pack, Text )
import Lucid (Html, HtmlT, script_, src_)
import Lucid.Base (Attribute, makeAttribute)
import Lucid.Hyperscript.QuasiQuoter (__, _hs)

useHyperscript :: Monad m => HtmlT m ()
useHyperscript :: HtmlT m ()
useHyperscript = [Attribute] -> Html () -> HtmlT m ()
forall arg result. TermRaw arg result => arg -> result
script_ [Text -> Attribute
src_ Text
"https://unpkg.com/hyperscript.org"] (Html ()
"" :: Html ())

useHyperscriptVersion :: Monad m => (Int, Int, Int) -> HtmlT m ()
useHyperscriptVersion :: (Int, Int, Int) -> HtmlT m ()
useHyperscriptVersion (Int
major, Int
minor, Int
patch) = [Attribute] -> Html () -> HtmlT m ()
forall arg result. TermRaw arg result => arg -> result
script_ [Text -> Attribute
src_ Text
url] (Html ()
"" :: Html ())
  where
    url :: Text
    url :: Text
url =
      Text
"https://unpkg.com/hyperscript.org@"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showT Int
major
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showT Int
minor
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showT Int
patch

    showT :: Show a => a -> Text
    showT :: a -> Text
showT = String -> Text
pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show