{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module WikiMusic.SSR.View.GenreHtml
  ( genreListPage',
    genreDetailPage',
    genreCreatePage',
  )
where

import Data.Map qualified as Map
import Optics
import Relude
import Text.Blaze.Html
import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A
import WikiMusic.Interaction.Model.Genre
import WikiMusic.SSR.Language
import WikiMusic.SSR.Model.Api
import WikiMusic.SSR.Model.Env
import WikiMusic.SSR.View.Components.Forms
import WikiMusic.SSR.View.Components.Meta
import WikiMusic.SSR.View.Components.Other
import WikiMusic.SSR.View.Components.PageTop

genreListPage' :: (MonadIO m) => Env -> UiMode -> Language -> Palette -> SortOrder -> GetGenresQueryResponse -> m Html
genreListPage' :: forall (m :: * -> *).
MonadIO m =>
Env
-> UiMode
-> Language
-> Palette
-> SortOrder
-> GetGenresQueryResponse
-> m Html
genreListPage' Env
env UiMode
mode Language
language Palette
palette SortOrder
sortOrder GetGenresQueryResponse
xs = do
  Html
sharedHead <- Env -> UiMode -> Palette -> Text -> m Html
forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Palette -> Text -> m Html
mkSharedHead Env
env UiMode
mode Palette
palette (LanguageDict
dictionary LanguageDict
-> Optic' A_Lens NoIx LanguageDict DictTerm -> DictTerm
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
#titles Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
-> Optic A_Lens NoIx Titles Titles DictTerm DictTerm
-> Optic' A_Lens NoIx LanguageDict DictTerm
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens NoIx Titles Titles DictTerm DictTerm
#genresPage DictTerm -> Language -> Text
|##| Language
language)
  Html -> m Html
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Html -> m Html) -> Html -> m Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
H.html (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
    Html
sharedHead
    Html -> Html
body (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
section (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
      Maybe Text -> UiMode -> Language -> Palette -> Html
sharedPageTop (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ LanguageDict
dictionary LanguageDict
-> Optic' A_Lens NoIx LanguageDict DictTerm -> DictTerm
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
#titles Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
-> Optic A_Lens NoIx Titles Titles DictTerm DictTerm
-> Optic' A_Lens NoIx LanguageDict DictTerm
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens NoIx Titles Titles DictTerm DictTerm
#genresPage DictTerm -> Language -> Text
|##| Language
language) UiMode
mode Language
language Palette
palette
      Html -> Html
section (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"flex direction-row justify-content-center gap-small align-items-baseline" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
        Html -> Html
H.a (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
href AttributeValue
"/genres/create" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
button (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
H.small Html
"+ new genre"
        Language -> SortOrder -> Text -> Text -> Html
mkSortingForm Language
language SortOrder
sortOrder Text
"/user-preferences/genre-sorting" Text
"genre-sorting"
      Html -> Html
section (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"entity-card-section" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ (Genre -> Html) -> [Genre] -> Html
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Language -> Text -> Genre -> Html
forall k1 k3 k4 k5 k6 k7 k8 k9 a k10 l1 l2 s1 u v k11 s2 k12 s3.
(Is k1 A_Getter, Is k3 A_Getter, Is k4 A_Getter, Is k5 A_Getter,
 Is k6 A_Getter, Is k7 A_Getter, Is k8 A_Getter, Is k9 A_Getter,
 Show a, JoinKinds k10 l1 k4, JoinKinds k10 l2 k3,
 LabelOptic "displayName" k8 s1 s1 Text Text,
 LabelOptic "isLike" l1 u v Bool Bool,
 LabelOptic "artworks" k5 s1 s1 (Map k11 s2) (Map k11 s2),
 LabelOptic "identifier" k7 s1 s1 UUID UUID,
 LabelOptic "opinions" k9 s1 s1 (Map k12 s3) (Map k12 s3),
 LabelOptic "viewCount" k1 s1 s1 a a,
 LabelOptic "artwork" k6 s2 s2 Artwork Artwork,
 LabelOptic "opinion" k10 s3 s3 u v,
 LabelOptic "isDislike" l2 u v Bool Bool) =>
Language -> Text -> s1 -> Html
simpleEntityCard Language
language Text
"genres") [Genre]
sortedXs
  where
    sortedXs :: [Genre]
sortedXs =
      (UUID -> Maybe Genre) -> [UUID] -> [Genre]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
        (\UUID
identifier -> (GetGenresQueryResponse
xs GetGenresQueryResponse
-> Optic' A_Lens NoIx GetGenresQueryResponse (Map UUID Genre)
-> Map UUID Genre
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx GetGenresQueryResponse (Map UUID Genre)
#genres) Map UUID Genre -> UUID -> Maybe Genre
forall k a. Ord k => Map k a -> k -> Maybe a
Map.!? UUID
identifier)
        (GetGenresQueryResponse
xs GetGenresQueryResponse
-> Optic' A_Lens NoIx GetGenresQueryResponse [UUID] -> [UUID]
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx GetGenresQueryResponse [UUID]
#sortOrder)

genreDetailPage' :: (MonadIO m) => Env -> UiMode -> Language -> Palette -> Genre -> m Html
genreDetailPage' :: forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Language -> Palette -> Genre -> m Html
genreDetailPage' Env
env UiMode
mode Language
language Palette
palette Genre
x = do
  Html
sharedHead <- Env -> UiMode -> Palette -> Text -> m Html
forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Palette -> Text -> m Html
mkSharedHead Env
env UiMode
mode Palette
palette (LanguageDict
dictionary LanguageDict
-> Optic' A_Lens NoIx LanguageDict DictTerm -> DictTerm
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
#titles Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
-> Optic A_Lens NoIx Titles Titles DictTerm DictTerm
-> Optic' A_Lens NoIx LanguageDict DictTerm
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens NoIx Titles Titles DictTerm DictTerm
#genresPage DictTerm -> Language -> Text
|##| Language
language)
  Html -> m Html
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Html -> m Html) -> Html -> m Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
H.html (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
    Html
sharedHead
    Html -> Html
body (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
section (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
      Maybe Text -> UiMode -> Language -> Palette -> Html
sharedPageTop Maybe Text
forall a. Maybe a
Nothing UiMode
mode Language
language Palette
palette
      Language -> Text -> Genre -> Html
forall k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 k12 k13 (t1 :: * -> *)
       (t2 :: * -> *) (t3 :: * -> *) (t4 :: * -> *) (t5 :: * -> *)
       (t6 :: * -> *) a1 a2 a3 a4 a5 s k14 a6.
(Is k1 A_Getter, Is k2 A_Getter, Is k3 A_Getter, Is k4 A_Getter,
 Is k5 A_Getter, Is k6 A_Getter, Is k7 A_Getter, Is k8 A_Getter,
 Is k9 A_Getter, Is k10 A_Getter, Is k11 A_Getter, Is k12 A_Getter,
 Is k13 A_Getter, Foldable t1, Foldable t2, Foldable t3,
 Foldable t4, Foldable t5, Foldable t6, Show a1, Show a2, Show a3,
 Show a4, Show a5, Functor t4, LabelOptic "createdAt" k4 s s a2 a2,
 LabelOptic "createdBy" k3 s s a1 a1,
 LabelOptic "lastEditedAt" k11 s s (t4 a5) (t4 a5),
 LabelOptic "displayName" k5 s s Text Text,
 LabelOptic "artworks" k6 s s (Map k14 a6) (Map k14 a6),
 LabelOptic "identifier" k9 s s a3 a3,
 LabelOptic "viewCount" k10 s s a4 a4,
 LabelOptic "artwork" k7 a6 a6 Artwork Artwork,
 LabelOptic "description" k8 s s (t3 Text) (t3 Text),
 LabelOptic "soundcloudUrl" k1 s s (t1 Text) (t1 Text),
 LabelOptic "spotifyUrl" k12 s s (t5 Text) (t5 Text),
 LabelOptic "wikipediaUrl" k2 s s (t2 Text) (t2 Text),
 LabelOptic "youtubeUrl" k13 s s (t6 Text) (t6 Text)) =>
Language -> Text -> s -> Html
entityDetails Language
language Text
"genres" Genre
x

genreCreatePage' :: (MonadIO m) => Env -> UiMode -> Language -> Palette -> m Html
genreCreatePage' :: forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Language -> Palette -> m Html
genreCreatePage' Env
env UiMode
mode Language
language Palette
palette = do
  Html
sharedHead <- Env -> UiMode -> Palette -> Text -> m Html
forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Palette -> Text -> m Html
mkSharedHead Env
env UiMode
mode Palette
palette (LanguageDict
dictionary LanguageDict
-> Optic' A_Lens NoIx LanguageDict DictTerm -> DictTerm
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
#titles Optic A_Lens NoIx LanguageDict LanguageDict Titles Titles
-> Optic A_Lens NoIx Titles Titles DictTerm DictTerm
-> Optic' A_Lens NoIx LanguageDict DictTerm
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens NoIx Titles Titles DictTerm DictTerm
#genresPage DictTerm -> Language -> Text
|##| Language
language)
  Html -> m Html
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Html -> m Html) -> Html -> m Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
H.html (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
    Html
sharedHead
    Html -> Html
body (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html -> Html
section (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
      Maybe Text -> UiMode -> Language -> Palette -> Html
sharedPageTop Maybe Text
forall a. Maybe a
Nothing UiMode
mode Language
language Palette
palette
      Html -> Html
section (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
        Html -> Html
H.h2 Html
"Create genre"
        Text -> Html -> Html
postForm Text
"/genres/create" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
          Text -> Text -> Html
requiredTextInput Text
"displayName" Text
"genre name"
          Text -> Text -> Html
optionalTextArea Text
"description" Text
"description"
          Text -> Text -> Html
optionalTextInput Text
"spotifyUrl" Text
"spotify URL"
          Text -> Text -> Html
optionalTextInput Text
"youtubeUrl" Text
"youtube URL"
          Text -> Text -> Html
optionalTextInput Text
"wikipediaUrl" Text
"wikipedia URL"
          Text -> Text -> Html
optionalTextInput Text
"soundcloudUrl" Text
"soundcloud URL"
          Language -> Html
submitButton Language
language