module Contact.Helpers exposing (..)

import Config.CardFormat exposing (..)
import Config.Colour exposing (..)
import Config.Format exposing (..)
import Config.StrengthBar exposing (..)
import Config.ToolTip exposing (..)
import Contact.Methods.Discord exposing (contactDiscord)
import Contact.Types exposing (..)
import Effect exposing (Effect)
import Element as E exposing (..)
import Element.Background as B exposing (..)
import Element.Border as D
import Element.Events exposing (onClick)
import Element.Font as F
import Headers.Types exposing (..)
import Html.Attributes as H exposing (style)
import Html.Events exposing (onMouseOver)
import Interviews.Types exposing (..)
import Layouts
import Page exposing (Page)
import Products.Types exposing (..)
import Route exposing (Route)
import Shared
import View exposing (View)


contactMaker : Contact -> Element msg
contactMaker contact =
    row
        topLevelBox
        [ cardMaker
            [ cardTitleMaker (contactTitle contact)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ linkMaker contact
                        , descriptionMaker contact
                        ]
                    ]
                ]
            ]
        ]


contactImage :
    Contact
    ->
        { src : String
        , description : String
        }
contactImage contact =
    { src = "contact/" ++ contact.contactImage ++ ".png"
    , description = contact.contactName
    }


contactTitle : Contact -> String
contactTitle contact =
    contact.contactName


descriptionMaker : Contact -> Element msg
descriptionMaker contact =
    column
        [ width fill
        , height fill
        ]
        [ paragraph [ width fill, F.size 15, spacing 10 ] <|
            List.map makeDescription
                contact.contactEntry
        ]


makeDescription : Method -> Element msg
makeDescription method =
    paragraph
        [ F.regular
        , F.alignLeft
        ]
        [ paragraph
            [ F.color colourTheme.textLightGrey
            ]
            [ text method.contactInstructions
            ]
        ]


linkMaker : Contact -> Element msg
linkMaker contact =
    paragraph
        (paragraphBoldFormat
            ++ [ F.size 18
               , spacing 8
               ]
        )
        [ paragraphLinkFormat
            { url = contact.contactLink
            , label = transitionHighlightedLinkHover <| text contact.contactLinkLabel
            }
        ]


instructionMaker : Element msg
instructionMaker =
    row
        topLevelBox
        [ cardMaker
            [ cardTitleMaker "CONTACT"
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ cardSubTitleMaker
                            [ instructionBody ]
                        ]
                    ]
                ]
            ]
        ]


