module Products.Helpers exposing (..)

import Config.CardFormat exposing (..)
import Config.Colour exposing (..)
import Config.Format exposing (..)
import Config.StrengthBar exposing (..)
import Config.Style.Svgs exposing (nutriDexLogo)
import Config.ToolTip 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)


nutriDexMaker : NutriDex -> Element msg
nutriDexMaker nutridex =
    row
        topLevelBox
        [ cardMaker
            [ cardTitleMaker (nutriDexTitle nutridex)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ cardSubTitleMaker
                            [ featureList nutridex
                            , nutriDexBodyMaker
                            , nutriDexAdjustments
                            , column [ spacing 10 ]
                                [ nutriDexVitamins
                                , nutriDexFattyAcids
                                , nutriDexMinerals
                                , nutriDexAminoAcids
                                ]
                            , nutriDexReferences nutridex
                            ]
                        ]
                    ]
                ]
            ]
        ]


nutriDexMakerMobile : NutriDex -> Element msg
nutriDexMakerMobile nutridex =
    row
        topLevelBox
        [ cardMaker
            [ cardTitleMaker (nutriDexTitle nutridex)
            , cardFormatter
                [ cardContentSpacing
                    [ column
                        fieldSpacer
                        [ cardSubTitleMaker
                            [ featureListMobile nutridex
                            , nutriDexBodyMaker
                            , nutriDexAdjustments
                            , column [ spacing 10 ]
                                [ nutriDexVitamins
                                , nutriDexFattyAcids
                                , nutriDexMinerals
                                , nutriDexAminoAcids
                                ]
                            , nutriDexReferences nutridex
                            ]
                        ]
                    ]
                ]
            ]
        ]


nutriDexTitle : NutriDex -> String
nutriDexTitle nutridex =
    String.toUpper nutridex.nutriDexTitle


makeFeature : Features -> Element msg
makeFeature features =
    column
        [ E.width fill
        , alignLeft
        , paddingEach
            { top = 0
            , right = 0
            , bottom = 0
            , left = 8
            }
        ]
        [ row [ E.width fill ]
            [ column [ E.width fill ]
                [ paragraph [ F.regular, F.alignLeft ]
                    [ text "‣ ", el [ F.bold, F.color colourTheme.textLightOrange ] (text features.featureTitle), text features.feature ]
                ]
            ]
        ]


price : Element msg
price =
    newTabLink []
        { url = "https://the-nutrivore.myshopify.com/cart/31192710807615:1?channel=buy_button"
        , label =
            row
                [ F.center
                , paddingEach
                    { top = 3
                    , right = 0
                    , bottom = 0
                    , left = 0
                    }
                ]
                [ text "$19.99" ]
        }


featureList : NutriDex -> Element msg
featureList nutridex =
    column
        [ spacing 8
        , width fill
        , height fill
        , paddingEach
            { top = 10
            , bottom = 0
            , left = 0
            , right = 0
            }
        ]
        [ row
            [ spacing 20
            , width fill
            , height fill
            ]
            [ column
                [ spacing 20
                ]
                [ row
                    [ centerX
                    , E.width <| px 250
                    ]
                    [ html nutriDexLogo
                    ]
                , row
                    [ D.width 5
                    , D.rounded 25
                    , centerX
                    , D.color colourTheme.backgroundLightGrey
                    , B.color colourTheme.backgroundLightGrey
                    ]
                    [ row
                        [ B.color colourTheme.textDarkOrange
                        , D.rounded 30
                        , F.size 25
                        , F.bold
                        , paddingEach
                            { top = 10
                            , right = 25
                            , bottom = 10
                            , left = 25
                            }
                        ]
                        [ price
                        ]
                    ]
                , column
                    [ centerX ]
                    [ column
                        [ F.size 18
                        , F.bold
                        , F.color colourTheme.textLightOrange
                        ]
                        [ newTabLink []
                            { url = "https://drive.google.com/file/d/1sk7VgjuL2rEqQdnBRdZjr2_Ab9vwrbmo/view?usp=sharing"
                            , label =
                                paragraph
                                    [ centerX
                                    , centerY
                                    ]
                                    [ text "Free Cost Efficiency Score!" ]
                            }
                        ]
                    ]
                ]
            , column [ width fill, F.size 12, spacing 3 ] <|
                List.map2 (\x y -> makeFeature x)
                    nutridex.nutriDexFeatures
                    (List.range 1 (List.length nutridex.nutriDexFeatures))
            ]
        ]


