module Debate.Cuckery.Helpers exposing (..)

import Config.CardFormat exposing (..)
import Config.Colour exposing (..)
import Config.Format exposing (..)
import Debate.Cuckery.CuckList.AdamSinger exposing (cuckAdamSinger)
import Debate.Cuckery.CuckList.AmberOHearn exposing (cuckAmberOHearn)
import Debate.Cuckery.CuckList.AnnChilders exposing (cuckAnnChilders)
import Debate.Cuckery.CuckList.AnthonyGustin exposing (cuckAnthonyGustin)
import Debate.Cuckery.CuckList.AshwaniGarg exposing (cuckAshwaniGarg)
import Debate.Cuckery.CuckList.AustinHerbert exposing (cuckAustinHerbert)
import Debate.Cuckery.CuckList.BartKay exposing (cuckBartKay)
import Debate.Cuckery.CuckList.BenBikman exposing (cuckBenBikman)
import Debate.Cuckery.CuckList.BennyMalone exposing (cuckBennyMalone)
import Debate.Cuckery.CuckList.BradCampbell exposing (cuckBradCampbell)
import Debate.Cuckery.CuckList.BradCohn exposing (cuckBradCohn)
import Debate.Cuckery.CuckList.BradMarshall exposing (cuckBradMarshall)
import Debate.Cuckery.CuckList.BretWeinstein exposing (cuckBretWeinstein)
import Debate.Cuckery.CuckList.BrianKerley exposing (cuckBrianKerley)
import Debate.Cuckery.CuckList.CarnivoreAurelius exposing (cuckCarnivoreAurelius)
import Debate.Cuckery.CuckList.CateShanahan exposing (cuckCateShanahan)
import Debate.Cuckery.CuckList.ChrisBoettcher exposing (cuckChrisBoettcher)
import Debate.Cuckery.CuckList.ClaraAboel exposing (cuckClaraAboel)
import Debate.Cuckery.CuckList.CliffHarvey exposing (cuckCliffHarvey)
import Debate.Cuckery.CuckList.DaveFeldman exposing (cuckDaveFeldman)
import Debate.Cuckery.CuckList.DavidDiamond exposing (cuckDavidDiamond)
import Debate.Cuckery.CuckList.DavidGornoski exposing (cuckDavidGornoski)
import Debate.Cuckery.CuckList.DianaRodgers exposing (cuckDianaRodgers)
import Debate.Cuckery.CuckList.EdwardGoeke exposing (cuckEdwardGoeke)
import Debate.Cuckery.CuckList.ElieJarrouge exposing (cuckElieJarrouge)
import Debate.Cuckery.CuckList.GaryBrecka exposing (cuckGaryBrecka)
import Debate.Cuckery.CuckList.GaryFettke exposing (cuckGaryFettke)
import Debate.Cuckery.CuckList.GaryTaubes exposing (cuckGaryTaubes)
import Debate.Cuckery.CuckList.GeorgeMartin exposing (cuckGeorgeMartin)
import Debate.Cuckery.CuckList.GuyAustin exposing (cuckGuyAustin)
import Debate.Cuckery.CuckList.IvorCummins exposing (cuckIvorCummins)
import Debate.Cuckery.CuckList.JakeMey exposing (cuckJakeMey)
import Debate.Cuckery.CuckList.JamesDiNicolantonio exposing (cuckJamesDiNicolantonio)
import Debate.Cuckery.CuckList.JosephEverett exposing (cuckJosephEverett)
import Debate.Cuckery.CuckList.JustinMares exposing (cuckJustinMares)
import Debate.Cuckery.CuckList.KaitMalthaner exposing (cuckKaitMalthaner)
import Debate.Cuckery.CuckList.KemMinnick exposing (cuckKemMinnick)
import Debate.Cuckery.CuckList.KenBerry exposing (cuckKenBerry)
import Debate.Cuckery.CuckList.KevinStock exposing (cuckKevinStock)
import Debate.Cuckery.CuckList.KyleMamounis exposing (cuckKyleMamounis)
import Debate.Cuckery.CuckList.MarkSisson exposing (cuckMarkSisson)
import Debate.Cuckery.CuckList.MartyKendall exposing (cuckMartyKendall)
import Debate.Cuckery.CuckList.MaxLugavere exposing (cuckMaxLugavere)
import Debate.Cuckery.CuckList.MichaelKummer exposing (cuckMichaelKummer)
import Debate.Cuckery.CuckList.MichaelManderville exposing (cuckMichaelManderville)
import Debate.Cuckery.CuckList.MikeMutzel exposing (cuckMikeMutzel)
import Debate.Cuckery.CuckList.MikeSweeney exposing (cuckMikeSweeney)
import Debate.Cuckery.CuckList.NickEggleton exposing (cuckNickEggleton)
import Debate.Cuckery.CuckList.NinaTeicholz exposing (cuckNinaTeicholz)
import Debate.Cuckery.CuckList.NorstrongChris exposing (cuckNorstrongChris)
import Debate.Cuckery.CuckList.PaulMason exposing (cuckPaulMason)
import Debate.Cuckery.CuckList.PaulSaladino exposing (cuckPaulSaladino)
import Debate.Cuckery.CuckList.PhilipOvadia exposing (cuckPhilipOvadia)
import Debate.Cuckery.CuckList.PhilippeStephenson exposing (cuckPhilippeStephenson)
import Debate.Cuckery.CuckList.RalphNapolitano exposing (cuckRalphNapolitano)
import Debate.Cuckery.CuckList.RaphaelSirtoli exposing (cuckRaphaelSirtoli)
import Debate.Cuckery.CuckList.RobMeijer exposing (cuckRobMeijer)
import Debate.Cuckery.CuckList.RobbWolf exposing (cuckRobbWolf)
import Debate.Cuckery.CuckList.SebastianRamirez exposing (cuckSebastianRamirez)
import Debate.Cuckery.CuckList.SimonGoddek exposing (cuckSimonGoddek)
import Debate.Cuckery.CuckList.TravisStatham exposing (cuckTravisStatham)
import Debate.Cuckery.CuckList.TristanHaggard exposing (cuckTristanHaggard)
import Debate.Cuckery.CuckList.TroKalayjian exposing (cuckTroKalayjian)
import Debate.Cuckery.CuckList.TuckerGoodrich exposing (cuckTuckerGoodrich)
import Debate.Cuckery.CuckList.ZoeHarcombe exposing (cuckZoeHarcombe)
import Debate.Cuckery.CuckList.ZsofiaClemens exposing (cuckZsofiaClemens)
import Debate.Cuckery.Types exposing (..)
import Effect exposing (Effect)
import Element as E exposing (..)
import Element.Background as B exposing (..)
import Element.Border as D
import Element.Font as F
import Html.Attributes as H exposing (style)
import Layouts
import Page exposing (Page)
import Route exposing (Route)
import Shared
import View exposing (View)


