<script>
    var getUrl = '<?php echo URL::route('getEmailData'); ?>';
    var getUrlAll = '<?php echo URL::route('getAllEmails'); ?>';
</script>

<!-- Dashboard companies start -->

<div id="dashboard-emails">
	<div class="row">
		<div class="col s12">
			<div id="vueEmails">
				<div id="recent-emails">
					<div class="widget-holder hoverable">
						<div class="widget-heading">
							<h2 class="widget-heading-thick"><?php echo Lang::get('dashboard.email_dashboard_heading'); ?></h2>
						</div>
						<div class="widget-content">
							<div class="row">
								<div class="col s10">
									<div class="email-container content-wrapper">
										<?php foreach($emails as $email): ?>
											<div class="email-single">
												<span class="email-date"><?php echo date('d.m.Y', strtotime($email->date)); ?> - </span><a v-on:click="getEmail(<?php echo $email->email_id; ?>)" class="icon-btn icon-btn-edit email-truncate"><?php echo $email->subject; ?></a>
											</div>
										<?php endforeach; ?>
									</div>
									<a href="<?php echo URL::route('getAllEmails'); ?>" class="fetch-more btn-floating tooltipped btn-large waves-effect waves-light" data-position="left" data-delay="25" data-tooltip="<?php echo Lang::get('dashboard.all_emails_tooltip'); ?>">...</a>
								</div>
							</div>
						</div>
					</div>

				</div>
				<div id="show-email" class="modal modal-fixed-footer">
					<div class="modal-content">
						<h4>{{ subject }}</h4>
						<hr>
						<p class="email-modal-text" v-html="content"></p>
						<div v-if="image" class="email-modal-attachment">
							<h3><?php echo Lang::get('dashboard.email_modal_attachment'); ?>: </h3>
							<div class="attachment-container" v-for="imagePath in image">
								<img onclick="bigImage=this.src; showImage()" v-if="imagePath" :src="imagePath" alt="email-image" class="enlargale email-modal-image">
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<a href="#!" class="modal-action modal-close btn waves-effect waves-light"><?php echo Lang::get('dashboard.email_modal_close'); ?></a>
					</div>
				</div>

				<div id="show-image-modal" class="modal modal-fixed-footer">
					<div class="modal-content">
						<img id="big-image" src="">
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<div id="dashboard-companies" class="fadeIn">
	<div class="row">
		<div class="col s12">

			<!-- Companies-->
			<div class="widget-holder hoverable fadeIn" id="dashboard-companies-overview">
				<div class="widget-heading">
					<h2 class="widget-heading-thick"><?php echo Lang::get('core.menu_companies'); ?></h2>

					<?php if(Entrust::hasRole('superadmin') || Entrust::hasRole('admin')): ?>

						<a href="<?php echo URL::route('getAddCompany'); ?>" class="btn-floating waves-effect waves-light btn-primary new-blog-post" id="add-company-button"><i class="material-icons">add</i></a>
					<?php endif; ?>

					<div class="row filter-row">
						<div class="col s12">

							<div class="input-field right">
								<i class="material-icons prefix">search</i>
								<input id="icon_prefix" type="text" onkeyup="filterTable()">
								<label for="icon_prefix">Search...</label>
							</div>
						</div>
					</div>
				</div>
				<div class="widget-content">

					<?php if(Entrust::hasRole('manager')): ?>
						<?php if($companies===null): ?>
							<h5><?php echo Lang::get('core.no_companies_for_manager'); ?></h5>

						<?php else: ?>
						<div class="table-wrapper">
							<table class="bordered responsive-table">
								<thead>
								<tr>
									<th><?php echo Lang::get('companiesList.header_name'); ?></th>
									<th><?php echo Lang::get('companiesList.header_email'); ?></th>
									<th><?php echo Lang::get('companiesList.header_phone'); ?></th>
									<th><?php echo Lang::get('companiesList.header_address'); ?></th>
									<th><?php echo Lang::get('communalService.reports_count'); ?></th>
									<th><?php echo Lang::get('communalService.header_action'); ?></th>

								</tr>
								</thead>

								<tbody id="searchable">
								<?php foreach($companies as $company): ?>

									<td>
										<?php echo $company['company']->name; ?>

									</td>
									<td>
										<?php echo $company['company']->email; ?>

									</td>
									<td>
										<?php echo $company['company']->phone; ?>

									</td>
									<td>
										<?php echo $company['company']->address; ?>

									</td>
									<td>
										<?php echo $company['count_items']; ?>

									</td>
									<td>

											<a href="<?php echo URL::route('getCompanyReports', array('id' => $company['company']->id)); ?>"  data-tooltip="<?php echo Lang::get('communalService.link_view_company_reports'); ?>" class="icon-btn icon-btn-edit tooltipped"><i class="material-icons">visibility</i></a>



									</td>
									</tr>

								<?php endforeach; ?>
								</tbody>
							</table>

						</div>
						<?php endif; ?>
					<?php endif; ?>
					<?php if(Entrust::hasRole('superadmin') || Entrust::hasRole('admin')): ?>

						<div class="table-wrapper">
							<table class="bordered responsive-table">
								<thead>
								<tr>
									<th><?php echo Lang::get('companiesList.header_name'); ?></th>
									<th><?php echo Lang::get('companiesList.header_city'); ?></th>
									<th><?php echo Lang::get('companiesList.header_email'); ?></th>
									<th><?php echo Lang::get('companiesList.header_phone'); ?></th>
									<th><?php echo Lang::get('companiesList.header_address'); ?></th>
									<th><?php echo Lang::get('companiesList.header_description'); ?></th>
									<th><?php echo Lang::get('communalService.header_action'); ?></th>

								</tr>
								</thead>

								<tbody  id="searchable">
								<?php foreach($companies as $company): ?>


									<tr>

										<td>
											<?php echo $company['city_company']->name; ?>

										</td>
										<td>
											<?php echo $company['city_company']->city_name; ?>

										</td>
										<td>
											<?php echo $company['city_company']->email; ?>

										</td>
										<td>
											<?php echo $company['city_company']->phone; ?>

										</td>
										<td>
											<?php echo $company['city_company']->address; ?>

										</td>
										<td>
											<?php echo $company['city_company']->description; ?>

										</td>
										<td>
											<a href="<?php echo URL::route('getEditCompany', array('id' => $company['city_company']->id)); ?>"  title="<?php echo Lang::get('companiesList.button_edit_company', array('name' => $company['city_company']->name)); ?>" class="icon-btn icon-btn-edit"><i class="material-icons">mode_edit</i></a>
											<a href="<?php echo URL::route('getDeleteCompany', array('id' => $company['city_company']->id)); ?>"  title="<?php echo Lang::get('companiesList.button_delete_company', array('name' => $company['city_company']->name)); ?>" class="icon-btn icon-btn-delete"><i class="material-icons">delete</i></a>
										</td>
									</tr>

								<?php endforeach; ?>
								</tbody>
							</table>

						</div>

					<?php endif; ?>
				</div>
			</div>
			<!--Companies end-->

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

<!-- Dashboard companies end -->

