-- JS world code.

var app = Elm.Main.init({
    node: document.getElementById("resume")
});
var loadContent = function (data) {
    app.ports.onFetchingData.send(data)
}
loadContent(
  JSON.stringify([
    {
      heading: "Career Summary",
      class: "career-summary",
      data:
        "I work on Front End Technologies. I also have experience in the Back-End development. I am inclined to work with different technologies with good practices and worked on diverse projects to gain an understanding of the software development process."
    }
  ])
);



-- Subscriptions 
subscriptions : Model -> Sub Msg
subscriptions _ =
    onFetchingData (\payload -> ResumeContent <| decode payload)


port onFetchingData : (String -> msg) -> Sub msg


decode : String -> Model
decode payload =
    case Decode.decodeValue resumeDataDecoder (Encode.string payload) of
        Ok resumeContent ->
            resumeContent

        Err err ->
            List.singleton (Section "Error" "temp" (Decode.errorToString err))



-- Decoders
resumeDataDecoder : Decode.Decoder Model
resumeDataDecoder =
    Decode.list resumeSectionDecoder


resumeSectionDecoder : Decode.Decoder Section
resumeSectionDecoder =
    Decode.succeed Section
        |> required "heading" Decode.string
        |> required "class" Decode.string
        |> required "data" Decode.string