cuckMaker : Cuck -> Element msg
cuckMaker cuck =
    row
        topLevelBox
        [ cardImageMaker (cuckImage cuck) (cuckSocial cuck)
        , cardMaker
            [ cardTitleMaker (cuckTitle cuck)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ socialMaker cuck
                        , dodgeTitle cuck
                        , dodgeMaker cuck
                        ]
                    ]
                ]
            ]
        ]


cuckMakerMobile : Cuck -> Element msg
cuckMakerMobile cuck =
    column
        topLevelBox
        [ column [] []
        , cardMaker
            [ cardTitleMaker (cuckTitle cuck)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ column
                            [ alignTop
                            , centerX
                            , alignLeft
                            , spacing 3
                            ]
                            [ row [ spacing 10 ]
                                [ cardImageMakerMobile (cuckImage cuck) (cuckSocial cuck)
                                , socialMaker cuck
                                ]
                            , dodgeTitle cuck
                            , dodgeMaker cuck
                            ]
                        ]
                    ]
                ]
            ]
        ]


cuckImage :
    Cuck
    ->
        { src : String
        , description : String
        }
cuckImage cuck =
    { src = "cucks/" ++ cuck.cuckImage ++ "/" ++ cuck.cuckImage ++ ".png"
    , description = cuck.cuckName
    }


cuckTitle : Cuck -> String
cuckTitle cuck =
    cuck.cuckName


cuckSocial : Cuck -> String
cuckSocial cuck =
    cuck.cuckSocial


dodgeMaker : Cuck -> Element msg
dodgeMaker cuck =
    column
        [ spacing 10
        , width fill
        ]
    <|
        List.map2 (\x y -> makeDodge x y)
            cuck.cuckDodges
            (List.range 1 (List.length cuck.cuckDodges))


socialMaker : Cuck -> Element msg
socialMaker cuck =
    paragraph
        (paragraphBoldFormat
            ++ [ F.size 18
               , spacing 8
               ]
        )
        [ text "Social: "
        , paragraphLinkFormat
            { url = cuck.cuckSocial
            , label = transitionHighlightedLinkHover <| text (formatCuckSocial cuck.cuckSocial)
            }
        ]


