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

	<!-- Taxa Calarasi -->
	<screen id="select_category" type="selector/image" title="Categoria">
		<fields>
			<selector-field id="category" title="Categorii autoturisme">
				<items type="static">
					<item value="0" title="3,5 - 7,00 tone" image="calarasi_cat_1.png"/>
					<item value="1" title="7,01 - 12,00 tone" image="calarasi_cat_2.png"/>
					<item value="2" title="12,01 - 20,00 tone" image="calarasi_cat_3.png"/>
					<item value="3" title="mai mare 20 tone" image="calarasi_cat_4.png"/>
				</items>
			</selector-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto type="success" target="select_availabilities"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="exit"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Select availabilities -->
	<screen id="select_availabilities" type="selector/button" title="Alege durata dorita">
		<fields>
			<selector-field id="duration" message="Selectati durata" title="Durata">
				<items type="static">
					<item value="0" title="1 zi"/>
					<item value="1" title="1 luna"/>
				</items>
			</selector-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<set key="valid_from" value="$now{yyyy-MM-dd}" value-title="$now{yyyy-MM-dd}" />
				<goto target="set_date_from"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_category"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<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="Inainte">
				<goto target="select_access_type"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_availabilities"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- access type -->
	<screen id="select_access_type" type="selector/button" title="Alege durata dorita">
		<fields>
			<selector-field id="access_type" message="Selectati tipul de acces" title="Acces">
				<items type="static">
					<item value="0" title="Limitat"/>
					<item value="1" title="Nelimitat"/>
				</items>
			</selector-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto target="set_phone_number"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="set_date_from"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Input phone number -->
	<screen id="set_phone_number" type="numeric" title="Numar de 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><center>Introduceti numarul de telefon]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto target="account"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_access_type"/>
			</action>
			<action type="Exit" title="Acasa">
				<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]:lower:true" max-len="8" message="Introduceti numarul de inmatriculare" title="Numar de inmatriculare" default="">
				<validator type="regex">
					<rules>
						<rule regex="[a-zA-Z]{1,2}[0-9]{2,3}[a-zA-Z]{3}"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html><center>Introduceti numarul de inmatriculare]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Achita">
				<online-request type="default" function="check_request" params="category,duration,valid_from,access_type,phone_number,id1">
					<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>
			</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_no,category,duration,start_date,end_date,access_type,phone_number,price,commission,price_total"/>
		<actions>
			<action type="Next" title="Achita">
				<set-sum from="price_total" 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>
