{{ define "title" }}Ask Me Anything{{ end }}
{{ define "content" }}

{{ $Q := .V.Q }}
<div class="card">
	<div class="card-body">
		<form action="/ask" method="POST">
		{{ CSRF }}

		<div class="form-group row">
			<div class="col-12 col-md-2">
				<label class="col-form-label" for="name">Name:</label>
			</div>
			<div class="col-12 col-md-10">
				<input type="text" class="form-control" id="name" name="name" value="{{ $Q.Name }}" placeholder="Anonymous">
			</div>
		</div>
		<div class="form-group row">
			<label class="col-12" for="question">Question: <small>(required)</small></label>
			<textarea cols="80" rows="6"
			class="col-12 form-control"
			name="question"
			id="question"
			placeholder="Ask me anything">{{ $Q.Question }}</textarea>
		</div>

		<div class="form-group row">
			<div class="col">
				<button type="submit"
				name="submit"
				value="ask"
				class="btn btn-primary">Ask away!</button>
			</div>
		</div>

		</form>
	</div>
</div>

{{ if gt (len .V.Recent) 0 }}
	<div class="card mt-4">
		<div class="card-header">
			Recently Answered
		</div>
		<div class="card-body">
			{{ range .V.Recent }}
			<strong>{{ or .Name "Anonymous" }}</strong> asks:
			<p>{{ .Question }}</p>
			<p>
				<a href="/{{ .Post.Fragment }}">Read answer&gt;</a>
			</p>
			<p class="blog-meta">
				<em title="{{ .CreatedAt.Format "Jan 2 2006 15:04:05 MST" }}">
					{{ .CreatedAt.Format "January 2, 2006" }}
				</em>
			</p>

			<hr class="my-4">
			{{ end }}

			<p>
				<a href="/tagged/ask">&rarr; More questions &amp; answers</a>
			</p>
		</div>
	</div>
{{ end }}

{{ if .LoggedIn }}
<div class="card mt-4">
	<div class="card-header bg-secondary text-light">
		Pending Questions
	</div>
	<div class="card-body">
		{{ if not .V.Pending }}
		<em>There are no pending questions.</em>
		{{ end }}

		{{ range .V.Pending }}
		<p>
			<strong>{{ or .Name "Anonymous" }}</strong> asks:<br>
			<small class="text-muted">
				<em>{{ .CreatedAt.Format "January 2, 2006 @ 15:04 MST" }}</em> by
			</small>
		</p>
		<p>
			{{ .Question }}
		</p>

		<div id="form-{{ .ID }}" class="dhtml-forms">
			<form method="POST" action="/ask/answer">
				{{ CSRF }}
				<input type="hidden" name="id" value="{{ .ID }}">
				<textarea cols="80" rows="4"
				class="form-control"
				name="answer"
				required="required"
				placeholder="Answer (Markdown formatting allowed)"></textarea>

				<div class="btn-group mt-3">
					<button type="submit" name="submit" value="answer" class="btn btn-primary">
						Answer
					</button>
					<button type="submit" name="submit" value="delete" class="btn btn-danger">
						Delete
					</button>
				</div>
			</form>
		</div>
		<div id="button-{{ .ID }}" class="dhtml-buttons" style="display: none">
			<button type="button" class="btn" id="show-{{ .ID }}" class="dhtml-show-button">Answer or delete</button>
		</div>

		<hr>
		{{ end }}
	</div>
</div>
{{ end }}

{{ end }}
