<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" href="./favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="./style.css" />
    <script
            src="https://code.jquery.com/jquery-3.3.1.min.js"
            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
            crossorigin="anonymous">
    </script>
    <script src="js/githubAPI.js"></script>
    <script src="js/friendsGraph.js"></script>
    <script src="js/profileGen.js"></script>
    <script src="js/utilities.js"></script>

    <script type="text/javascript" src="js/vis/vis.js"></script>
    <link href="js/vis/vis-network.min.css" rel="stylesheet" type="text/css" />

</head>
<body>
    <div id="header-bar" class="d-flex flex-column flex-md-row shadow-sm align-items-center">
        <div id="header-title">
            <a href="./index.html">
                <img id="logo" src="./logo.svg" />
            </a>
        </div>
        <div id="navigation">
            <ul class="nav">
                <li class="nav-item">
                    <a href="./FriendsGraph.html">
                        Generate graphs
                    </a>
                </li>
                <div class="nav-sep"></div>
                <li class="nav-item">
                    <a href="https://github.com/jrtechs/github-graphs">
                        View on GitHub
                    </a>
                </li>
                <div class="nav-sep"></div>
                <li class="nav-item">
                    <a href="./about.html">
                        About
                    </a>
                </li>
            </ul>
        </div>
    </div>
<div class="main container">

    <div class="row align-center" id="searchBarTop">
        <nav class="navbar navbar-light bg-light justify-content-between">
          <a class="navbar-brand">Create Graph</a>
          <form class="form-inline">
            <input class="form-control mr-sm-2" id='txtUsername' type="search" placeholder="GitHub Username" aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" onclick='fetchUserInput()' type='button'>Look Up</button>
          </form>
        </nav>
    </div>

    <div class="row">
        <div class="col-md-8 col-12">
            <h2 id="graphLabel"></h2>
            <div id="myGraph" class="w-100"></div>
            <pre id="eventSpan"></pre>
        </div>
        <div class="col-md-4 col-12 w-100">
            <div id="profileGen"></div>
        </div>
    </div>
</body>

<script>

    document.addEventListener("keydown", event => {
        if (event.key === "Enter") {
            fetchUserInput();
        }
    })

    function fetchUserInput()
    {
        const inputedName = $("#txtUsername").val();
        createGraphs(inputedName);
    }

    function createGraphs(username)
    {
        options.width = $("#myGraph").width() + "px";
        options.height = "700px";
        createFriendsGraph(username, "myGraph", "graphLabel");
        profileGen(username, "profileGen");
        $("#searchBarTop").html("");
    }

    if(findGetParameter("name") !== null)
    {
        createGraphs(findGetParameter("name"))
    }
</script>

</html>