<vn>
<vn-lot-query id="params">
	<vn-spec name="from" type="Date"/>
	<vn-spec name="to" type="Date"/>
</vn-lot-query>
<h1 id="title">
	_Visits
</h1>
<div id="actions">
	<htk-bar-button
		icon="refresh"
		tip="_Refresh"
		on-click="onRefreshClick"/>
	<htk-bar-button
		icon="user-info"
		tip="_Connections"
		on-click="onSessionsClick"/>
</div>
<div id="main" class="visits">
	<div class="card form">
		<div>
			<label>_From</label>
			<htk-date-chooser lot="params" name="from"/>
		</div>
		<div>
			<label>_To</label>
			<htk-date-chooser lot="params" name="to"/>
		</div>
	</div>
	<div class="summary card form">
		<p>
			<htk-text>
				<db-calc-sum
					property="param"
					model="visits"
					column-name="visits"/>
			</htk-text> 
			<span>_visits</span>,
			<htk-text>
				<db-calc-sum
					property="param"
					model="visits"
					column-name="newVisits"/>
			</htk-text> 
			<span>_news</span>
		</p>
	</div>
	<div class="card list ">
		<htk-repeater empty-message="_Select date interval">
			<db-model property="model" id="visits" lot="params">
				SELECT browser
						,MIN(CAST(version AS DECIMAL(4,1))) minVersion
						,MAX(CAST(version AS DECIMAL(4,1))) maxVersion
						,MAX(c.stamp) lastVisit
						,COUNT(DISTINCT c.id) visits
						,SUM(a.firstAccess = c.id AND v.firstAgent = a.id) newVisits
					FROM visitUser e
						JOIN visitAccess c ON e.access = c.id
						JOIN visitAgent a ON c.agent = a.id
						JOIN visit v ON a.visit = v.id
					WHERE c.stamp BETWEEN TIMESTAMP(#from,'00:00:00') AND TIMESTAMP(#to,'23:59:59')
					GROUP BY browser
					ORDER BY visits DESC
			</db-model>
			<custom>
				<div class="list-row">
					<p class="important">
						{{browser}} {{minVersion}} - {{maxVersion}}
					</p>
					<p>
						{{visits}} <span>_visits</span>, {{newVisits}} <span>_news</span>
					</p>
					<p>
						<htk-text lot="iter" name="lastVisit" format="_%a, %e %b %Y at %T"/>
					</p>
				</div>
			</custom>
		</htk-repeater>
	</div>
</div>
</vn>
