{"size": 4059, "ext": "js", "max_stars_repo_path": "assets/js/script.js", "max_stars_repo_name": "clhurlbut/virtual_fortune_cookie", "max_stars_repo_stars_event_min_datetime": "2021-03-14T19:49:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T19:49:24.000Z", "max_issues_repo_path": "assets/js/script.js", "max_issues_repo_name": "clhurlbut/virtual_fortune_cookie", "max_issues_repo_issues_event_min_datetime": "2020-11-18T04:36:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-02T07:22:21.000Z", "max_forks_repo_path": "assets/js/script.js", "max_forks_repo_name": "clhurlbut/virtual_fortune_cookie", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 15, "max_forks_count": null, "avg_line_length": 26.7039473684, "max_line_length": 138, "alphanum_fraction": 0.620596206}
// 
// Define Variables 

var moodInput = $("#inputMood").val()
var cookieAnimateRight = $("#cookieRight");
var cookieAnimateLeft = $("#cookieLeft");

let results = []




// Get the input from the user and save it to local storage 
$("#searchBtn").click(function () {
    // show and hide boxs
    cookieAnimation();
    let searchResult = {}
    searchResult.input
    searchResult.result
    searchResult.input = $("#inputMood").val()
    // fetch results from giphy based on term 
    getGiphyData(searchResult.input)

        .then(giphyData => {
            searchResult.result = giphyData
            storeMoodResult(searchResult.input);
            renderGiphyData(searchResult.result);
        })

    fetch("https://type.fit/api/quotes")
        .then(function (response) {
            return response.json();
        })
        .then(function (data) {
            renderQuoteData(data)
            // console.log(data)
        })
    //    //fetch results from quotes based on terms
    //     getquoteData(searchResult.input)
    //     .then(quoteData => {
    //         searchResult.result = quoteData
    //         storeMoodResult(searchResult.input);
    //         renderQuoteData(searchResult.result);
    //     }) 
}
);

//     const handleevent = (response) => {
//         console.log(response) //my quote
//     }

//     fetch("https://quotes.rest/qod/categories?language=en&detailed=true")
//     .then (response => response.json())
//     .then(data => handleevent(data.contents.quotes[7]));
// }
// );

// then(giphyData => {
//     searchResult.result = giphyData
//     storeMoodResult(searchResult.input);
//     renderGiphyData(searchResult.result);
// })

// fetch results from quotes based on terms




// function renderQuoteData(data) {
//     let quoteContainer = $("#quoteCont")
//     quoteContainer.html(`text`);
// }

// Animation Functions
function cookieAnimation() {
    cookieAnimateLeft.addClass('animate__animated animate__rotateOutUpLeft');
    window.setTimeout(function () {
        cookieAnimateLeft.removeClass('animate__animated animate__rotateOutUpLeft');

        $("#cookieBox").hide();
        $("#fortuneBox").show();
        $("#newBtnContainer").show();
        $("#searchContainer").hide();
    }, 2000);

    cookieAnimateRight.addClass('animate__animated animate__rotateOutUpRight');
    window.setTimeout(function () {
        cookieAnimateRight.removeClass('animate__animated animate__rotateOutUpRight');

        $("#cookieBox").hide();
        $("#fortuneBox").show();
        $("#newBtnContainer").show();
        $("#searchContainer").hide();
    }, 2000);
};

// jQuery for newCookieButton

$("#newCookieBtn").click(function () {
    $("#fortuneBox").hide();
    $("#newBtnContainer").hide();
    $("#cookieBox").show();
    $("#searchContainer").show();
    clearInput();

});
// function to render the data
function renderGiphyData(data) {
    let giphyContainer = $("#giphyCont")
    giphyContainer.html(
        `
      <img class="center-align responsive-img" src="${data[0].images.fixed_height.url}"/>
      `
    );

}

// function to get the GIPHY data 

function getGiphyData(inputMood) {
    return new Promise((resolve, reject) => {
        fetch(`https://api.giphy.com/v1/gifs/search?q=${inputMood}&api_key=m1Xfg0VXns59b9T57eo1ghhh0KJYrA1c&limit=1&rating=pg-13&lang=en`)
            .then(function (response) {
                return response.json();
            })
            .then(result => resolve(result.data))
            .catch(err => reject(err))
    });




}

function renderQuoteData(data) {
    var randomQuote = data[Math.floor(Math.random() * data.length)]
    let quoteContainer = $("#quoteCont")
    quoteContainer.html(randomQuote.text);
    // renderQuoteData(Math.floor(Math.random() * 10))
    //console.log(randomQuote)
}

function clearInput() {
    document.getElementById("inputMood").value = "";
}

// function to store the results 
function storeMoodResult(input) {
    results.push(input)
    localStorage.setItem("mood", JSON.stringify(results))
}
