<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="${package}.entity.SampleEntity" %>

<html>
<head>
	<title>index</title>
</head>
<body>
<%
    User user = (User) request.getAttribute("user");
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can <a href="<%= request.getAttribute("logoutUrl") %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello! <a href="<%= request.getAttribute("loginUrl") %>">Sign in</a> to include your name with greetings you post.</p>
<%
    }
%>

<h1>index</h1>
<%
	List<SampleEntity> entities = (List<SampleEntity>) request.getAttribute("entities");
	if (entities.isEmpty()) {
%>
<p>no entities.</p>
<%
	} else {
%>
<ul>
<%
		for (SampleEntity entity : entities) {
			if (entity.getUser() == null) {
%>
<li><%= entity.getContent() %> (anonymous, <%= entity.getCreated() %>)</li>
<%
			} else {
%>
<li><%= entity.getContent() %> (<%= entity.getUser().getNickname() %>, <%= entity.getCreated() %>)</li>
<%
			}
		}
%>
</ul>
<%
	}
%>

<form action="/post" method="post">
  <div><input type="text" name="content" size="100"/></div>
  <div><input type="submit" value="New Post" /></div>
</form>

</body>
</html>
