/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 07/01/2022 : LBE : V2.4
 * DM-ID : Redmine#9098 : 07/01/2022 : creation
 * Version : 12/09/2023 : LBE : V2.8
 * DM-ID : Redmine#10629 : 12/09/2023 : SEP plot improvments
 * Version : 25/11/2024 : LBE : V2.11
 * DM-ID : Redmine#11104 : 25/11/2024 : VDA module added
 * ----------------------------------------
 */
package fr.tlse.irap.pt.client.controller.tools.plot;

import java.util.Map;

import fr.tlse.irap.pt.client.controller.common.ISelectedItem;
import fr.tlse.irap.pt.client.controller.common.Item;
import fr.tlse.irap.pt.client.controller.tools.jmap.IJMapMenu;
import java.util.List;
import javafx.scene.chart.LineChart;

/**
 *
 * JMap contextual menu builder
 *
 */
public class SpectroPlotItemBuilder {

    public static final String ZOOM = "Zoom";
    public static final String ZOOM_SET = "Set zoom";
    public static final String ZOOM_RESET = "Reset";
    static final String SELECT_FIT = "Select fit by click";
    static final String ADD_FIT = "Add fit points";
    static final String CLICK_POINTS = "Enter points by click";
    static final String REMOVE_LAST_POINT = "Remove last point";
    static final String CLICK_POINTS_FILE = "Load file of points";
    static final String SAVE_POINTS_FILE = "Save points";
    static final String FIT_POINTS = "Fit points";

    //private static List<String> energyTable = new ArrayList<String>();
    //private static List<Float[]> energyTable = new ArrayList<Float[]>();
    //private static Map<FluxType, List<FluxMeasure>> fluxTypeMeasures = new HashMap<FluxType, List<FluxMeasure>>();
    /**
     * Init flare flux type measures
     */
    /*private static void initEnergyTable(List<Float[]> pNrgs) {
        energyTable = pNrgs;
    }*/
    /**
     * Define catalogue menu
     *
     * @param map
     * @return
     */
    public static Item getShowNrjsItem(List<Float[]> energyTable,
            Map<Item, ISelectedItem> map, final ISpectroPlotMenu pSpectroPlotMenu) {
        Item catItem = new Item("Show/Hide energies");
//        Item lSpectroItem = new Item("Show spectro/energies");
//        map.put(lSpectroItem, new ISelectedItem() {
//            @Override
//            public void run() {
//                pSpectroPlotMenu.runShowSpectro(SpectroPlotComponent.ESEPPlotTool.TIMESERIES);
//            }
//        });
//        catItem.add(lSpectroItem);
        Item lAllNrjItem = new Item("Show/hide all energies");
        map.put(lAllNrjItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runShowAllEnergies();
            }
        });
        catItem.add(lAllNrjItem);
        int i = 0;
        for (final Float[] fRange : energyTable) {
            Item ftItem = new Item(fRange[0] + "-" + fRange[1]);
            final int lIdx = i;
            map.put(ftItem, new ISelectedItem() {
                @Override
                public void run() {
                    //pSpectroPlotMenu.runShowAllFlux(fType);
                    pSpectroPlotMenu.runShowEnergy(lIdx);
                }
            });
            catItem.add(ftItem);
            i++;
        }
        return catItem;
    }

    public static Item getShowSpectraItem(Map<Item, ISelectedItem> map, final ISpectroPlotMenu pSpectroPlotMenu) {
        Item catItem = new Item("Display type");
        Item lSpectroItem = new Item("Energy spectrogram");
        map.put(lSpectroItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runShowSpectro(SpectroPlotComponent.ESEPPlotTool.SPECTRA);
            }
        });
        catItem.add(lSpectroItem);
        lSpectroItem = new Item("1/beta spectrogram");
        map.put(lSpectroItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runShowSpectro(SpectroPlotComponent.ESEPPlotTool.VDA);
            }
        });
        catItem.add(lSpectroItem);
        lSpectroItem = new Item("Time series");
        map.put(lSpectroItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runShowSpectro(SpectroPlotComponent.ESEPPlotTool.TIMESERIES);
            }
        });
        catItem.add(lSpectroItem);

        return catItem;
    }


    /**
     * Build Add Fit items
     */
    public static Item getAddFitItem(Map<Item, ISelectedItem> map, final ISpectroPlotMenu pSpectroPlotMenu) {
        Item addFitItem = new Item(ADD_FIT);
        /* Childs */
        Item clickPointsItem = new Item(CLICK_POINTS);
        addFitItem.add(clickPointsItem);
        map.put(clickPointsItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runClickPoints();
            }
        });
        Item removeLastPointItem = new Item(REMOVE_LAST_POINT);
        addFitItem.add(removeLastPointItem);
        map.put(removeLastPointItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runRemoveLastPoint();
            }
        });
        Item clickPointsFileItem = new Item(CLICK_POINTS_FILE);
        addFitItem.add(clickPointsFileItem);
        map.put(clickPointsFileItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runClickPointsFile();
            }
        });
        Item savePointsFileItem = new Item(SAVE_POINTS_FILE);
        addFitItem.add(savePointsFileItem);
        map.put(savePointsFileItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runSavePoints();
            }
        });
        Item fitPointsItem = new Item(FIT_POINTS);
        addFitItem.add(fitPointsItem);
        map.put(fitPointsItem, new ISelectedItem() {
            @Override
            public void run() {
                pSpectroPlotMenu.runFitPoints();
            }
        });

        return addFitItem;
    }

    /**
     * Build items of Zoom
     */
    public static Item getZoomItem(Map<Item, ISelectedItem> map, final ISpectroPlotMenu pPlotMenu) {
        Item zoomItem = new Item(ZOOM);
        Item selectT1Item = new Item(ZOOM_SET);
        zoomItem.add(selectT1Item);
        map.put(selectT1Item, new ISelectedItem() {
            @Override
            public void run() {
                pPlotMenu.runSetZoom();
            }
        });
//        Item selectT2Item = new Item(ZOOM_T2);
//        zoomItem.add(selectT2Item);
//        map.put(selectT2Item, new ISelectedItem() {
//            @Override
//            public void run() {
//                flarePlotMenu.runZoomT2();
//            }
//        });
        Item ResetItem = new Item(ZOOM_RESET);
        zoomItem.add(ResetItem);
        map.put(ResetItem, new ISelectedItem() {
            @Override
            public void run() {
                pPlotMenu.runResetZoom();
            }
        });

        return zoomItem;
    }

}
