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

import Browser.Dom as Dom
import Config.Colour as T exposing (..)
import Config.Format as O exposing (..)
import Config.Identity as I exposing (..)
import Config.Response exposing (..)
import Config.Viewport exposing (..)
import Donate.Helpers exposing (..)
import Donate.Methods.Cardano exposing (donateCardano)
import Donate.Methods.KoFi exposing (donateKoFi)
import Donate.Methods.LiberaPay exposing (donateLiberaPay)
import Donate.Methods.Merch exposing (donateMerch)
import Donate.Methods.Patreon exposing (donatePatreon)
import Donate.Methods.PayPal exposing (donatePayPal)
import Donate.Methods.Stripe exposing (donateStripe)
import Donate.Methods.YouTube exposing (donateYouTube)
import Donate.Types exposing (..)
import Effect exposing (Effect)
import Element as E exposing (..)
import Element.Background as B exposing (..)
import Element.Border as D exposing (..)
import Element.Font as F
import Headers.Helpers exposing (headerMaker)
import Headers.Pages.Donate exposing (donateHeader)
import Html.Attributes as H exposing (style)
import Layouts
import Page exposing (Page)
import Route exposing (Route)
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.pageDonate ++ " ( )"
    , attributes = []
    , element = donateContainer shared.device
    }


donateContainer : Device -> Element msg
donateContainer device =
    topLevelContainer (donateList device)


donateList : Device -> Element msg
donateList device =
    column
        (case ( device.class, device.orientation ) of
            _ ->
                pageListDesktop
        )
    <|
        List.concat
            [ List.map headerMaker
                [ donateHeader ]
            , (case ( device.class, device.orientation ) of
                ( Phone, Portrait ) ->
                    List.map donateMakerMobile

                ( Tablet, Portrait ) ->
                    List.map donateMakerMobile

                _ ->
                    List.map donateMaker
              )
                [ donateLiberaPay
                , donateStripe
                , donatePatreon
                , donateCardano
                , donateKoFi
                , donateYouTube
                , donateMerch
                ]
            ]
