<?xml version="1.0" encoding="UTF-8"?>
<scenario begin="LoadInfo">
    
    <!-- Load Info Page
    ID: 96 / 1096 - Apavital
    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 litere si cifre;
    - Primul caracter este U sau A sau P urmat de 5 pana la 7 cifre
    - Sa permita continuarea doar la indeplinirea minimului de caractere;
    -->
    <screen id="StepOne" type="group" title="Introduceti codul de client">
        <fields>
            <text-field id="id1" keyboard="any:[en]:lower:true" max-len="8" title="Codul de client">
                <validator type="regex">
                    <rules>
                        <rule regex="^.\d{4,8}$"/>
                    </rules>
                </validator>
                <help>
                    <![CDATA[<html>Introduceti codul de client <strong>(primul caracter este o litera, deobicei U, A sau P)</strong> urmat de 5 pana la 7 cifre.]]>
                </help>
            </text-field>
        </fields>
        <actions>
            <action type="Next">
              <if condition="id1 ~ ^[a-zA-Z]\d{5,7}$">
                  <then>
                      <online-request type="default" function="invoices" params="id1">
                        <actions>
                          <goto-action type="success" target="InvoicesList"/>
                          <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>
                  </then>
                  <else>
                      <dialog type="Info" title="Info" message="Codul de client este gresit, va rugam sa verificati datele introduse" timeout="10" default="okay">
                          <actions>
                              <action type="okay" title="OK">
                                  <cancel/>
                              </action>
                          </actions>
                      </dialog>
                  </else>
              </if>
            </action>
            <action type="Prev">
                <goto target="InfoPage"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
    
    <screen id="InvoicesList" type="table" title="Alege tara">
      <fields>
        <table-field id="tf" title="Tabel" read-only="false">
          <columns>
            <column key="title" title="Nr. Factura" width="0.7"/>
            <column key="date" title="Data emitere" width="0.7"/>
            <column key="sum" title="Sold" width="0.3"/>
          </columns>
          <items type="data" key="#invoices"/>
        </table-field>
      </fields>
      <actions>
        <action type="Next" title="Inainte">
          <goto target="PhoneNumber"/>
        </action>
        <action type="Prev" title="Inapoi">
          <goto target="previous"/>
        </action>
        <action type="Exit" title="Pagina principala">
          <goto target="exit"/>
        </action>
      </actions>
    </screen>
    
    <!-- Numarul de factura
    - Sa contina prefixul ENG;
    - Sa fie lungimea maxima 15 impreuna cu prefixul;
    - Sa fie numarul de factura pana in 11 cifre, Engie mai are un zero libere;
    -->
    <screen id="StepTwo" type="numeric" title="Introduceti numarul de factura">
        <fields>
            <text-field id="id2" keyboard="Digital" prefix="ENG" max-len="15" title="Numarul de factura">
                <validator type="regex">
                    <rules>
                        <rule regex="^ENG(\d{11,12})$"/>
                    </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">
                <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 cifre;
    -->
    <screen id="PhoneNumber" type="numeric" title="Introduceti numarul de telefon">
        <fields>
            <text-field id="id3" 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>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="ConfirmPage"/>
            </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,sum,title"/>
        <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>
