/* ----------------------------------------
 * Origin  : Akkodis
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : V2.12
 * DM-ID : Redmine#11103 : 25/03/2025 : LBE : Radio spectro interface added
 * Version : V2.13
 * DM-ID : redmine#12153 : 09/09/2025 : LBE : added WIND radio spectro
 * ----------------------------------------
 */
package fr.tlse.irap.pt.client.controller.tools.radio;

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.common.SpaceElementCollection;
import fr.tlse.irap.spaceElement.Probe;
import fr.tlse.irap.tool.radial.CMEType;

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

    static final String CHOOSE_MAP = "Choose map";
    static final String CHOOSE_CATALOG = "Choose Catalogue";
    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_MODEL = "Select density model";
    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";
    public static final String CLICK_POINTS_FILE = "Load file of points";
    public static final String SAVE_POINTS_FILE = "Save points";
    public static final String FIT_POINTS = "Fit points";
    public static final String FIT_POINTS_MANN = "Mann 2023";
    public static final String FIT_POINTS_LEBLANC = "Leblanc 1998";

    private RadioRadialltemBuilder() {
    }

    /**
     * Define choose map menu
     *
     * @param pMap triggering method mapping
     * @param pRadioMenuImpl Object triggering menu
     * @return Created menu to add
     */
    public static Item getChooseMapItem(Map<Item, ISelectedItem> pMap, final IRadioMenu pRadioMenuImpl) {
        /* Define main Choose map menu */
        Item chooseMapItem = new Item(CHOOSE_MAP);

        for (final RadioRadialModel.Instrument instr : RadioRadialModel.Instrument.values()) {
            if (SpaceElementCollection.getSpaceElementWrapper() != null) {
                //System.out.println("Loading ************* " + SpaceElementCollection.getSpaceElementWrapper() + " " + instr);
                Probe obs = SpaceElementCollection.getSpaceElementWrapper().getProbe(instr.getObs());
                if (obs.isDefined()) {
                    Item obsItem = new Item(instr.getObs());
                    pMap.put(obsItem, new ISelectedItem() {
                        @Override
                        public void run() {
                            pRadioMenuImpl.runChooseMap(instr.getObs(), instr.getName());
                        }
                    });
                    chooseMapItem.add(obsItem);
                }
            }
        }

        return chooseMapItem;
    }

    /**
     * Build Add Fit items
     */
    public static Item getAddInSituItem(Map<Item, ISelectedItem> map, final IRadioMenu pRadioMenu) {
        Item lAddItem = new Item(SELECT_MODEL);
        /* Childs */
        Item lItem1 = new Item(FIT_POINTS_MANN);
        lAddItem.add(lItem1);
        map.put(lItem1, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runMannInSituLine();
            }
        });
        Item lItem2 = new Item(FIT_POINTS_LEBLANC);
        lAddItem.add(lItem2);
        map.put(lItem2, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runLeblancInSituLine();
            }
        });

        return lAddItem;
    }

    public static Item getChooseCatalogItem(Map<Item, ISelectedItem> map, final IRadioMenu pRadioMenu) {
        Item chooseCatalog = new Item(CHOOSE_CATALOG);
        Item wp3Item = new Item("HELCATS HIGeoCAT");
        chooseCatalog.add(wp3Item);
        for (final CMEType cmeType : CMEType.values()) {
            //Item item = new Item("HELCATS " + cmeType.getName());
            Item item = new Item(cmeType.getName());
            map.put(item, new ISelectedItem() {
                @Override
                public void run() {
                    pRadioMenu.runChooseCatalog(false, cmeType);
                }
            });
            wp3Item.add(item);
        }
        Item wp4Item = new Item("HELCATS LINKCAT");
        chooseCatalog.add(wp4Item);
        Item item = new Item(CMEType.SSE.getName());
        map.put(item, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runChooseCatalog(true, CMEType.SSE);
            }
        });
        wp4Item.add(item);
        //chooseCatalog.add(item);
        return chooseCatalog;
    }

    /**
     * Build Add Fit items
     */
    public static Item getAddFitItem(Map<Item, ISelectedItem> map, final IRadioMenu pRadioMenu) {
        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() {
                pRadioMenu.runClickPoints();
            }
        });
        Item removeLastPointItem = new Item(REMOVE_LAST_POINT);
        addFitItem.add(removeLastPointItem);
        map.put(removeLastPointItem, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runRemoveLastPoint();
            }
        });
        Item clickPointsFileItem = new Item(CLICK_POINTS_FILE);
        addFitItem.add(clickPointsFileItem);
        map.put(clickPointsFileItem, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runClickPointsFile();
            }
        });
        Item savePointsFileItem = new Item(SAVE_POINTS_FILE);
        addFitItem.add(savePointsFileItem);
        map.put(savePointsFileItem, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runSavePoints();
            }
        });
        Item fitPointsItem = new Item(FIT_POINTS);
        addFitItem.add(fitPointsItem);

        Item fitPoints1Item = new Item(FIT_POINTS_MANN);
        map.put(fitPoints1Item, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runMannFitPoints();
            }
        });
        fitPointsItem.add(fitPoints1Item);
        Item fitPoints2Item = new Item(FIT_POINTS_LEBLANC);
        map.put(fitPoints2Item, new ISelectedItem() {
            @Override
            public void run() {
                pRadioMenu.runLeblancFitPoints();
            }
        });
        fitPointsItem.add(fitPoints2Item);

        return addFitItem;
    }

    /**
     * Build items of Zoom
     */
    public static Item getZoomItem(Map<Item, ISelectedItem> map, final IRadioMenu 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;
    }

}
