module Pages.Interviews exposing (Model, Msg, page)

import Config.Data.Identity exposing (pageNames)
import Config.Data.ImageFolders as M
    exposing
        ( ImageFolder(..)
        , imagePathMaker
        )
import Config.Helpers.Cards.Inner.StrengthBar
    exposing
        ( barMaker
        , barPadding
        )
import Config.Helpers.Cards.Inner.Text
    exposing
        ( detailBodyLink
        , detailBodyMaker
        , detailFormat
        , detailFormatEl
        , detailSpacing
        , detailTitleLinkWide
        , detailTitleMaker
        , listCounter
        , listItem
        , listMaker
        , listMaker2
        , socialMaker
        )
import Config.Helpers.Cards.Inner.ToolTip
    exposing
        ( ToolTipPosition(..)
        , tooltip
        )
import Config.Helpers.Cards.Outer.Helpers exposing (cardMaker)
import Config.Helpers.Cards.Outer.Types as C exposing (Cardable(..))
import Config.Helpers.Converters exposing (formatSocial)
import Config.Helpers.Headers.Helpers exposing (headerMaker)
import Config.Helpers.Headers.Records exposing (interviewHeader)
import Config.Helpers.Headers.Types as R exposing (Header)
import Config.Helpers.Response
    exposing
        ( pageList
        , topLevelContainer
        )
import Config.Helpers.Viewport exposing (resetViewport)
import Config.Pages.Debate.Cuckery.List exposing (cuckList)
import Config.Pages.Interviews.Records.DrShawnBakerPodcast exposing (drShawnBakerPodcast)
import Config.Pages.Interviews.Records.FitAndFurious exposing (fitAndFurious)
import Config.Pages.Interviews.Records.FoolproofMastery exposing (foolproofMastery)
import Config.Pages.Interviews.Records.KetogeeksPodcast exposing (ketoGeeksPodcast)
import Config.Pages.Interviews.Records.LegendaryLifePodcast exposing (legendaryLifePodcast)
import Config.Pages.Interviews.Records.MarkBellsPowerProject exposing (markBellsPowerProject)
import Config.Pages.Interviews.Records.MuscleMemoirsPodcast exposing (muscleMemoirsPodcast)
import Config.Pages.Interviews.Records.SigmaNutritionRadio exposing (sigmaNutritionRadio)
import Config.Pages.Interviews.Records.StrenuousLifePodcast exposing (strenuousLifePodcast)
import Config.Pages.Interviews.Types
    exposing
        ( Appearance
        , Interview
        , Subjects
        )
import Config.Style.Colour.Helpers
    exposing
        ( ThemeColor(..)
        , colourTheme
        )
import Config.Style.Images
    exposing
        ( ElementSize(..)
        , imageSquareMaker
        )
import Effect exposing (Effect)
import Element as E
    exposing
        ( Device
        , DeviceClass(..)
        , Element
        , Orientation(..)
        , alignLeft
        , alignTop
        , column
        , el
        , explain
        , fill
        , newTabLink
        , none
        , paddingEach
        , row
        , text
        , width
        )
import Html.Attributes as H exposing (style)
import Layouts
import Page exposing (Page)
import Route exposing (Route)
import Shared exposing (Model)
import View exposing (View)


page : Shared.Model -> Route () -> Page Model Msg
page shared route =
    Page.new
        { init = init
        , update = update
        , subscriptions = subscriptions
        , view = view shared
        }
        |> Page.withLayout toLayout


toLayout : Model -> Layouts.Layout Msg
toLayout model =
    Layouts.Navbar {}



-- INIT


type alias Model =
    {}


init : () -> ( Model, Effect Msg )
init () =
    ( {}
    , Effect.map
        (\_ -> NoOp)
        (Effect.sendCmd resetViewport)
    )



-- UPDATE


type Msg
    = NoOp


update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
    case msg of
        NoOp ->
            ( model
            , Effect.none
            )



-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.none



-- VIEW


view : Shared.Model -> Model -> View Msg
view shared model =
    { title = pageNames.pageInterviews
    , attributes = []
    , element = interviewContainer shared
    }


interviewContainer : Shared.Model -> Element msg
interviewContainer shared =
    topLevelContainer (interviewList shared)


