using Telerik.WinControls;
using Telerik.WinControls.UI;

namespace Pilz.UI.Telerik.Controls.RadValidationProvider;

public delegate void RadValidationEventHandlerEx(object sender, RadValidationEventArgsEx e);

public class RadValidationEventArgsEx : EventArgs
{
    const string DefaultToolTipTitle = "Validation Failed";
    private readonly Control control;
    private readonly IRadValidationRuleEx validationRule;
    private bool displayIconAndToolTip = true;
    private string errorTitle = DefaultToolTipTitle;
    private bool enableToolTipShadow = true;

    /// <summary>
    /// Gets or Sets the ValidationHelperElement descendant that contains the Error image. This element is set next to the validated control.
    /// </summary>
    public ValidationHelperElement ValidationHelperElement { get; set; }

    /// <summary>
    /// Gets or Sets the result from the rule evaluation.
    /// </summary>
    public bool IsValid { get; set; }

    /// <summary>
    /// Get the Control which is evaluated in the ValidationRule.
    /// </summary>
    public Control Control { get { return control; } }

    /// <summary>
    /// Error image that will displayed next to the Validated control.
    /// </summary>
    public Image ErrorImage { get; set; }
    /// <summary>
    /// Error SVG image that will displayed next to the Validated control.
    /// </summary>
    public RadSvgImage ErrorSvgImage { get; set; }
    /// <summary>
    /// Gets or sets the custom ToolTip for the Rule.
    /// </summary>
    public ToolTip ToolTip { get; set; }

    /// <summary>
    /// Sets the X position of the ToolTip.
    /// </summary>
    public int? ToolTipX { get; set; }

    /// <summary>
    /// Sets the Y position of the ToolTip.
    /// </summary>
    public int? ToolTipY { get; set; }

    /// <summary>
    /// Sets the ToolTip's duration in Milliseconds
    /// </summary>
    public int? ToolTipDuration { get; set; }

    /// <summary>
    /// The Rule that fires this event.
    /// </summary>
    public IRadValidationRuleEx ValidationRule { get { return validationRule; } }

    /// <summary>
    /// Sets or Gets the ToolTip's Text.
    /// </summary>
    public string ErrorText { get; set; }

    /// <summary>
    /// Sets or Gets the ToolTip's Title.
    /// </summary>
    public string ErrorTitle { get { return errorTitle; } set { errorTitle = value; } }

    /// <summary>
    /// Enable or Disable the Error border and error image.
    /// </summary>
    public bool DisplayIconAndToolTip { get { return displayIconAndToolTip; } set { displayIconAndToolTip = value; } }

    /// <summary>
    /// Enable or Disable the ToolTip shadow.
    /// </summary>
    public bool EnableToolTipShadow { get { return enableToolTipShadow; } set { enableToolTipShadow = value; } }

    /// <summary>
    /// Construct the RadValidationEventArgs object.
    /// </summary>
    /// <param name="control">The validated control. Must be RadEditorControl descendant</param>
    /// <param name="errorImage">Erorr image</param>
    /// <param name="errorText">Error text</param>
    /// <param name="errorTitle">Error title</param>
    /// <param name="validationRule">Validation rule</param>
    /// <param name="isFailed">Validatation failed</param>
    public RadValidationEventArgsEx(
        Control control,
        Image errorImage,
        string errorText,
        string errorTitle,
        IRadValidationRuleEx validationRule,
        bool isFailed)
    {
        this.control = control;
        ErrorImage = errorImage;
        ErrorText = errorText;
        this.validationRule = validationRule;
        IsValid = !isFailed;
        this.errorTitle = errorTitle;
    }
}
