package com.fitbank.arreglos.formulario;

import com.fitbank.arreglos.ArregloFormulario;
import com.FitBank.xml.Formas.ListaTabs;
import com.FitBank.xml.Formas.ListaForms;
import com.FitBank.xml.Formas.Formulario;
import java.util.Iterator;

/**
 * Corrige la propiedad posicionTextos de acuerdo al estilo aplicado.
 *
 * @author FitBank CI
 */
public class ArregloPosicionTabs implements ArregloFormulario {

    public boolean arreglar(Formulario formulario) {
        boolean arreglado = false;

        Iterator<ListaTabs> iLT = formulario.iterator(ListaTabs.class);
        while (iLT.hasNext()) {
            ListaTabs elementoLT = iLT.next();
            arreglado |= arreglarPosicionLT(elementoLT);
        }
        Iterator<ListaForms> iLF = formulario.iterator(ListaForms.class);
        while (iLF.hasNext()) {
            ListaForms elementoLF = iLF.next();
            arreglado |= arreglarPosicionLF(elementoLF);
        }

        return arreglado;
    }

    public static boolean arreglarPosicionLT(ListaTabs elemento) {
        boolean arreglado = false;
        String estilo = elemento.getEstilo();
        int textoSize = Integer.parseInt("0" + elemento.getTarget(), 10);
        boolean cambiarEstilo = true;

        if (estilo.equalsIgnoreCase("LTabs")) {
            elemento.setPosicionTextos("D");
        } else if (estilo.equalsIgnoreCase("LTabsC")) {
            elemento.setPosicionTextos("C");
        } else if (estilo.equalsIgnoreCase("LTabsIzq")) {
            elemento.setPosicionTextos("I");
        } else {
            cambiarEstilo = false;
        }

        if (cambiarEstilo) {
            elemento.setEstilo("Tabs");
            arreglado = true;
        }
        if (textoSize < 10) {
            elemento.setTarget("10");
            arreglado = true;
        }

        return arreglado;
    }

    public static boolean arreglarPosicionLF(ListaForms elemento) {
        boolean arreglado = false;
        String estilo = elemento.getEstilo();
        int textoSize = Integer.parseInt("0" + elemento.getTarget(), 10);
        boolean cambiarEstilo = true;

        if (estilo.equalsIgnoreCase("LTabs")) {
            elemento.setPosicionTextos("D");
        } else if (estilo.equalsIgnoreCase("LTabsC")) {
            elemento.setPosicionTextos("C");
        } else if (estilo.equalsIgnoreCase("LTabsIzq")) {
            elemento.setPosicionTextos("I");
        } else {
            cambiarEstilo = false;
        }

        if (cambiarEstilo) {
            elemento.setEstilo("Tabs");
            arreglado = true;
        }
        if (textoSize < 10) {
            elemento.setTarget("10");
            arreglado = true;
        }

        return arreglado;
    }

}
