from ..common.utils import NoWheelDoubleSpinBox
from .base_parameter_control import BaseParameterControl


class IntensityControlBox(BaseParameterControl):
    def __init__(self, parent=None):
        super().__init__(title="Intensity Filter Settings", parent=parent)

        self.intensityFrac = NoWheelDoubleSpinBox()
        self.intensityFrac.setMinimum(0)
        self.intensityFrac.setValue(0.9999)

        self.thermalFactor = NoWheelDoubleSpinBox()
        self.thermalFactor.setMinimum(0)
        self.thermalFactor.setToolTip("""
            Factor to compensate the thermal decrease of intensity of high-angle rings.
            The higher this is, the more low-angle rings will be filtered by intensity
            and the less high-angle rings will be filtered by intensity.
            Typical range: 0.1 - 2
        """)
        self.thermalFactor.setValue(0.2)

        self.settingsLayout.addRow("Intensity Fraction", self.intensityFrac)
        self.settingsLayout.addRow("Thermal Factor", self.thermalFactor)

    def validate(self):
        if self.thermalFactor.value() == 0.0 or self.intensityFrac.value() == 0.0:
            raise ValueError(
                "Intensity Filter can't have thermal factor or intensity frac value 0.0"
            )
