/**
 * 
 */
package view.FactoryPrincipale;

import language.Francais;
import language.Language;
import view.Fenetre;
import view.OngletDeGauche;
import view.OngletSuperieur;
import view.vueRapportArriveeDepart.VueRapportArriveeDepart;
import view.vueRapportDepot.VueRapportDepot;
import view.vueRapportFacture.VueRapportFacture;
import view.vueRapportFermeture.VueRapportFermeture;
import view.vueRapportStatistique.VueRapportStatistique;
import view.vueRechercheArticle.VueRechercheArticle;
import view.vueRechercheChambre.VueRechercheChambre;
import view.vueRechercheClient.VueRechercheClient;
import view.vueRechercheFacture.VueRechercheFacture;
import view.vueRechercheFermeture.VueRechercheFermeture;
import view.vueRechercheGroupe.VueRechercheGroupe;
import view.vueRechercheReservation.VueRechercheReservation;
import view.vueRechercheUtilisateur.VueRechercheUtilisateur;
import view.vueRechercheVille.VueRechercheVille;
import view.vueSelectorDateChambre.SelecteurDateChambre;
import controler.Controler;
import controler.plan.ControlerPlan;
import controler.rapport.ControlerRapportArriveDepart;
import controler.rapport.ControlerRapportDepot;
import controler.rapport.ControlerRapportFacture;
import controler.rapport.ControlerRapportFermeture;
import controler.rapport.ControlerRapportStatistique;
import controler.recherche.ControlerRechercheChambreLibre;
import controler.recherche.ControlerRechercheClient;
import controler.recherche.ControlerRechercheFacture;
import controler.recherche.ControlerRechercheFermeture;
import controler.recherche.ControlerRechercheGroupe;
import controler.recherche.ControlerRecherchePromotionArticle;
import controler.recherche.ControlerRechercheReservation;
import controler.recherche.ControlerRechercheUtilisateur;
import controler.recherche.ControlerRechercheVille;

/**
 * @author alexis
 *
 */
public class PrincipaleSpectateurFactory implements PrincipaleFactory {

	/**
	 * 
	 */
	public PrincipaleSpectateurFactory() {}
	
	public static OngletDeGauche buildPlan(Language lang){
		//creer les vue
		SelecteurDateChambre vuePlan = new SelecteurDateChambre(lang,null);
		//creer la tab
		OngletDeGauche principePlan = new OngletDeGauche();
		//creer la soustab
		principePlan.addJPanelObservable(lang.getPrincipalePlan(), vuePlan, ControlerPlan.reveil);
		//ajouter l observateur
		principePlan.getObservable().addObserver(Controler.getInstance());
		vuePlan.getObservable().addObserver(Controler.getInstance());
		//connecter le boutton
		vuePlan.connecterUneAction("SelectionDate", ControlerPlan.reveil);
		//retourner la tab
		return principePlan;
	}
	
	public static OngletDeGauche buildRecherche(Language lang) throws Exception{
		//creer les vue
		VueRechercheClient vueRechercheClient = new VueRechercheClient(lang,null);
		VueRechercheChambre vueRechercheChambre = new VueRechercheChambre(lang,null);
		VueRechercheReservation vueRechercheReservation = new VueRechercheReservation(lang,null);
		VueRechercheFacture vueRechercheFacture = new VueRechercheFacture(lang,null);
		VueRechercheFermeture vueRechercheFermeture = new VueRechercheFermeture(lang,null);
		VueRechercheGroupe vueRechercheGroupe = new VueRechercheGroupe(lang,null);
		VueRechercheUtilisateur vueRechercheUtilisateur = new VueRechercheUtilisateur(lang,null);
		VueRechercheArticle vueRechercheArticle = new VueRechercheArticle(lang,null);
		VueRechercheVille vueRechercheVille = new VueRechercheVille(lang,null);
		//creer la tab
		OngletDeGauche principeRecherche = new OngletDeGauche();
		//creer les sous tab
		principeRecherche.addJPanelObservable(lang.getRechercheClient(), vueRechercheClient, ControlerRechercheClient.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheChambre(), vueRechercheChambre, ControlerRechercheChambreLibre.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheReservation(), vueRechercheReservation, ControlerRechercheReservation.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheFacture(), vueRechercheFacture, ControlerRechercheFacture.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheFermeture(), vueRechercheFermeture, ControlerRechercheFermeture.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheGroupe(), vueRechercheGroupe, ControlerRechercheGroupe.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheUtilisateur(), vueRechercheUtilisateur, ControlerRechercheUtilisateur.reveil);
		principeRecherche.addJPanelObservable(lang.getRechercheArticPromo(), vueRechercheArticle, ControlerRecherchePromotionArticle.reveil);
		principeRecherche.addJPanelObservable(lang.getRecherche_Ville(), vueRechercheVille, ControlerRechercheVille.reveil);
		//ajouter les observateurs
		principeRecherche.getObservable().addObserver(Controler.getInstance());

		vueRechercheClient.getObservable().addObserver(Controler.getInstance());
		vueRechercheChambre.getObservable().addObserver(Controler.getInstance());
		vueRechercheReservation.getObservable().addObserver(Controler.getInstance());
		vueRechercheFacture.getObservable().addObserver(Controler.getInstance());
		vueRechercheFermeture.getObservable().addObserver(Controler.getInstance());
		vueRechercheGroupe.getObservable().addObserver(Controler.getInstance());
		vueRechercheUtilisateur.getObservable().addObserver(Controler.getInstance());
		vueRechercheArticle.getObservable().addObserver(Controler.getInstance());
		vueRechercheVille.getObservable().addObserver(Controler.getInstance());
		//connecter les bouttons
		vueRechercheClient.addButton(lang.getRechercheClient_Recherche(), ControlerRechercheClient.recherche);
		vueRechercheChambre.addButton(lang.getRechercheChambre_Recherche(), ControlerRechercheChambreLibre.recherche);
		vueRechercheReservation.addButton(lang.getRechercheReservation_Recherche(), ControlerRechercheReservation.recherche);
		vueRechercheFacture.addButton(lang.getRechercheFacture_Recherche(),ControlerRechercheFacture.recherche);
		vueRechercheFermeture.addButton(lang.getRechercheFermeture_Recherche(),ControlerRechercheFermeture.recherche);
		vueRechercheGroupe.addButton(lang.getRechercheGroupe_Recherche(), ControlerRechercheGroupe.recherche);
		vueRechercheUtilisateur.addButton(lang.getRechercheUtilisateur_Recherche(), ControlerRechercheUtilisateur.recherche);
		vueRechercheArticle.addButton(lang.getRechercheArticle_Recherche(),ControlerRecherchePromotionArticle.recherche);
		vueRechercheVille.addButton(lang.getRechercheVille_Recherche(), ControlerRechercheVille.recherche);
		//retourner la tab
		return principeRecherche;
	}
	