dodgeTitle : Cuck -> Element msg
dodgeTitle cuck =
    paragraph
        (paragraphBoldFormat
            ++ [ F.size 18
               ]
        )
        [ text "Dodges: " ]


makeDodge : Dodge -> Int -> Element msg
makeDodge dodgeEntry index =
    column
        (paragraphAlignLeft
            ++ [ spacing 8
               , width fill
               ]
        )
        [ row
            [ width fill
            , paddingEach
                { top = 0
                , right = 0
                , bottom = 0
                , left = 35
                }
            ]
            [ column
                (paragraphFormat
                    ++ [ F.size 18
                       , alignTop
                       , alignRight
                       , F.alignRight
                       ]
                )
                [ text (String.fromInt index ++ ". ") ]
            , column
                [ spacing 3
                , width fill
                ]
                [ circumstanceMaker dodgeEntry
                , column
                    [ spacing 3
                    , width fill
                    ]
                    [ propositionMaker dodgeEntry
                    , reductioMaker dodgeEntry
                    , attitudeMaker dodgeEntry
                    , reasonMaker dodgeEntry
                    ]
                ]
            ]
        ]


dodgeWidth =
    width <| px 93


formatProposition : String -> String
formatProposition proposition =
    if proposition == "N/A" then
        proposition

    else
        "\"" ++ proposition ++ "\""


dodgeCounter : Int -> Element msg
dodgeCounter index =
    column
        (paragraphFormat
            ++ [ F.size 18
               ]
        )
        [ text (String.fromInt index ++ ". ") ]


circumstanceMaker : Dodge -> Element msg
circumstanceMaker dodgeEntry =
    column
        [ width fill
        ]
        [ paragraphLinkFormat
            { url = dodgeEntry.dodgeLink
            , label =
                row [ F.size 18 ]
                    [ column [ width fill ]
                        [ paragraph []
                            [ transitionHighlightedLinkHover <|
                                text
                                    (case dodgeEntry.dodgeDescription of
                                        NoReply ->
                                            "Debate invitation extended with no response"

                                        RanAway ->
                                            "Engaged in written debate and ran away when cornered"

                                        GhostedMe ->
                                            "Debate invitation accepted with no follow-up"

                                        OutrightNo ->
                                            "Debate invitation declined"

                                        InTooDeep ->
                                            "Debate invitation accepted and subsequently retracted"

                                        KillScreen ->
                                            "All further debate invitations preemptively declined"

                                        VagueGesture ->
                                            "Chose to gesture vaguely instead of engaging"
                                    )
                            , paragraph [ F.color colourTheme.textLightGrey ] [ text "." ]
                            , column
                                [ spacing 5
                                , F.size 12
                                ]
                                (List.indexedMap
                                    (\index2 link ->
                                        newTabLink
                                            [ paddingEach
                                                { top = 0
                                                , right = 0
                                                , bottom = 0
                                                , left = 5
                                                }
                                            ]
                                            { url = link
                                            , label =
                                                row [ moveUp 5 ]
                                                    [ transitionHighlightedLinkHover <| text (String.fromInt (index2 + 1))
                                                    , text ", " |> el [ F.color colourTheme.textLightGrey ]
                                                    ]
                                            }
                                    )
                                    dodgeEntry.dodgeReceipts
                                )
                            ]
                        ]
                    ]
            }
        ]


propositionMaker : Dodge -> Element msg
propositionMaker dodgeEntry =
    row paragraphBoldFormat
        [ paragraph
            [ alignTop
            , dodgeWidth
            ]
            [ text "Proposition:"
            ]
        , paragraph
            [ E.width fill
            , alignLeft
            ]
            [ paragraph [ F.regular ] [ text (formatProposition dodgeEntry.dodgeProposition) ]
            ]
        ]


attitudeMaker : Dodge -> Element msg
attitudeMaker dodgeEntry =
    row (paragraphBoldFormat ++ [ width fill ])
        [ paragraph
            [ alignTop
            , dodgeWidth
            ]
            [ text "Attitude:"
            ]
        , paragraph
            [ E.width fill
            , alignLeft
            ]
            [ case dodgeEntry.dodgeNicksDoxasticState of
                Nothing ->
                    paragraph [ F.regular ] [ text "I don't form a doxastic state." ]

                Just Belief ->
                    paragraph [ F.regular ]
                        [ text "I lean more toward "
                        , el [ F.bold ] (text "TRUE")
                        , text " than false."
                        ]

                Just Disbelief ->
                    paragraph [ F.regular ]
                        [ text "I lean more toward "
                        , text "FALSE" |> el [ F.bold ]
                        , text " than true."
                        ]

                Just Agnostic ->
                    el [ F.regular ] (text "I don't form beliefs about this proposition.")
            ]
        ]


