<template name="dashboard">
	<div class="template-dashboard">
		<div class="container">
			<div class="row">
				<div class="col-md-3">
					{{> addPost}}
					{{> favoritesSidebar}}
				</div>
        <div class="col-md-3">
          {{> addRobot}}
        </div>
				<div class="col-md-6">
					{{> robots}}
          {{> posts}}
				</div>
			</div>
		</div>
	</div>
</template>

<template name="addPost">
	<div class="template-add-post">
		<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title">{{_ "add_post"}}</h3>
				</div>
				<div class="panel-body">
					{{#autoForm id="add" collection="Posts" type="insert"}}
					{{> afQuickField name="title"}}
					{{> afQuickField name="content"}}
					{{> afQuickField name="picture"}}
					<button type="submit" class="btn btn-primary">{{_ "add_post_btn"}}</button>
					{{/autoForm}}
				</div>
		</div>
	</div>
</template>

<template name="addRobot">
  <div class="template-add-robot">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">{{_ "add_robot"}}</h3>
      </div>
      <div class="panel-body">
        {{#autoForm id="addRobot" collection="Robots" type="insert"}}
          {{> afQuickField name="name"}}
          {{> afQuickField name="rosip"}}
          {{> afQuickField name="topics"}}
          <button type="submit" class="btn btn-primary">{{_ "add_robot_btn"}}</button>
        {{/autoForm}}
      </div>
    </div>
  </div>
</template>

<template name="posts">
	<div class="template-posts">
		{{#each posts}}
		{{> post}}
		{{else}}
		{{> noData}}
		{{/each}}
	</div>
</template>

<template name="robots">
  <div class="template-robots">
    {{#each robots}}
      {{> robot}}
    {{else}}
      {{> noData}}
    {{/each}}
  </div>
</template>

<!--TODO add displaying robots-->

<template name="post">
	<div class="template-post">
		<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title">
						{{title}}
						<span class="pull-right">
							<i class="fa fa-thumbs-up"></i> {{#with favoritesByDoc _id}}{{count}}{{/with}}
							<i class="fa fa-comments"></i> {{commentCount _id}}
						</span>
					</h3>
				</div>
				<div class="panel-body">

					<p class="text-center">
						{{#with getDoc picture 'Attachments'}}
							<img src="{{url}}" class="img-thumbnail img-rounded">
						{{/with}}
					</p>
					<div class="media">
						<a class="pull-left" href="#">
							{{> avatar userId=owner shape="circle"}}
						</a>
						<div class="media-body">
							<p>{{content}}</p>
							{{#if $eq owner User._id}}
							<small>
								{{#afModal title="Update post" omitFields="createdAt,updatedAt,owner" class="text-primary" collection="Posts" operation="update" doc=_id}}
									<i class="fa fa-pencil" buttonContent="Edit post"></i> {{_ "edit_post"}}
								{{/afModal}}
								{{#afModal title="Delete post" class="text-danger" collection="Posts" operation="remove" doc=_id}}
									<i class="fa fa-times" buttonContent="Edit post"></i> {{_ "delete"}}
								{{/afModal}}
							</small>
							{{/if}}
						</div>
					</div>
				</div>
				<div class="panel-footer">
					{{> favoriteButton _id=_id}}
					{{> commentFormToggle }}
					{{> comments}}
				</div>
		</div>
	</div>
</template>

<template name="robot">
  <div class="template-robot">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">
          {{name}}
        </h3>
      </div>
      <div class="panel-body">
        <div class="media">
          <a class="pull-left" href="#">
            {{> avatar userId=owner shape="circle"}}
          </a>
          <div class="media-body">
            <p>{{rosip}}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<template name="favoritesSidebar">
	<div class="template-favorites-sidebar">
		{{#if myFavorites.count}}
		<div class="panel panel-default">
			<div class="panel-heading">
					<h3 class="panel-title">{{_ "favorites"}}</h3>
			</div>
			<div class="panel-body">
				<ul>
				{{#each myFavorites}}
					<li>
						<a>{{_id}}</a>
					</li>
				{{/each}}
				</ul>
			</div>
		</div>
		{{/if}}
	</div>
</template>
