package com.sas.jobindsats.ui.playground;

import java.util.ArrayList;

import org.dom4j.rule.Mode;

import wicket.Component.IVisitor;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.DropDownChoice;
import wicket.markup.html.form.Form;
import wicket.markup.html.form.Radio;
import wicket.markup.html.form.RadioGroup;
import wicket.markup.html.list.ListItem;
import wicket.markup.html.list.ListView;
import wicket.markup.html.panel.Panel;
import wicket.model.IModel;
import wicket.model.Model;

import com.sas.jobindsats.ui.DataItemRendererNew;

public class RadioDropdown extends Panel {

	private ListView myList;

	private ArrayList myControlList = new ArrayList();

	private int radio_selected = -1;

	private int radio_current = 0;

	private ArrayList dropdownList = new ArrayList();

	Form myform;

	public RadioDropdown(String arg0) {
		super(arg0);
		myform = new Form("form");

		// add radiogroup
		// add listview
		RadioGroup myRadio = new RadioGroup("radiogroup") {
			protected void onSelectionChanged(Object newSelection) {
				// nr i in array list is selected
				int i = Integer.parseInt(newSelection.toString());
				radio_selected=i;
				/*
				for (int j = 0; j < dropdownList.size(); j++) {
					DropDownChoice myChoice = (DropDownChoice) dropdownList
							.get(j);
					if (j == i) {
						myChoice.setEnabled(true);

					} else {
						myChoice.setEnabled(false);
						myChoice.setModel(new Model());
					}

				}
*/
			}

			protected boolean wantOnSelectionChangedNotifications() {
				return true;
			}

		};
		Model radioModel = new Model();
		myRadio.setModel(radioModel);

		myform.add(myRadio);
		myList = new ListView("myListView", myControlList) {
			protected void onBeginPopulateItem(ListItem arg0) {
				// TODO Auto-generated method stub
				super.onBeginPopulateItem(arg0);
				radio_current = 0;
			}

			public void populateItem(final ListItem item) {
				ArrayList container = (ArrayList) item.getModelObject();

				String RadioLabel = (String) container.get(0);
				ArrayList ListChoiceArray = (ArrayList) container.get(1);

				Radio radio = new Radio("radio");
				Model RadioModel = new Model();

				RadioModel.setObject(radio_current + "");
				radio.setModel(RadioModel);
				

				Label lbl_Radio = new Label("radiolabel", RadioLabel);

				radio.add(lbl_Radio);
				item.add(radio);

				DropDownChoice DropChoice = new DropDownChoice("dropdown",
						ListChoiceArray, new DataItemRendererNew());
				if (!(radio_current == radio_selected)) {
					DropChoice.setEnabled(false);
				}
				item.add(DropChoice);
				//dropdownList.add(DropChoice);
				radio_current++;
			}
		};

		myRadio.add(myList);
		this.add(myform);

	}

	public RadioDropdown(String arg0, IModel arg1) {
		super(arg0, arg1);

		// TODO Auto-generated constructor stub
	}

	public boolean addControl(Object arg0) {
		return myControlList.add(arg0);
	}

}
