module Pages.Debate exposing
    ( Model
    , Msg
    , debateArguments
    , debateCuckList
    , debateGibberish
    , page
    )

import Config.Data.Identity
    exposing
        ( pageNames
        )
import Config.Helpers.Cards.Inner.Helpers exposing (detailBodyLink, detailBodyMaker, detailFormat, detailSpacing, detailTitleMaker)
import Config.Helpers.Cards.Outer.Helpers exposing (cardMaker)
import Config.Helpers.Cards.Outer.Types as C
import Config.Helpers.Converters exposing (formatName)
import Config.Helpers.Format
    exposing
        ( headerFontSizeSmall
        , paragraphFontSize
        , paragraphSpacing
        )
import Config.Helpers.Headers.Helpers exposing (..)
import Config.Helpers.Headers.Records exposing (debateHeader)
import Config.Helpers.Headers.Types as R exposing (..)
import Config.Helpers.ImageFolders as M exposing (..)
import Config.Helpers.Response
    exposing
        ( pageList
        , topLevelContainer
        )
import Config.Helpers.ServiceFormat exposing (chunkMaker)
import Config.Helpers.Viewport exposing (resetViewport)
import Config.Pages.Debate.Arguments.List exposing (argumentList)
import Config.Pages.Debate.Cuckery.List exposing (cuckList)
import Config.Pages.Debate.Gibberish.List exposing (gibberishList)
import Config.Pages.Debate.Types exposing (..)
import Config.Style.Colour.Helpers as T exposing (ThemeColor(..), colourTheme)
import Config.Style.Glow
    exposing
        ( glowDeepDarkGrey
        , glowDeepDarkOrange
        )
import Config.Style.Images exposing (imageSquareMaker)
import Config.Style.Transitions
    exposing
        ( transitionStyleSlow
        )
import Effect exposing (Effect)
import Element as E exposing (..)
import Element.Background as B
import Element.Border as D
import Element.Font as F
import Html exposing (label)
import Html.Attributes as H
import Layouts
import Page exposing (Page)
import Route exposing (Route)
import Route.Path as Path
import Shared exposing (..)
import Task
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.pageDebate
    , attributes = []
    , element = debateContainer shared.device
    }


debateContainer : Device -> Element msg
debateContainer device =
    topLevelContainer (debateList device)


debateList : Device -> Element msg
debateList device =
    column
        (case ( device.class, device.orientation ) of
            _ ->
                pageList device
        )
    <|
        List.concat
            [ [ headerMaker (R.Debate debateHeader) ]
            , List.map
                (\debate ->
                    cardMaker device (C.Debate debate) (contentList device debate)
                )
                [ debateArguments
                , debateCuckList
                , debateGibberish
                ]
            ]


contentList : Device -> Debate -> List (Element msg)
contentList device debate =
    [ descriptionMaker device debate ]


descriptionMaker : Device -> Debate -> Element msg
descriptionMaker device debate =
    let
        image : String -> Element msg
        image size =
            el
                [ alignLeft
                , paddingEach
                    { top = 0
                    , right = 10
                    , bottom = 0
                    , left = 0
                    }
                ]
            <|
                imageSquareMaker device (imagePathMaker M.Debate debate.debateImage) True size
    in
    detailFormat row
        [ case ( device.class, device.orientation ) of
            ( Phone, Portrait ) ->
                none

            ( Tablet, Portrait ) ->
                none

            _ ->
                image "Fatty"
        , detailFormat column
            [ inferenceMaker debate
            , detailBodyMaker TextLightGrey
                (text debate.debateDescription)
            ]
        ]


inferenceMaker : Debate -> Element msg
inferenceMaker debate =
    detailFormat row
        [ detailTitleMaker TextLightOrange
            (case debate.debateTitle of
                "Arguments" ->
                    "Inferences:"

                "Cucklist" ->
                    "Cucks:"

                "Gibberish" ->
                    "Gibberations:"

                _ ->
                    ""
            )
        , detailBodyMaker TextLightGrey
            (text
                (String.fromInt debate.debateCount)
            )
        ]


debateArguments : Debate
debateArguments =
    let
        name =
            "Arguments"
    in
    { debateTitle = name
    , debateLink = Path.toString Path.Debate_Arguments
    , debateCount = List.length argumentList
    , debateImage = formatName name
    , isNewTabLink = False
    , debateDescription = "This page features arguments that I hold to be sound, though with varying degrees of confidence. I'm open to hearing all challenges, as I am ready to engage with any substantive critiques and defend any argument listed. I have additionally included a confidence meter with each argument to give readers a clearer understanding of how strongly I hold to the argument."
    }


debateCuckList : Debate
debateCuckList =
    let
        name =
            "Cucklist"
    in
    { debateTitle = name
    , debateLink = Path.toString Path.Debate_Cucklist
    , debateCount = List.length cuckList
    , debateImage = formatName name
    , isNewTabLink = False
    , debateDescription = "This page features a list of complete fucking morons who wrote cheques with their mouths that their asses ultimately couldn't cash. Each person included in this list has dodged debating me in some way, shape, or form. Whether it's simply ignoring invitations, or outright refusing to engage, or agreeing to debate and then subsequently withdrawing. All such instances are catalogued here."
    }


debateGibberish : Debate
debateGibberish =
    let
        name =
            "Gibberish"
    in
    { debateTitle = name
    , debateLink = Path.toString Path.Debate_Gibberish
    , debateCount = List.length gibberishList
    , debateImage = formatName name
    , isNewTabLink = False
    , debateDescription = "This page is specifically for terms and ostensible concepts that I don't have a good reason to believe are understandable from at least one viewpoint. If the clarification of a philosophical term is unsatisfying or unsuccessful, and my interlocutor has exhausted all means of rendering the concept to me, the term ends up here until someone explains to me what the fuck it even means."
    }