interviewList : Shared.Model -> Element msg
interviewList shared =
    column
        (case shared.device.class of
            _ ->
                pageList shared.device
        )
    <|
        List.concat
            [ [ headerMaker (R.Interviews interviewHeader) ]
            , List.map
                (\interview ->
                    cardMaker shared.device (C.Interview interview) (contentList shared interview)
                )
                [ sigmaNutritionRadio
                , markBellsPowerProject
                , foolproofMastery
                , ketoGeeksPodcast
                , legendaryLifePodcast
                , muscleMemoirsPodcast
                , fitAndFurious
                , strenuousLifePodcast
                , drShawnBakerPodcast
                ]
            ]


contentList : Shared.Model -> Interview -> List (Element msg)
contentList shared interview =
    let
        image : ElementSize -> Element msg
        image size =
            el
                [ alignLeft
                , alignTop
                , paddingEach
                    { top = 0
                    , right = 8
                    , bottom = 0
                    , left = 0
                    }
                ]
            <|
                imageSquareMaker shared.device (imagePathMaker M.Interviews interview.interviewImage) True size

        imageMaker : Element msg
        imageMaker =
            case ( shared.device.class, shared.device.orientation ) of
                ( Phone, Portrait ) ->
                    none

                ( Tablet, Portrait ) ->
                    none

                _ ->
                    image Big
    in
    [ detailFormat row
        [ imageMaker
        , detailFormat column
            [ socialMaker interview.interviewSocial interview.interviewSocial
            , detailTitleMaker TextLightGrey "Appearances:"
            , appearanceMaker shared interview
            ]
        ]
    ]


appearanceMaker : Shared.Model -> Interview -> Element msg
appearanceMaker shared interview =
    detailFormat column
        [ listMaker2 (makeAppearance shared) interview.interviewAppearances ]


makeAppearance : Shared.Model -> Appearance -> Int -> Element msg
makeAppearance shared appearanceEntry index =
    detailFormat row
        [ listCounter index
        , detailFormat column
            [ episodeMaker appearanceEntry
            , experienceMaker shared appearanceEntry
            , dateMaker appearanceEntry
            , subjectMaker appearanceEntry
            ]
        ]


episodeMaker : Appearance -> Element msg
episodeMaker appearanceEntry =
    newTabLink
        [ width fill ]
        { url = appearanceEntry.appearanceLink
        , label = detailTitleLinkWide TextLightOrange ("#" ++ appearanceEntry.appearanceEpisode ++ ": " ++ appearanceEntry.appearanceTitle)
        }


experienceMaker : Shared.Model -> Appearance -> Element msg
experienceMaker shared appearanceEntry =
    detailFormat row
        [ el
            (case ( shared.device.class, shared.device.orientation ) of
                ( Phone, Portrait ) ->
                    []

                ( Tablet, Portrait ) ->
                    []

                _ ->
                    if not shared.isNavbarExpanded then
                        [ tooltip IsLeft
                            "This represents the pleasantness of the host."
                        ]

                    else
                        []
            )
          <|
            detailTitleMaker TextLightGrey "Pleasantness:"
        , barPadding
            [ barMaker shared getExperienceTooltip appearanceEntry.appearanceExperience ]
        ]


dateMaker : Appearance -> Element msg
dateMaker appearanceEntry =
    detailFormat row
        [ detailTitleMaker TextLightGrey "Published:"
        , detailBodyMaker TextLightGrey (text appearanceEntry.appearanceYear)
        ]


subjectMaker : Appearance -> Element msg
subjectMaker appearanceEntry =
    detailFormat column
        [ detailFormatEl <| detailTitleMaker TextLightGrey "Subjects: "
        , detailFormat column [ listMaker makeSubject appearanceEntry.appearanceSubjects ]
        ]


makeSubject : Subjects -> Element msg
makeSubject subjects =
    listItem TextLightGrey subjects.subject


getExperienceTooltip : Int -> String
getExperienceTooltip num =
    case num of
        0 ->
            "Nightmare. Complete fucking cunt."

        1 ->
            "Toxic. Deliberately malicious."

        2 ->
            "Hostile. Consistently disruptive."

        3 ->
            "Belligerent. Consistently disrespectful."

        4 ->
            "Uncivil. Frequently dismissive."

        5 ->
            "Neutral. Unremarkable social interaction."

        6 ->
            "Civil. Slightly considerate."

        7 ->
            "Pleasant. Genuinely respectful."

        8 ->
            "Very kind. Consistently supportive."

        9 ->
            "Compassionate. Went out of their way."

        10 ->
            "Absolute angel. Perfectly empathetic."

        _ ->
            "Behavior level out of expected range."
