import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;

public class TestModule extends WebModule implements EntryPoint //Don't extend WebModule when sending to vendor
{
    private static String[][] cellValues = new String[][] { { "Engels, Taylor (7523483661-7523686071-RSIL) ", "" },
            { "", "" }, { "Total Customer Charge", "9.92711467999999" }, { "Total Energy Charge", "30.78482638608" },
            { "Total Demand Charge", "" }, { "Total Bill", "40.71194106608" }, { "if", "" }, { "Customer Count", "1" },
            { "end if", "" }, { "On Peak kW Qty", "" }, { "", "" }, { "Read Date", "20160406" },
            { "Current Month", "4" }, { "Weather Factor", "0.0098" }, { "", "" }, { "", "" }, { "CHIE", "6913" },
            { "PGE", "31900" }, { "Current Jurisdiction", "6913" }, { "if", "" }, { "Total Customers", "426005" },
            { "elseif", "" }, { "Total Customers", "" }, { "end if", "" }, { "Customer To Divide Rate By", "426005" },
            { "Weather Factor (For Posting Only)", "2.30044248306945E-08" }, { "", "" }, { "", "" }, { "", "" },
            { "", "" }, { "if", "" }, { "Active Demand?", "" }, { "end if", "" }, { "IS Rate Compare?", "" },
            { "if", "" }, { "Current RC", "" }, { "Rate Code of Sequence", "" }, { "if", "" }, { "kW Minimun", "" },
            { "Current Period", "" }, { "11 Periods Ago", "" }, { "", "" }, { "Total Demand In Past 12 Months?", "" },
            { "Total Active Bills In Past 12 Months?", "" }, { "", "" }, { "Avg Demand", "" }, { "", "" }, { "if", "" },
            { "Process Rate Compare", "" }, { "end if", "" }, { "else", "" }, { "Home Rate Code", "" },
            { "end if", "" }, { "else", "" }, { "Post", "1" }, { "end if", "" }, { "", "" }, { "if", "" },
            { "kW Price", "" }, { "Penalty For Not Meeting Minimum", "" }, { "if", "" },
            { "Amount To Add To Bill", "" }, { "end if", "" }, { "end if", "" }, { "Customer Group", "" }, { "", "" },
            { "if", "" }, { "Total Customer Charge", "9.92711467999999" }, { "Total Energy Charge", "30.78482638608" },
            { "Total Demand Charge", "" }, { "Facility Related Demand Charge", "" }, { "Total Bill", "40.71194106608" },
            { "CIS Total Bill", "40.71194106608" }, { "", "" }, { "Bill Components", "" },
            { "Customer Charge", "9.92711467999999" }, { "Energy Charge", "30.78482638608" }, { "Demand Charge", "" },
            { "Facility Related Demand Charge", "" }, { "Fuel Charge", "" },
            { "Total Bill w/ Riders & Fuel", "40.71194106608" }, { "Quantities For RD", "" },
            { "Block 1 or Base kWh Qty", "551.304" }, { "Block 2 kWh Qty", "" }, { "Block 3 kWh Qty", "" },
            { "On Peak kWh Qty", "220.5216" }, { "Mid Peak kWh Qty", "" }, { "Off Peak kWh Qty", "330.7824" },
            { "All kWh Qty", "551.304" }, { "On Peak kW Qty", "" }, { "Mid Peak kW Qty", "" },
            { "Off Peak kW Qty", "" }, { "All kW Qty", "" }, { "Block 1 or Base kWh Charge", "30.78482638608" },
            { "Block 2 kWh Charge", "" }, { "Block 3 kWh Charge", "" }, { "On Peak kWh Charge", "" },
            { "Off Peak kWh Charge", "" }, { "On Peak kW Charge", "" }, { "Total kWh Amount", "1102.608" },
            { "Weather Adjustment", "10.8055584" }, { "Bill Start Date", "20160306" }, { "Bill End Date", "20160406" },
            { "Billing Days", "31" } };

    public void onModuleLoad()
    {
                Canvas p = getMainPanel();
                p.draw();
    }


    public Canvas getMainPanel()
    {
        final ListGrid grid = new ListGrid()
        {

            @Override
            protected String getCellCSSText(ListGridRecord record, int rowNum, int colNum)
            {
                if (colNum == 0 && rowNum % 2 == 0)
                {
                    return "border: 1px solid #ebebeb !important; font-weight: bold;";
                }
                return "border: 1px solid #ebebeb !important;";
            }
        };

        ListGridField frozenField = new ListGridField("frozen1");
        frozenField.setFrozen(true);
        frozenField.setWidth(100);

        ListGridField unfrozenField = new ListGridField("unfrozen");
        unfrozenField.setWidth(100);

        grid.setWrapCells(true);
        grid.setFixedRecordHeights(false);
        grid.setCanFreezeFields(true);
        grid.setFields(frozenField, unfrozenField);

        ArrayList<TestRecord> records = new ArrayList<TestRecord>();
        for (String[] row : cellValues)
        {
            TestRecord record = new TestRecord(row);
            records.add(record);
        }
        grid.setRecords(records.toArray(new ListGridRecord[0]));
        grid.setHeight("75%");
        grid.setWidth("98%");

        HLayout panel = new HLayout();
        panel.setHeight("100%");
        panel.setWidth("100%");
        panel.addMember(grid);

        return panel;
    }

    private class TestRecord extends ListGridRecord
    {
        public TestRecord(String[] values)
        {
            this.setAttribute("frozen1", values[0]);
            this.setAttribute("unfrozen", values[1]);
        }
    }

}
