<vn>
<vn-lot-query id="params">
	<vn-spec name="from" type="Date"/>
	<vn-spec name="to" type="Date"/>
</vn-lot-query>
<div id="title">
	<h1><t>Visits</t></h1>
</div>
<div id="actions">
	<htk-bar-button
		icon="refresh"
		tip="_Refresh"
		on-click="visits.refresh()"/>
	<htk-bar-button
		icon="visibility"
		tip="_Connections"
		on-click="this.hash.setAll({form: 'admin/connections'})"/>
</div>
<div id="form" class="visits">
	<div class="vn-w-xs">
		<div class="form vn-pa-lg box">
			<div class="form-group">
				<label><t>From</t></label>
				<htk-date-chooser
					form="params"
					column="from"/>
			</div>
			<div class="form-group">
				<label><t>To</t></label>
				<htk-date-chooser
					form="params"
					column="to"/>
			</div>
		</div>
		<div class="summary vn-pa-lg box">
			<p>
				<htk-text>
					<db-calc-sum
						property="param"
						model="visits"
						column-name="visits"/>
				</htk-text> 
				<t>visits</t>,
				<htk-text>
					<db-calc-sum
						property="param"
						model="visits"
						column-name="newVisits"/>
				</htk-text> 
				<t>news</t>
			</p>
		</div>
		<htk-repeater
			class="box htk-list"
			form-id="iter"
			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.firstAccessFk = c.id AND v.firstAgentFk = a.id) newVisits
					FROM visitUser e
						JOIN visitAccess c ON c.id = e.accessFk
						JOIN visitAgent a ON a.id = c.agentFk
						JOIN visit v ON v.id = a.visitFk
					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="item">
					<div class="content">
						<p class="important">
							{{iter.browser}} {{iter.minVersion}} - {{iter.maxVersion}}
						</p>
						<p>
							{{iter.visits}} <t>visits</t>, 
							{{iter.newVisits}} <t>news</t>
						</p>
						<p>
							{{Vn.Value.format(iter.lastVisit, _('%a, %e %b %Y at %T'))}}
						</p>
					</div>
				</div>
			</custom>
		</htk-repeater>
	</div>
</div>
</vn>
