module Services.Helpers exposing (..)

import Browser
import Config.CardFormat exposing (..)
import Config.Colour exposing (..)
import Config.Format 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 exposing (Html, a, text)
import Html.Attributes as H exposing (href, style)
import Layouts
import Page exposing (Page)
import Route exposing (Route)
import Services.Types exposing (..)
import Shared
import View exposing (View)


serviceMaker : Service -> Element msg
serviceMaker service =
    row
        topLevelBox
        [ cardImageMaker (serviceImage service) ""
        , cardMaker
            [ cardTitleMaker (serviceTitle service)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ rateMaker service
                        , descriptionMaker service
                        , offeringMaker service
                        ]
                    ]
                ]
            ]
        ]


serviceMakerMobile : Service -> Element msg
serviceMakerMobile service =
    row
        topLevelBox
        [ column [] []
        , cardMaker
            [ cardTitleMaker (serviceTitle service)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ row [spacing 10] [ cardImageMakerMobile (serviceImage service) "", rateMaker service ]
                        , descriptionMaker service
                        , offeringMaker service
                        ]
                    ]
                ]
            ]
        ]


emailLink : List (Html msg) -> Html msg
emailLink =
    a [ href "mailto:nick@upRootNutrition.com?subject=Hello&body=%20" ]


serviceImage : Service -> { src : String, description : String }
serviceImage service =
    { src = "services/" ++ service.serviceImage ++ ".png"
    , description = service.serviceName
    }


serviceTitle : Service -> String
serviceTitle service =
    service.serviceName


serviceWidth =
    width <| px 45


rateMaker : Service -> Element msg
rateMaker service =
    row
        (paragraphBoldFormat
            ++ [ F.size 18
               , E.width fill
               ]
        )
        [ column
            [ alignTop
            , serviceWidth
            ]
            [ E.text "Rate:"
            ]
        , column
            [ E.width fill
            , alignLeft
            ]
            [ paragraph [ F.regular ]
                [ el [ F.color colourTheme.textLightOrange ] <|
                    E.text service.serviceRate
                ]
            ]
        ]


descriptionMaker : Service -> Element msg
descriptionMaker service =
    row paragraphBoldFormat
        [ column
            [ alignTop
            , width <| px 80
            ]
            [ E.text "Offerings:"
            ]
        ]


offeringMaker : Service -> Element msg
offeringMaker service =
    column
        [ spacing 8
        , width fill
        , paddingEach
            { top = 0
            , right = 0
            , bottom = 0
            , left = 35
            }
        ]
    <|
        List.map2 (\x y -> makeDescription x)
            service.serviceDescription
            (List.range 1 (List.length service.serviceDescription))


makeDescription : Description -> Element msg
makeDescription description =
    column
        (paragraphAlignLeft
            ++ [ spacing 8
               , width fill
               ]
        )
        [ paragraph [ F.regular ]
            [ E.text ("‣ " ++ description.point) ]
        ]
