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

module WikiMusic.SSR.View.ArtistHtml
  ( artistListPage',
    artistDetailPage',
    artistCreatePage',
  )
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.Artist
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

artistListPage' :: (MonadIO m) => Env -> UiMode -> Language -> Palette -> SortOrder -> GetArtistsQueryResponse -> m Html
artistListPage' :: forall (m :: * -> *).
MonadIO m =>
Env
-> UiMode
-> Language
-> Palette
-> SortOrder
-> GetArtistsQueryResponse
-> m Html
artistListPage' Env
env UiMode
mode Language
language Palette
palette SortOrder
sortOrder GetArtistsQueryResponse
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
#artistsPage 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
#artistsPage 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
"/artists/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 artist"
        Language -> SortOrder -> Text -> Text -> Html
mkSortingForm Language
language SortOrder
sortOrder Text
"/user-preferences/artist-sorting" Text
"artist-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
$ (Artist -> Html) -> [Artist] -> Html
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Language -> Text -> Artist -> 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
"artists") [Artist]
sortedXs
  where
    sortedXs :: [Artist]
sortedXs =
      (UUID -> Maybe Artist) -> [UUID] -> [Artist]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
        (\UUID
identifier -> (GetArtistsQueryResponse
xs GetArtistsQueryResponse
-> Optic' A_Lens NoIx GetArtistsQueryResponse (Map UUID Artist)
-> Map UUID Artist
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx GetArtistsQueryResponse (Map UUID Artist)
#artists) Map UUID Artist -> UUID -> Maybe Artist
forall k a. Ord k => Map k a -> k -> Maybe a
Map.!? UUID
identifier)
        (GetArtistsQueryResponse
xs GetArtistsQueryResponse
-> Optic' A_Lens NoIx GetArtistsQueryResponse [UUID] -> [UUID]
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx GetArtistsQueryResponse [UUID]
#sortOrder)

artistDetailPage' :: (MonadIO m) => Env -> UiMode -> Language -> Palette -> Artist -> m Html
artistDetailPage' :: forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Language -> Palette -> Artist -> m Html
artistDetailPage' Env
env UiMode
mode Language
language Palette
palette Artist
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
#artistsPage 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 -> Artist -> 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
"artists" Artist
x

artistCreatePage' :: (MonadIO m) => Env -> UiMode -> Language -> Palette -> m Html
artistCreatePage' :: forall (m :: * -> *).
MonadIO m =>
Env -> UiMode -> Language -> Palette -> m Html
artistCreatePage' 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
#artistsPage 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 artist"
        Text -> Html -> Html
postForm Text
"/artists/create" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
          Text -> Text -> Html
requiredTextInput Text
"displayName" Text
"artist 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