featureListMobile : NutriDex -> Element msg
featureListMobile nutridex =
    column
        [ spacing 8
        , width fill
        , height fill
        , paddingEach
            { top = 10
            , bottom = 0
            , left = 0
            , right = 0
            }
        ]
        [ column
            [ spacing 20
            , centerX
            ]
            [ row
                [ centerX
                , E.width <| px 150
                ]
                [ html nutriDexLogo
                ]
            , row
                [ D.width 5
                , D.rounded 25
                , centerX
                , D.color colourTheme.backgroundLightGrey
                , B.color colourTheme.backgroundLightGrey
                ]
                [ row
                    [ B.color colourTheme.textDarkOrange
                    , D.rounded 30
                    , F.size 25
                    , F.bold
                    , paddingEach
                        { top = 10
                        , right = 25
                        , bottom = 10
                        , left = 25
                        }
                    ]
                    [ price
                    ]
                ]
            , column
                [ centerX ]
                [ column
                    [ F.size 18
                    , F.bold
                    , F.color colourTheme.textLightOrange
                    ]
                    [ newTabLink []
                        { url = "https://drive.google.com/file/d/1sk7VgjuL2rEqQdnBRdZjr2_Ab9vwrbmo/view?usp=sharing"
                        , label =
                            paragraph
                                [ centerX
                                , centerY
                                ]
                                [ text "Free Cost Efficiency Score!" ]
                        }
                    ]
                ]
            ]
        , column [ width fill, F.size 12, spacing 3 ] <|
            List.map2 (\x y -> makeFeature x)
                nutridex.nutriDexFeatures
                (List.range 1 (List.length nutridex.nutriDexFeatures))
        ]


nutriDexTitleMaker : String -> Element msg
nutriDexTitleMaker title =
    column
        [ width fill
        , height fill
        , spacing 20
        , paddingEach { top = 0, bottom = 0, left = 100, right = 100 }
        ]
        [ row
            [ width fill
            , centerX
            , D.widthEach { bottom = 1, top = 0, left = 0, right = 0 }
            , D.color (rgb255 200 200 200)
            , paddingEach { top = 40, bottom = 0, left = 0, right = 0 }
            ]
            []
        , paragraph
            (paragraphBoldFormat
                ++ [ centerX
                   , F.size 25
                   , F.color colourTheme.textLightOrange
                   , paddingEach
                        { top = 10
                        , right = 0
                        , bottom = 10
                        , left = 0
                        }
                   ]
            )
            [ text title ]
        ]


linkFormat : List (Attr () msg)
linkFormat =
    paragraphFormat
        ++ [ F.color colourTheme.textLightOrange
           ]


