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

    <!-- Load Info Page
    ID: 201 / 1201 - Aquavas Vaslui
    Smith & Smith
    -->
    <screen type="Void" id="LoadInfo">
        <actions>
            <action type="Next">
                <set key="#file" value="file://smith.html" />
                <goto target="InfoPage"/>
            </action>
        </actions>
    </screen>

    <!-- Info -->
    <screen id="InfoPage" type="info" title="Informare">
        <field key="#file" />
        <actions>
            <action type="Next">
                <goto target="StepOne"/>
            </action>
            <action type="Prev">
                <goto target="previous"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Codul de client
    - Sa contina doar cifre;
    - Sa fie pana in 10 caractere;
    - Sa permita continuarea la indeplinirea a 7 caractere;
    -->
    <screen id="StepOne" type="numeric" title="Introduceti codul de client">
        <fields>
            <text-field id="id1" keyboard="Digital" max-len="11" title="Cod client">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{7,11}$"/>
                    </rules>
                </validator>
                <help>
                    <![CDATA[<html>Prin continuarea tranzactiei va dati acordul pentru plata unui comision de <b>3 RON</b> pentru procesarea acestei plati;]]>
                </help>
            </text-field>
        </fields>
        <actions>
            <action type="Next">
                <goto target="StepTwo"/>
            </action>
            <action type="Prev">
                <goto target="InfoPage"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Numarul de factura
    - Sa contina doar cifre;
    - Sa fie pana in 10 caractere;
    - Sa permita continuarea daca se ajunge la 7 caractere;
    -->
    <screen id="StepTwo" type="numeric" title="Introduceti numarul facturii">
        <fields>
            <text-field id="id2" keyboard="Digital" max-len="10" title="Numar factura">
                <validator type="regex">
                    <rules>
                        <rule regex="^(\d{7,10})$"/>
                    </rules>
                </validator>
                <help>
                    <![CDATA[<html>Prin continuarea tranzactiei va dati acordul pentru plata unui comision de <b>3 RON</b> pentru procesarea acestei plati;]]>
                </help>
            </text-field>
        </fields>
        <actions>
            <action type="Next">
                <goto target="PhoneNumber"/>
            </action>
            <action type="Prev">
                <goto target="StepOne"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Numarul de telefon
    - Sa contina prefixul 07, doar retea mobila;
    - Sa fie lungimea maxima 10 impreuna cu prefixul;
    - Sa permita continuarea doar la indeplinirea celor 10 caractere;
    -->
    <screen id="PhoneNumber" type="numeric" title="Introduceti numarul de telefon">
        <fields>
            <text-field id="id3" keyboard="Digital" max-len="10" title="Numarul de telefon">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{10}$"/>
                    </rules>
                </validator>
                <formatter type="regex">
                    <rules default="**** *** ***"/>
                </formatter>
                <help>
                    <![CDATA[<html>Prin continuarea tranzactiei va dati acordul pentru plata unui comision de <b>3 RON</b> pentru procesarea acestei plati;]]>
                </help>
            </text-field>
        </fields>
        <actions>
            <action type="Next">
                <set key="service_name" value="AquaVas"/>
                <online-request type="default" function="check_request" params="id1,id2,id3,service_name">
                    <actions>
                        <action type="success">
                            <if condition="code == 0">
                                <then>
                                    <goto target="ConfirmPage"/>
                                </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 incercati din nou" timeout="10" default="okay">
                                <actions>
                                    <action type="okay" title="OK">
                                        <cancel/>
                                    </action>
                                </actions>
                            </dialog>
                        </action>
                    </actions>
                </online-request>
            </action>
            <action type="Prev">
                <goto target="StepTwo"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Confirm -->
    <screen id="ConfirmPage" type="confirm" title="Verificati corectitudinea datelor introduse">
        <fields list="id1,id2,id3"/>
        <actions>
            <action type="Next" title="Achita">
                <clear keys="#file"/>
                <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="StepOne"/>
            </action>
            <action type="Exit" title="Acasa">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
</scenario>