	public static OngletDeGauche buildRapport(Language lang) throws Exception{
		//creer les vue
		VueRapportArriveeDepart vueRapportArriveeDepart = new VueRapportArriveeDepart(lang,null);
		VueRapportFermeture vueRapportFermeture = new VueRapportFermeture(lang,null);
		VueRapportDepot vueRapportDepot = new VueRapportDepot(lang,null);
		VueRapportFacture vueRapportFacture = new VueRapportFacture(lang,null);
		VueRapportStatistique vueRapportStatistique = new VueRapportStatistique(lang,null);
		//creer la tab 
		OngletDeGauche principeRapport = new OngletDeGauche();
		//creer les soustabs
		principeRapport.addJPanelObservable( lang.getRapportArrivDepart(), vueRapportArriveeDepart, ControlerRapportArriveDepart.imprimer);
		principeRapport.addJPanelObservable( lang.getRapportFermeture(), vueRapportFermeture, ControlerRapportFermeture.imprimer);
		principeRapport.addJPanelObservable( lang.getRapportDepot(), vueRapportDepot, ControlerRapportDepot.imprimer);
		principeRapport.addJPanelObservable( lang.getRapportFacture(), vueRapportFacture, ControlerRapportFacture.imprimer);
		principeRapport.addJPanelObservable( lang.getRapportStatistique(), vueRapportStatistique, ControlerRapportStatistique.imprimer);
		//ajouter les observateurs
		principeRapport.getObservable().addObserver(Controler.getInstance());

		vueRapportArriveeDepart.getObservable().addObserver(Controler.getInstance());
		vueRapportFermeture.getObservable().addObserver(Controler.getInstance());
		vueRapportDepot.getObservable().addObserver(Controler.getInstance());
		vueRapportFacture.getObservable().addObserver(Controler.getInstance());
		vueRapportStatistique.getObservable().addObserver(Controler.getInstance());
		//ajouter des bouttons
		vueRapportArriveeDepart.addButton(lang.getRapportArrivDepartRefresh(), ControlerRapportArriveDepart.reveil);
		vueRapportArriveeDepart.addButton(lang.getRapportArrivDepartImprimer(), ControlerRapportArriveDepart.imprimer);
		vueRapportFermeture.addButton(lang.getRapportFermetureImprimer(), ControlerRapportFermeture.imprimer);
		vueRapportFermeture.addButton(lang.getRapportFermetureSelection(), ControlerRapportFermeture.selectionner);
		vueRapportFacture.addButton(lang.getRapportFactureImprimer(), ControlerRapportFacture.imprimer);
		vueRapportFacture.addButton(lang.getRapportFactureRechercher(), ControlerRapportFacture.rechercher);
		vueRapportDepot.addButton(lang.getRapportDepotImprimer(), ControlerRapportDepot.imprimer);
		vueRapportDepot.addButton(lang.getRapportDepotSelection(), ControlerRapportDepot.selectionner);
		vueRapportStatistique.addButton(lang.getRapportStatistiqueImprimer(), ControlerRapportStatistique.imprimer);

		//retourner la tab
		return principeRapport;
	}
	
	public OngletSuperieur build(Language lang) throws Exception{
		OngletSuperieur principe = new OngletSuperieur();

		/*onglet plan*/
		principe.addSubTab(lang.getPrincipalePlan(), buildPlan(lang));

		/*onglet recherche*/
		principe.addSubTab(lang.getPrincipaleRecherche(), buildRecherche(lang));

		/*onglet rapport*/
		principe.addSubTab(lang.getPrincipaleRapport(), buildRapport(lang));

		/*preloader la page courrante*/
		principe.setSelectedTab(lang.getPrincipalePlan(), lang.getPrincipalePlan());
		
		return principe;
	}
	
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		Fenetre a = new Fenetre(Francais.getInstance(),"Denise Rivard");
		a.setPrincipale(new PrincipaleSpectateurFactory().build(Francais.getInstance()));
		a.setNom("Billy");
		a.setEnteteVisible(true);
	}
}