instructionBody : Element msg
instructionBody =
    column
        [ spacing 10
        , paddingEach
            { top = 10
            , bottom = 0
            , left = 0
            , right = 0
            }
        ]
        [ paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "The following terms may seem unreasonable to some, but after years on a large platform, I've learned the importance of filtering the criticisms I receive. Most feedback I receive is just vague gesturing and lacks substance, making some sort of quality filter essential. Thank you for your patience and understanding." ]
        , paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "Please keep in mind that any failure to comply with the following terms and conditions will forfeit your access to my time and attention. I ask that you respect my time and read these terms carefully. You are the one requesting an audience with me, and my time is mine to donate as I see fit. If you wish to submit your criticisms, you must do so on my terms, following the rules and conditions that streamline the process for me." ]
        , paragraph
            (paragraphBoldFormat
                ++ [ F.center
                   , width fill
                   , paddingEach
                        { top = 10
                        , bottom = 10
                        , left = 0
                        , right = 0
                        }
                   ]
            )
            [ el
                [ F.color colourTheme.textLightOrange
                , F.size 18
                ]
              <|
                text "Terms and Conditions"
            ]
        , column [ spacing 10 ] <|
            List.indexedMap
                (\index term ->
                    row
                        [ spacing 10
                        , width fill
                        ]
                        [ column
                            [ width <| px 15
                            , alignTop
                            ]
                            [ el [ alignRight ] <| text (String.fromInt (index + 1) ++ ". ") ]
                        , column
                            [ spacing 10
                            , width fill
                            , alignRight
                            ]
                            [ paragraph
                                [ width fill
                                , F.size 16
                                , F.alignLeft
                                ]
                                term
                            ]
                        ]
                )
                termsAndConditions
        , paragraph
            (paragraphBoldFormat
                ++ [ F.center
                   , width fill
                   , paddingEach
                        { top = 10
                        , bottom = 10
                        , left = 0
                        , right = 0
                        }
                   ]
            )
            [ el
                [ F.color colourTheme.textLightOrange
                , F.size 18
                ]
              <|
                text "Additional Clarifications"
            ]
        , paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "• "
            , text "You are only allowed to post one criticism at a time in the "
            , newTabLink []
                { url = "https://discord.com/channels/692563032546476062/1301247050796634182"
                , label = el orangeFormat <| text "🔎┃criticism"
                }
            , text " channel. You may post an additional criticism only after the previous one has been addressed and resolved to my satisfaction. This policy aims to reduce spamming, rambling, and Gish galloping, and to encourage linear discourse."
            ]
        , paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "• ", text "You may or may not be asked to voice chat about your criticism. While your willingness to engage in voice chat is a necessary condition for submitting your criticism, it does not guarantee that a voice chat will be requested. If your initial criticism is clear and I agree with it, then no voice chat will be required." ]
        , paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "• ", text "You may or may not be asked to have your criticism formalized. While your willingness to have your criticism formalized is a necessary condition for submitting your criticism, it does not guarantee that a formalization will be requested. If your initial criticism is clear and I agree with it, then no formalization will be required." ]
        , paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "• "
            , text "If I find it necessary to access a text-based channel (for simple clarifying questions, for example), then either I or a moderator will open a new thread in the "
            , newTabLink []
                { url = "https://discord.com/channels/692563032546476062/1301247050796634182"
                , label = el orangeFormat <| text "🔎┃criticism"
                }
            , text " channel. There we can then engage in a text-based discussion and/or ping other users if needed."
            ]
        , paragraph
            (paragraphFormat
                ++ [ F.alignLeft
                   , width fill
                   ]
            )
            [ text "• ", text "I will only request that your criticism be formalized if I do not understand it and we have exhausted all other reasonable means of clarification. If formalization is requested, you will not need to do it yourself, as I recognize that not everyone understands formal logic. If formalization is requested and I am unavailable to assist you, you may ping the @Logic role, and another user may help you." ]
        ]


darkFormat : Attr decorative msg
darkFormat =
    F.color colourTheme.textDarkGrey


orangeFormat : List (Attr () msg)
orangeFormat =
    [ F.color colourTheme.textLightOrange
    , mouseOver [ F.color colourTheme.textDarkOrange ]
    , htmlAttribute <| style "transition" "all 0.1s ease-in-out"
    ]


rounding : Attribute msg
rounding =
    D.rounded 10


