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

import Config.Data.Identity
    exposing
        ( pageNames
        )
import Config.Data.ImageFolders as M
    exposing
        ( ImageFolder(..)
        , imagePathMaker
        )
import Config.Helpers.Cards.Inner.Text
    exposing
        ( detailBodyLink
        , detailBodyMaker
        , detailFormat
        , detailSpacing
        , detailTitleMaker
        )
import Config.Helpers.Cards.Outer.Helpers exposing (cardMaker)
import Config.Helpers.Cards.Outer.Types as C exposing (Cardable(..))
import Config.Helpers.Converters exposing (formatName)
import Config.Helpers.Headers.Helpers exposing (headerMaker)
import Config.Helpers.Headers.Records exposing (debateHeader)
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.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 (Debate)
import Config.Style.Colour.Helpers as T
    exposing
        ( ThemeColor(..)
        , colourTheme
        )
import Config.Style.Images
    exposing
        ( ElementSize(..)
        , imageSquareMaker
        )
import Effect exposing (Effect)
import Element as E
    exposing
        ( Device
        , DeviceClass(..)
        , Element
        , Orientation(..)
        , alignLeft
        , column
        , el
        , none
        , paddingEach
        , row
        , text
        )
import Layouts
import Page exposing (Page)
import Route exposing (Route)
import Route.Path as Path
import Shared exposing (Model)
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 : ElementSize -> 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 Big
        , 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."
    }



-- if you decide to readd this page, move Gibberish.elm from src/Disabled back to src/Pages/Debate
-- 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."
--     }
