module IHP.Breadcrumb.Types where

import IHP.Prelude
import Text.Blaze.Html (Html)
import Text.Blaze.Html.Renderer.String (renderHtml)
import ClassyPrelude

data BreadcrumbItem =
    BreadcrumbItem
    { BreadcrumbItem -> Html
breadcrumbLabel :: Html -- ^ The label of a single breadcrumbs item. May be HTML, thus use SVG or font icon.
    , BreadcrumbItem -> Maybe Text
url :: Maybe Text -- ^ The URL of the item. If Nothing, it will only show the label.
    }

-- Html doesn't have a Show instance, so we define it manually and use 'renderHtml' for that.
instance Show BreadcrumbItem where
    show :: BreadcrumbItem -> String
show BreadcrumbItem
breadcrumbItem = [plain|{ breadcrumbLabel = "#{breadcrumbLabel}", url = #{url} }|]
        where
            breadcrumbLabel :: String
breadcrumbLabel = Html -> String
renderHtml (Html -> String) -> Html -> String
forall a b. (a -> b) -> a -> b
$ BreadcrumbItem
breadcrumbItem.breadcrumbLabel
            url :: String
url = Maybe Text -> String
forall a. Show a => a -> String
ClassyPrelude.show (Maybe Text -> String) -> Maybe Text -> String
forall a b. (a -> b) -> a -> b
$ BreadcrumbItem
breadcrumbItem.url