<?xml version="1.0" encoding="UTF-8"?>
<scenario begin="select_country">

	<!-- Rovinieta -->
	<!-- Select country -->
	<screen id="select_country" type="table" title="Alege tara">
		<fields>
			<table-field id="tf" title="Tabel" read-only="false">
				<columns>
					<column key="title" title="Tara (In care este inmatriculata)" width="0.7"/>
					<column key="iso_code" title="ISO" width="0.3"/>
				</columns>
				<items>
					<item><cell key="title" key-title="key-title" value="Romania" value-title="Romania"/><cell key="iso_code" key-title="key-title" value="RO" value-title="RO"/></item>
					<item><cell key="title" key-title="key-title" value="Bulgaria" value-title="Bulgaria"/><cell key="iso_code" key-title="key-title" value="BG" value-title="BG"/></item>
					<item><cell key="title" key-title="key-title" value="Hungary" value-title="Hungary"/><cell key="iso_code" key-title="key-title" value="HU" value-title="HU"/></item>
					<item><cell key="title" key-title="key-title" value="R. Moldova" value-title="R. Moldova"/><cell key="iso_code" key-title="key-title" value="MD" value-title="MD"/></item>
					<item><cell key="title" key-title="key-title" value="Turkey" value-title="Turkey"/><cell key="iso_code" key-title="key-title" value="TR" value-title="TR"/></item>
					<item><cell key="title" key-title="key-title" value="Ukraine" value-title="Ukraine"/><cell key="iso_code" key-title="key-title" value="UA" value-title="UA"/></item>
					<item><cell key="title" key-title="key-title" value="Spain" value-title="Spain"/><cell key="iso_code" key-title="key-title" value="ES" value-title="ES"/></item>
					<item><cell key="title" key-title="key-title" value="Italy" value-title="Italy"/><cell key="iso_code" key-title="key-title" value="IT" value-title="IT"/></item>
					<item><cell key="title" key-title="key-title" value="United Kingdom" value-title="United Kingdom"/><cell key="iso_code" key-title="key-title" value="GB" value-title="GB"/></item>
					<item><cell key="title" key-title="key-title" value="Austria" value-title="Austria"/><cell key="iso_code" key-title="key-title" value="AT" value-title="AT"/></item>
					<item><cell key="title" key-title="key-title" value="Belgium" value-title="Belgium"/><cell key="iso_code" key-title="key-title" value="BE" value-title="BE"/></item>
					<item><cell key="title" key-title="key-title" value="Bosnia and Herzegovina" value-title="Bosnia and Herzegovina"/><cell key="iso_code" key-title="key-title" value="BA" value-title="BA"/></item>
					<item><cell key="title" key-title="key-title" value="Belarus" value-title="Belarus"/><cell key="iso_code" key-title="key-title" value="BY" value-title="BY"/></item>
					<item><cell key="title" key-title="key-title" value="Switzerland" value-title="Switzerland"/><cell key="iso_code" key-title="key-title" value="CH" value-title="CH"/></item>
					<item><cell key="title" key-title="key-title" value="Sweden" value-title="Sweden"/><cell key="iso_code" key-title="key-title" value="SE" value-title="SE"/></item>
					<item><cell key="title" key-title="key-title" value="Albania" value-title="Albania"/><cell key="iso_code" key-title="key-title" value="AL" value-title="AL"/></item>
					<item><cell key="title" key-title="key-title" value="Andorra" value-title="Andorra"/><cell key="iso_code" key-title="key-title" value="AD" value-title="AD"/></item>
					<item><cell key="title" key-title="key-title" value="Croatia" value-title="Croatia"/><cell key="iso_code" key-title="key-title" value="HR" value-title="HR"/></item>
					<item><cell key="title" key-title="key-title" value="Cyprus" value-title="Cyprus"/><cell key="iso_code" key-title="key-title" value="CY" value-title="CY"/></item>
					<item><cell key="title" key-title="key-title" value="Czech Republic" value-title="Czech Republic"/><cell key="iso_code" key-title="key-title" value="CZ" value-title="CZ"/></item>
					<item><cell key="title" key-title="key-title" value="Denmark" value-title="Denmark"/><cell key="iso_code" key-title="key-title" value="DK" value-title="DK"/></item>
					<item><cell key="title" key-title="key-title" value="Estonia" value-title="Estonia"/><cell key="iso_code" key-title="key-title" value="EE" value-title="EE"/></item>
					<item><cell key="title" key-title="key-title" value="Finland" value-title="Finland"/><cell key="iso_code" key-title="key-title" value="FI" value-title="FI"/></item>
					<item><cell key="title" key-title="key-title" value="France" value-title="France"/><cell key="iso_code" key-title="key-title" value="FR" value-title="FR"/></item>
					<item><cell key="title" key-title="key-title" value="Georgia" value-title="Georgia"/><cell key="iso_code" key-title="key-title" value="GE" value-title="GE"/></item>
					<item><cell key="title" key-title="key-title" value="Germany" value-title="Germany"/><cell key="iso_code" key-title="key-title" value="DE" value-title="DE"/></item>
					<item><cell key="title" key-title="key-title" value="Greece" value-title="Greece"/><cell key="iso_code" key-title="key-title" value="GR" value-title="GR"/></item>
					<item><cell key="title" key-title="key-title" value="Greenland" value-title="Greenland"/><cell key="iso_code" key-title="key-title" value="GL" value-title="GL"/></item>
					<item><cell key="title" key-title="key-title" value="Iceland" value-title="Iceland"/><cell key="iso_code" key-title="key-title" value="IS" value-title="IS"/></item>
					<item><cell key="title" key-title="key-title" value="Ireland" value-title="Ireland"/><cell key="iso_code" key-title="key-title" value="IE" value-title="IE"/></item>
					<item><cell key="title" key-title="key-title" value="Israel" value-title="Israel"/><cell key="iso_code" key-title="key-title" value="IL" value-title="IL"/></item>
					<item><cell key="title" key-title="key-title" value="Latvia" value-title="Latvia"/><cell key="iso_code" key-title="key-title" value="LV" value-title="LV"/></item>
					<item><cell key="title" key-title="key-title" value="Liechtenstein" value-title="Liechtenstein"/><cell key="iso_code" key-title="key-title" value="LI" value-title="LI"/></item>
					<item><cell key="title" key-title="key-title" value="Lithuania" value-title="Lithuania"/><cell key="iso_code" key-title="key-title" value="LT" value-title="LT"/></item>
					<item><cell key="title" key-title="key-title" value="Luxembourg" value-title="Luxembourg"/><cell key="iso_code" key-title="key-title" value="LU" value-title="LU"/></item>
					<item><cell key="title" key-title="key-title" value="Macedonia" value-title="Macedonia"/><cell key="iso_code" key-title="key-title" value="MK" value-title="MK"/></item>
					<item><cell key="title" key-title="key-title" value="Malta" value-title="Malta"/><cell key="iso_code" key-title="key-title" value="MT" value-title="MT"/></item>
					<item><cell key="title" key-title="key-title" value="Monaco" value-title="Monaco"/><cell key="iso_code" key-title="key-title" value="MC" value-title="MC"/></item>
					<item><cell key="title" key-title="key-title" value="Montenegro" value-title="Montenegro"/><cell key="iso_code" key-title="key-title" value="ME" value-title="ME"/></item>
					<item><cell key="title" key-title="key-title" value="Netherlands" value-title="Netherlands"/><cell key="iso_code" key-title="key-title" value="NL" value-title="NL"/></item>
					<item><cell key="title" key-title="key-title" value="Norway" value-title="Norway"/><cell key="iso_code" key-title="key-title" value="NO" value-title="NO"/></item>
					<item><cell key="title" key-title="key-title" value="Poland" value-title="Poland"/><cell key="iso_code" key-title="key-title" value="PL" value-title="PL"/></item>
					<item><cell key="title" key-title="key-title" value="Portugal" value-title="Portugal"/><cell key="iso_code" key-title="key-title" value="PT" value-title="PT"/></item>
					<item><cell key="title" key-title="key-title" value="Russian Federation" value-title="Russian Federation"/><cell key="iso_code" key-title="key-title" value="RU" value-title="RU"/></item>
					<item><cell key="title" key-title="key-title" value="San Marino" value-title="San Marino"/><cell key="iso_code" key-title="key-title" value="SM" value-title="SM"/></item>
					<item><cell key="title" key-title="key-title" value="Serbia" value-title="Serbia"/><cell key="iso_code" key-title="key-title" value="RS" value-title="RS"/></item>
					<item><cell key="title" key-title="key-title" value="Slovakia" value-title="Slovakia"/><cell key="iso_code" key-title="key-title" value="SK" value-title="SK"/></item>
					<item><cell key="title" key-title="key-title" value="Slovenia" value-title="Slovenia"/><cell key="iso_code" key-title="key-title" value="SI" value-title="SI"/></item>				</items>
			</table-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<load from="point.address" key="trm_location"/>
				<set key="availabilities" value="0"/>
				<set key="chassis_no" value=""/>
				<set key="summ" value="1"/>
				<set key="actionType" value="getCountries"/>
				<set key="service_name" value="rovinieta"/>
				<goto target="select_category"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="previous"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Select category -->
	<screen id="select_category" type="selector/image" title="Alege categoria">
		<fields>
			<selector-field id="category" title="Categorii autoturisme">
				<items type="static">
					<item value="1" title="Autoturisme" image="rovinieta_cat1.png"/>
					<item value="2" title="Transport marfa cu 0,0t mai mic MTMA mai mic egal 3,5t" image="rovinieta_cat2.png"/>
					<item value="3" title="Transport marfa cu 3,5t mai mic MTMA mai mic egal 7,5t" image="rovinieta_cat3.png"/>
					<item value="4" title="Transport marfa cu 7,5t mai mic MTMA mai mic 12,0t" image="rovinieta_cat4.png"/>
					<item value="5" title="Transport marfa cu MTMA mai mare egal 12,0t, cu maximum 3 axe (inclusiv)" image="rovinieta_cat5.png"/>
					<item value="6" title="Transport marfa cu MTMA mai mare egal 12,0t, cu minimum 4 axe (inclusiv)" image="rovinieta_cat6.png"/>
					<item value="7" title="Vehicule de transport persoane cu 9-23 locuri pe scaune (inclusiv conducatorul auto" image="rovinieta_cat7.png"/>
					<item value="8" title="Vehicule de transport persoane cu mai mult de 23 de locuri pe scaune (inclusiv conducatorul auto)" image="rovinieta_cat8.png"/>
				</items>
			</selector-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<online-request type="default" function="get_availabilities" params="availabilities,category,actionType,service_name">
					<actions>
						<goto-action type="success" target="select_availabilities"/>
						<action type="error">
							<dialog type="Info" title="Eroare" message="Lista produselor este inaccesibila momentan" timeout="10" default="okay">
								<actions>
									<action type="okay" title="OK">
										<cancel/>
									</action>
								</actions>
							</dialog>
						</action>
					</actions>
				</online-request>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_country"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Select availabilities -->
	<screen id="select_availabilities" type="table" title="Alege durata dorita">
		<fields>
			<table-field id="tf" title="Tabel" read-only="false">
				<columns>
					<column key="title" title="Durata" width="0.7"/>
					<column key="suma" title="Pret (RON)" width="0.3"/>
				</columns>
				<items type="data" key="#availabilities"/>
			</table-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto target="account"/>
				<set key="actionType" value=""/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_category"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Registration number -->
	<screen id="account" type="group" title="Registration Number">
		<fields>
			<text-field id="id1" keyboard="any:[en,symb]:upper:true" max-len="8" message="Introduceti numarul de inmatriculare" title="Numar de inmatriculare" default="">
				<validator type="regex">
					<rules>
						<rule regex=".*"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html><center>Introduceti numarul de inmatriculare]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<!-- no chassis number required for 1 or 7 days -->
				<if condition="days gt 7">
					<then>
						<goto target="set_chassis_number"/>
					</then>
					<else>
						<goto target="set_phone_number"/>
					</else>
				</if>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_availabilities"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Input chassis number -->
	<screen id="set_chassis_number" type="group" title="Numar sasiu">
		<fields>
			<text-field id="chassis_no" keyboard="any:[en,symb]:lower:true" max-len="17" message="Introduceti seria sasiului" title="Serie sasiu" default="">
				<validator type="regex">
					<rules>
						<rule regex="[a-zA-Z0-9]{17}"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html><center>Introduceti seria sasiului]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto target="set_phone_number"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Input phone number -->
	<screen id="set_phone_number" type="numeric" title="Telefon">
		<fields>
			<text-field id="phone_number" keyboard="Digital" prefix="07" max-len="10" title="Numarul de telefon">
				<validator type="regex">
					<rules>
						<rule regex="^07(\d{8})$"/>
					</rules>
				</validator>
				<formatter type="regex">
					<rules default="**** *** ***"/>
				</formatter>
				<help>
					<![CDATA[<html>Introduceti numarul de telefon.]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Achita">
				<set key="email" value="-"/>
				<if condition="days gt 7">
					<then>
						<dialog type="Info" title="Info" message="Doriti sa primiti notificare pe email de la CNAIR la expirarea rovinietei?" timeout="10" default="cancel" mess-params="name">
							<actions>
								<action type="okay" title="Da">
									<goto target="emailaddress"/>
								</action>
								<action type="cancel" title="Nu">
									<goto target="set_date_from"/>
								</action>
							</actions>
						</dialog>
					</then>
				<else>
					<goto target="set_date_from"/>
				</else>
				</if>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Adresa de email -->
	<screen id="emailaddress" type="group" title="Email">
		<fields>
			<text-field id="email" keyboard="any:[en,symb]:lower:true" max-len="99" message="Introduceti adresa de email" title="Email" default="">
				<validator type="regex">
					<rules>
						<rule regex="^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html><center>Introduceti a adresa de email valida]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto target="set_date_from"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Choose start date -->
	<screen id="set_date_from" type="date" title="Alegeti data de start">
		<fields>
			<date-field id="valid_from" title="Valid de la" format="yyyy-MM-dd" format-title="yyyy-MM-dd" from="2022-01-01" to="2052-12-31"/>
		</fields>
		<actions>
			<action type="Next" title="Achita">
				<if condition="is-not-null valid_from">
					<then>
					<online-request type="default" function="get_guid" params="id1,iso_code,value,category,chassis_no,valid_from,service_name,email">
						<actions>
							<action type="success">
								<if condition="code == 0">
									<then>
										<goto target="confirm"/>
									</then>
									<else>
										<dialog type="Info" title="Eroare" message="Eroare: {0}" timeout="10" default="okay" mess-params="exception">
											<actions>
												<action type="okay" title="OK">
													<cancel/>
												</action>
											</actions>
										</dialog>
									</else>
								</if>
							</action>
							<action type="error">
								<dialog type="Info" title="Eroare" message="A intervenit o eroare, va rugam sa verificati toate datele" timeout="10" default="okay">
									<actions>
										<action type="okay" title="OK">
											<cancel/>
										</action>
									</actions>
								</dialog>
							</action>
						</actions>
					</online-request>
				</then>
					<else>
						<dialog type="Info" title="Eroare" message="Alegeti data de start" timeout="10" default="okay">
							<actions>
								<action type="okay" title="OK">
									<cancel/>
								</action>
							</actions>
						</dialog>
					</else>
				</if>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="set_phone_number"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Confirmare -->
	<screen id="confirm" type="confirm" title="Confirmare">
		<fields list="registration_number,phone_number,chassis_number2,guid,country,valid_from,title,price"/>
		<actions>
<!--			<action type="Next" title="Achita">-->
<!--				<set-sum from="summ" type="units"/>-->
<!--				<goto target="pay"/>-->
<!--			</action>-->
			<action type="Next" title="Achita">
				<set-sum from="price" type="units"/>
				<dialog type="Info" title="Info" message="Sunteti de acord cu prelucrarea datelor cu caracter personal in scopuri de marketing?" timeout="10" default="cancel" mess-params="name">
					<actions>
						<action type="okay" title="Da">
							<set key="gdpr" value="1"/>
							<goto target="pay"/>
						</action>
						<action type="cancel" title="Nu">
							<set key="gdpr" value="0"/>
							<goto target="pay"/>
						</action>
					</actions>
				</dialog>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>
</scenario>