nutriDexBodyMaker : Element msg
nutriDexBodyMaker =
    column
        [ width fill
        , height fill
        ]
        [ column [ spacing 10 ]
            [ nutriDexTitleMaker "Backstory"
            , row []
                [ paragraph
                    (paragraphFormat
                        ++ [ F.alignLeft
                           , width fill
                           ]
                    )
                    [ text "In May 2019, after losing my job, I sought a way to optimize my diet for nutrient density (ND) while keeping costs low. I initially found a resource called "
                    , newTabLink linkFormat
                        { url = "https://efficiencyiseverything.com/food/"
                        , label = text "Efficiency Is Everything"
                        }
                    , text ", which ranked foods by nutrition per cost, but I found it too simplistic and lacking nuance, especially since it ranked processed foods like white bread highly, despite their limited health benefits. I wanted a more personalized approach—one that took into account both ND and the cost of foods specific to my region. Inspired by Mat Lalonde's AHS12 talk "
                    , newTabLink linkFormat
                        { url = "https://www.youtube.com/watch?v=HwbY12qZcF4"
                        , label = text "Nutrient Density: Sticking to the Essentials"
                        }
                    , text " on nutrient density, I created a rudimentary list of 75 foods and manually assigned them scores based on nutritional content from "
                    , newTabLink linkFormat
                        { url = "https://cronometer.com/"
                        , label = text "Cronometer"
                        }
                    , text ", paired with local grocery prices."
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "As I refined the list, I found a community on Reddit called "
                    , newTabLink linkFormat
                        { url = "https://www.reddit.com/r/EatCheapAndHealthy/"
                        , label = text "EatCheapAndHealthy"
                        }
                    , text " where I shared my "
                    , newTabLink linkFormat
                        { url = "https://www.reddit.com/r/EatCheapAndHealthy/comments/cbmxre/had_no_idea_this_sub_existed_heres_a_nutrient/"
                        , label = text "spreadsheet"
                        }
                    , text ". The overwhelming response encouraged me to expand it further, incorporating more foods, detailed nutritional data, and more accurate ND scores. To improve accuracy, I turned to the USDA’s "
                    , newTabLink linkFormat
                        { url = "https://www.ars.usda.gov/northeast-area/beltsville-md-bhnrc/beltsville-human-nutrition-research-center/nutrient-data-laboratory/docs/sr28-download-files/"
                        , label = text "SR28 database"
                        }
                    , text ", which provided granular data for over 700 common foods. I developed a more sophisticated scoring system, assigning points based on how well each food met the daily recommended intake for essential nutrients, then normalizing these scores from 0 to 100."
                    ]
                ]
            , row []
                [ paragraph
                    (paragraphFormat
                        ++ [ F.alignLeft
                           , width fill
                           ]
                    )
                    [ text "The final ND scores were calculated non-linearly, allowing for a more balanced representation of a food’s nutrient profile rather than allowing one nutrient to dominate the score. For instance, while Brazil nuts are high in selenium, the non-linear formula prevents their score from being artificially inflated by this one nutrient. Ultimately, the system I created allows for a more objective and personalized way to rank foods by both nutrient density and cost, making it a valuable resource for anyone looking to optimize their diet." ]
                ]
            ]
        ]


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


nutriDexAdjustments : Element msg
nutriDexAdjustments =
    column
        [ width fill
        , height fill
        , spacing 20
        ]
        [ nutriDexTitleMaker "Nutrient Density Score Adjustments"
        , row []
            [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                [ text "• "
                , text "No adjustments are made to vitamin B1, vitamin B2, vitamin B3, manganese, phosphorus, and potassium, due to their DRIs only representing total daily intake, or due to the nutrient having close to 100% bioavailability. "
                , row [ F.regular, F.size 12 ]
                    [ newTabLink referenceFormat
                        { url = "https://www.ncbi.nlm.nih.gov/books/NBK114331/"
                        , label = text "1"
                        }
                    , text ", "
                    , newTabLink referenceFormat
                        { url = "https://www.ncbi.nlm.nih.gov/books/NBK114322/"
                        , label = text "2"
                        }
                    , text ", "
                    , newTabLink referenceFormat
                        { url = "https://www.ncbi.nlm.nih.gov/books/NBK114304/"
                        , label = text "3"
                        }
                    , text ", "
                    , newTabLink referenceFormat
                        { url = "https://www.ncbi.nlm.nih.gov/books/NBK56056/"
                        , label = text "4"
                        }
                    , text ", "
                    , newTabLink referenceFormat
                        { url = "https://www.nap.edu/read/11537/chapter/39"
                        , label = text "5"
                        }
                    , text ", "
                    , newTabLink referenceFormat
                        { url = "https://www.nap.edu/read/11537/chapter/41"
                        , label = text "6"
                        }
                    , text ", "
                    , newTabLink referenceFormat
                        { url = "https://www.nap.edu/read/11537/chapter/42"
                        , label = text "7"
                        }
                    ]
                ]
            ]
        ]


