package _VisualDVM.Visual.Windows;
import Common.Utils.Utils_;
import Common.Visual.Trees.TreeForm;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.SapforData.Arrays.UI.DimensionsTableForm;
import _VisualDVM.ProjectData.SapforData.Arrays.UI.RulesTree;
import _VisualDVM.Visual.Interface.VariantsWindow;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class VariantsForm implements VariantsWindow {
    public JSplitPane SC4;
    public JSplitPane SC5;
    //--
    public TreeForm distributionForm1;
    private JButton BDistributed;
    private JButton bMultiplied;
    private JPanel dimensionsPanel;
    private JPanel distributionPanel;
    // private JLabel SelectedVariantsCount;
    private JLabel VisibleVariantsCount;
    private JLabel TotalVariantsCount;
    private JPanel variantsPanel;
    private JPanel content;
    private JToolBar variantsFilterTools1;
    private DimensionsTableForm dimensionsForm;
    //--
    public VariantsForm() {
        LoadSplitters();
        Global.mainModule.getProject().parallelVariants.mountUI(variantsPanel);
        distributionForm1 = new TreeForm(RulesTree.class, distributionPanel);
        dimensionsForm = new DimensionsTableForm(dimensionsPanel);
        //-
        BDistributed.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Global.mainModule.getProject().SwitchFilterDistributed();
                BDistributed.setIcon(Utils_.getIcon(Global.mainModule.getProject().f_distributed() ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
                ShowVariantsFilter();
                ShowFilteredVariantsCount();
            }
        });
        bMultiplied.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Global.mainModule.getProject().SwitchFilterMultiplied();
                bMultiplied.setIcon(Utils_.getIcon(Global.mainModule.getProject().f_multiplied() ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
                ShowVariantsFilter();
                ShowFilteredVariantsCount();
            }
        });
    }
    @Override
    public JPanel getContent() {
        return content;
    }
    @Override
    public void ShowProjectDistribution() {
        distributionForm1.Show();
    }
    @Override
    public void ShowNoProjectDistribution() {
        distributionForm1.Clear();
    }
    @Override
    public void ShowVariantsFilterButtons() {
        BDistributed.setIcon(Utils_.getIcon(Global.mainModule.getProject().f_distributed() ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
        bMultiplied.setIcon(Utils_.getIcon(Global.mainModule.getProject().f_multiplied() ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
    }
    @Override
    public void ShowVariantsFilter() {
        dimensionsForm.Show();
    }
    @Override
    public void ShowNoVariantsFilter() {
        dimensionsForm.Clear();
    }
    @Override
    public void ShowFilteredVariantsCount() {
        VisibleVariantsCount.setText(String.valueOf(Global.mainModule.getProject().getFilteredVariantsCount()));
    }
    @Override
    public void ShowTotalVariantsCount() {
        TotalVariantsCount.setText(String.valueOf(Global.mainModule.getProject().getTotalVariantsCount()));
    }
    @Override
    public void ShowVariants() {
        Global.mainModule.getProject().parallelVariants.ShowUI();
    }
    @Override
    public void RefreshVariants() {
        Global.mainModule.getProject().parallelVariants.getUI().RedrawControl();
    }
    @Override
    public void ShowNoVariants() {
        Global.mainModule.getProject().parallelVariants.ClearUI();
    }
    @Override
    public void ShowNoFilteredVariantsCount() {
        VisibleVariantsCount.setText("0");
    }
    @Override
    public void ShowNoTotalVariantsCount() {
        TotalVariantsCount.setText("0");
    }
}