termsAndConditions : List (List (Element msg))
termsAndConditions =
    [ [ paragraph [ alignLeft ]
            [ text "You will register an account with "
            , newTabLink []
                { url = "https://discord.com/login"
                , label = el orangeFormat <| text "Discord"
                }
            , text " (if you haven't already)."
            ]
      ]
    , [ row [ alignLeft ]
            [ text "You will join the "
            , newTabLink []
                { url = "https://discord.com/invite/VzU8yCvYX8"
                , label = el orangeFormat <| text "upRootNutrition"
                }
            , text " Discord Server (if you haven't already)."
            ]
      ]
    , [ el [ alignLeft ] <| text "You will click the \"😃\" emoji to enter the server (if you haven't already)." ]
    , [ paragraph [ alignLeft ]
            [ text "You will locate the "
            , newTabLink []
                { url = "https://discord.com/channels/692563032546476062/826225570219687956"
                , label = el orangeFormat <| text "💻┃general"
                }
            , text " channel in General category."
            ]
      ]
    , [ row [ F.alignLeft, alignLeft ]
            [ paragraph [ alignLeft ]
                [ text "You will post exactly this in the "
                , newTabLink []
                    { url = "https://discord.com/channels/692563032546476062/826225570219687956"
                    , label = el orangeFormat <| text "💻┃general"
                    }
                , text " channel:"
                ]
            , column
                [ paddingEach
                    { top = 10
                    , bottom = 10
                    , left = 0
                    , right = 0
                    }
                , alignLeft
                ]
                [ paragraph
                    [ paddingEach
                        { top = 15
                        , bottom = 15
                        , left = 20
                        , right = 20
                        }
                    , B.color colourTheme.backgroundLightGrey
                    , rounding
                    , width fill
                    , spacing 8
                    ]
                    [ text "\"@Moderators I have a criticism for Nick.\""
                    ]
                ]
            ]
      ]
    , [ el [ alignLeft ] <| text "You will then receive the @Critic role." ]
    , [ paragraph [ alignLeft ]
            [ text "You will locate the "
            , newTabLink []
                { url = "https://discord.com/channels/692563032546476062/1301247050796634182"
                , label = el orangeFormat <| text "🔎┃criticism"
                }
            , text " channel in the General category."
            ]
      ]
    , [ paragraph [ alignLeft ]
            [ paragraph [ F.alignLeft ]
                [ text "You will post your criticism in the "
                , newTabLink []
                    { url = "https://discord.com/channels/692563032546476062/1301247050796634182"
                    , label = el orangeFormat <| text "🔎┃criticism"
                    }
                , text " channel with this exact format:"
                ]
            ]
      , column
            [ paddingEach
                { top = 10
                , bottom = 10
                , left = 0
                , right = 0
                }
            , alignLeft
            ]
            [ column
                [ paddingEach
                    { top = 15
                    , bottom = 15
                    , left = 20
                    , right = 20
                    }
                , B.color colourTheme.backgroundLightGrey
                , rounding
                , width fill
                , spacing 8
                ]
                [ text "\"Hello, <@191027366640877568>. I have a criticism for you."
                , row [ alignLeft ]
                    [ paragraph []
                        [ text "Proposition: "
                        , el [ darkFormat ] <| text "specify the exact proposition you are addressing."
                        ]
                    ]
                , row [ alignLeft ]
                    [ paragraph []
                        [ text "Link: "
                        , el [ darkFormat ] <| text "provide a url to the claim, with a timestamp if applicable."
                        ]
                    ]
                , row [ alignLeft ]
                    [ paragraph []
                        [ text "Reason for Error: "
                        , el [ darkFormat ] <| text "explain exactly why you believe this claim is in error."
                        ]
                    ]
                , row [ alignLeft ]
                    [ paragraph []
                        [ text "Suggested Correction (if any): "
                        , el [ darkFormat ] <| text "provide the corrected information or perspective."
                        ]
                    ]
                , row [ alignLeft ]
                    [ paragraph []
                        [ text "Additional Comments: "
                        , el [ darkFormat ] <| text "any other relevant thoughts or context."
                        , text "\""
                        ]
                    ]
                ]
            ]
      ]
    , [ el [ alignLeft ] <| text "You will not post additional criticisms until the last one has been resolved." ]
    , [ paragraph [ alignLeft ]
            [ text "You will not post anything other than criticisms in the "
            , newTabLink [ alignLeft ]
                { url = "https://discord.com/channels/692563032546476062/1301247050796634182"
                , label = el orangeFormat <| text "🔎┃criticism"
                }
            , text " channel."
            ]
      ]
    , [ el [ alignLeft ] <| text "You must be willing to converse over voice chat." ]
    , [ el [ alignLeft ] <| text "You must be willing to have your criticism formalized." ]
    ]