nutridexSubTitleMaker : String -> Element msg
nutridexSubTitleMaker title =
    paragraph
        (paragraphBoldFormat
            ++ [ F.alignLeft
               , width fill
               , F.size 18
               , F.color colourTheme.textLightOrange
               ]
        )
        [ text title ]


nutriDexVitamins : Element msg
nutriDexVitamins =
    column
        [ width fill
        , height fill
        ]
        [ column [ spacing 10 ]
            [ row
                [ centerX
                , paddingEach
                    { top = 10
                    , right = 0
                    , bottom = 10
                    , left = 0
                    }
                ]
                [ nutridexSubTitleMaker "Vitamins"
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for vitamin B5 is multiplied by 2 in order to accommodate its average 50% bioavailability from food. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/books/NBK114311/"
                            , label = text "8"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for plant-derived vitamin B6 is multiplied by 1.74 in order to accommodate the average ~42.5% reduction in bioavailability of pyridoxine glucoside. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/2843032"
                            , label = text "9"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for animal-derived vitamin B6 is multiplied by 1.33 in order to accommodate the average ~25% reduction in bioavailability of as a result of cooking. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://pdfs.semanticscholar.org/b844/5e60d87753144ef856e0ae207b551aa75b9c.pdf"
                            , label = text "10"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The contribution of vitamin B12 is capped at 1.5mcg in order to account for the average absorption cap of ~1.5mcg per serving in healthy people. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/18606874"
                            , label = text "11"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for folate has been multiplied by 2 in order to accommodate its average 50% bioavailbility from food. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3257685/"
                            , label = text "12"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The contribution of plant-derived vitamin A (as retinol activity equivalents) is capped at 900mcg. This is to accommodate the fact that it is unlikely that the body can convert more than the DRI of vitamin A from carotenoids. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2855261/"
                            , label = text "13"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for plant-derived vitamin K, phylloquinone, is multiplied by 10 in order to accommodate its 10% bioavailability from plant foods. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/8813897"
                            , label = text "14"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for vitamin C has been multiplied by 1.25 in order to accommodate its average ~80% bioavailability. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/12134712"
                            , label = text "15"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for vitamin E has been multiplied by 4.65 in order to accommodate its average 21.5% bioavailability. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5745505/"
                            , label = text "16"
                            }
                        ]
                    ]
                ]
            ]
        ]


nutriDexFattyAcids : Element msg
nutriDexFattyAcids =
    column
        [ width fill
        , height fill
        ]
        [ column [ spacing 10 ]
            [ row
                [ centerX
                , paddingEach
                    { top = 10
                    , right = 0
                    , bottom = 10
                    , left = 0
                    }
                ]
                [ nutridexSubTitleMaker "Fatty Acids"
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRIs for omega-3 and omega-6 have been recalculated to 250mg/day and 500mg/day, respectively. This better reflects our actual physiological requirements for these fatty acids as provided by their pre-elongated, animal-derived varieties. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5946201/"
                            , label = text "17"
                            }
                        , text ", "
                        , newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5452278/"
                            , label = text "18"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRIs for plant-derived omega-3 and omega-6 have been multiplied by 6.66 in order to reflect their maximal ~15% conversion rate. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/12323090"
                            , label = text "19"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The contributions of plant-derived omega-3 and omega-6 are capped at 4.4444g before conversion rates are factored, in order to accommodate their conversion rate cap of 2% of calories per day. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3132704/"
                            , label = text "20"
                            }
                        ]
                    ]
                ]
            ]
        ]