reductioMaker : Dodge -> Element msg
reductioMaker dodgeEntry =
    case dodgeEntry.dodgeFallacy of
        Nothing ->
            none

        Just fallacy ->
            case fallacy of
                SpecificFallacy str ->
                    if String.isEmpty str then
                        none

                    else
                        displayFallacy str

                AppealToNature ->
                    displayFallacy "Appeal to Nature"

                AppealToTradition ->
                    displayFallacy "Appeal to Tradition"

                AppealToIgnorance ->
                    displayFallacy "Appeal to Ignorance"

                AppealFromIncredulity ->
                    displayFallacy "Appeal from Incredulity"

                RedHerring ->
                    displayFallacy "Red Herring"

                BeggingTheQuestion ->
                    displayFallacy "Begging the Question"

                Strawman ->
                    displayFallacy "Strawman"

                Equivocation ->
                    displayFallacy "Equivocation"

                GeneticFallacy ->
                    displayFallacy "Genetic Fallacy"

                MotteAndBailey ->
                    displayFallacy "Motte and Bailey"


reasonMaker : Dodge -> Element msg
reasonMaker dodgeEntry =
    row (paragraphBoldFormat ++ [ width fill ])
        [ paragraph
            [ alignTop
            , dodgeWidth
            ]
            [ text "Reason:"
            ]
        , paragraph [ F.regular ]
            [ text <|
                case dodgeEntry.dodgeNicksDoxasticReason of
                    NoProp ->
                        "There is no proposition to evaluate."

                    VagueProp ->
                        "The proposition is too vague to evaluate."

                    SpecificPropReason str ->
                        str
            ]
        ]


displayFallacy : String -> Element msg
displayFallacy fallacyText =
    row paragraphBoldFormat
        [ paragraph
            [ alignTop
            , dodgeWidth
            ]
            [ text "Fallacy:"
            ]
        , paragraph
            [ E.width fill
            , alignLeft
            ]
            [ paragraph [ F.regular ]
                [ text fallacyText ]
            ]
        ]


cuckList =
    [ cuckAdamSinger
    , cuckAmberOHearn
    , cuckAnnChilders
    , cuckAnthonyGustin
    , cuckAshwaniGarg
    , cuckAustinHerbert
    , cuckBartKay
    , cuckBenBikman
    , cuckBennyMalone
    , cuckBradCampbell
    , cuckBradCohn
    , cuckBradMarshall
    , cuckBretWeinstein
    , cuckBrianKerley
    , cuckCarnivoreAurelius
    , cuckCateShanahan
    , cuckChrisBoettcher
    , cuckClaraAboel
    , cuckCliffHarvey
    , cuckDaveFeldman
    , cuckDavidDiamond
    , cuckDavidGornoski
    , cuckDianaRodgers
    , cuckEdwardGoeke
    , cuckElieJarrouge
    , cuckGaryBrecka
    , cuckGaryFettke
    , cuckGaryTaubes
    , cuckGeorgeMartin
    , cuckGuyAustin
    , cuckIvorCummins
    , cuckJakeMey
    , cuckJamesDiNicolantonio
    , cuckJosephEverett
    , cuckJustinMares
    , cuckKaitMalthaner
    , cuckKemMinnick
    , cuckKenBerry
    , cuckKevinStock
    , cuckKyleMamounis
    , cuckMarkSisson
    , cuckMartyKendall
    , cuckMaxLugavere
    , cuckMichaelKummer
    , cuckMichaelManderville
    , cuckMikeMutzel
    , cuckMikeSweeney
    , cuckNickEggleton
    , cuckNinaTeicholz
    , cuckNorstrongChris
    , cuckPaulMason
    , cuckPaulSaladino
    , cuckPhilipOvadia
    , cuckPhilippeStephenson
    , cuckRalphNapolitano
    , cuckRaphaelSirtoli
    , cuckRobbWolf
    , cuckRobMeijer
    , cuckSebastianRamirez
    , cuckSimonGoddek
    , cuckTravisStatham
    , cuckTristanHaggard
    , cuckTroKalayjian
    , cuckTuckerGoodrich
    , cuckZoeHarcombe
    , cuckZsofiaClemens
    ]


cuckListNumber : Int
cuckListNumber =
    List.length cuckList