nutriDexMinerals : Element msg
nutriDexMinerals =
    column
        [ width fill
        , height fill
        ]
        [ column [ spacing 10 ]
            [ row
                [ centerX
                , paddingEach
                    { top = 10
                    , right = 0
                    , bottom = 10
                    , left = 0
                    }
                ]
                [ nutridexSubTitleMaker "Minerals"
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for calcium has been adjusted dynamically based on the oxalate-to-calcium ratio of each food. "
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for plant-derived copper has been multiplied by 2.94 in order to accommodate its average ~34% bioavailability from plant foods. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/8615369"
                            , label = text "21"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for animal-derived copper has been multiplied by 2.43 in order to accommodate its average ~41% bioavailability from animal foods. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/8615369"
                            , label = text "21"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for magnesium has been multiplied by 2.85 in order to accommodate its 35% bioavailability. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/1864954"
                            , label = text "22"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for iron has been adjusted dynamically based on the phytate-to-iron ratio of each food."
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for selenium has been multiplied by 1.11 in order to accommodate its 90% bioavailability. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/20200264"
                            , label = text "23"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The contribution of zinc is capped at 7mg in order to account for the average absorption cap of 7mg per serving in healthy people. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://www.ncbi.nlm.nih.gov/pubmed/10801947"
                            , label = text "24"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRI for zinc has been adjusted dynamically based on the phytate-to-zinc ratio of each food. "
                    ]
                ]
            ]
        ]


nutriDexAminoAcids : Element msg
nutriDexAminoAcids =
    column
        [ width fill
        , height fill
        ]
        [ column [ spacing 10 ]
            [ row
                [ centerX
                , paddingEach
                    { top = 10
                    , right = 0
                    , bottom = 10
                    , left = 0
                    }
                ]
                [ nutridexSubTitleMaker "Amino Acids"
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "The DRIs for all essential amino acids from non-animal sources have been multiplied by 1.492 in order to accommodate their average PDCAAS score of .67. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://en.wikipedia.org/wiki/Protein_Digestibility_Corrected_Amino_Acid_Score"
                            , label = text "25"
                            }
                        ]
                    ]
                ]
            , row []
                [ paragraph (paragraphFormat ++ [ F.alignLeft, width fill ])
                    [ text "• "
                    , text "All scores reflecting total protein yield of non-animal foods have been multiplied by .67 in order to accommodate the average 67% bioavailability of protein from non-animal sources. "
                    , row [ F.regular, F.size 12 ]
                        [ newTabLink referenceFormat
                            { url = "https://en.wikipedia.org/wiki/Protein_Digestibility_Corrected_Amino_Acid_Score"
                            , label = text "25"
                            }
                        ]
                    ]
                ]
            ]
        ]


nutriDexReferenceTitleMaker : Element msg
nutriDexReferenceTitleMaker =
    column
        [ width fill
        , height fill
        , spacing 20
        ]
        [ row
            [ width fill
            , centerX
            , D.widthEach { bottom = 1, top = 0, left = 0, right = 0 }
            , D.color (rgb255 200 200 200)
            , paddingEach { top = 40, bottom = 0, left = 0, right = 0 }
            ]
            []
        , paragraph
            (paragraphBoldFormat
                ++ [ centerX
                   , F.size 25
                   , F.color colourTheme.textLightOrange
                   , paddingEach
                        { top = 10
                        , right = 0
                        , bottom = 10
                        , left = 0
                        }
                   ]
            )
            [ text "References" ]
        ]


nutriDexReferences : NutriDex -> Element msg
nutriDexReferences nutridex =
    column
        [ width fill
        , height fill
        ]
        [ nutriDexTitleMaker "Reference"
        , column [ width fill, F.size 15, spacing 10 ] <|
            List.map2 (\x y -> makeReference x y)
                nutridex.nutriDexReference
                (List.range 1 (List.length nutridex.nutriDexReference))
        ]


makeReference : References -> Int -> Element msg
makeReference references index =
    paragraph
        [ F.regular
        , F.alignLeft
        ]
        [ row []
            [ newTabLink
                [ F.bold
                , F.color colourTheme.textLightOrange
                , mouseOver [ F.color colourTheme.textDarkOrange ]
                , htmlAttribute <| style "transition" "all 0.1s ease-in-out"
                ]
                { url = references.link, label = text (String.fromInt index ++ ". ") }
            , text references.author
            , text references.title
            , text references.journal
            , text references.year
            ]
        ]
