@using Radzen.Blazor.Rendering
@implements IDisposable

@inherits AxisBase
<CascadingValue Value="@this">
  @ChildContent
</CascadingValue>
@code {
    [Parameter]
    public string? Name { get; set; }

    internal double Measure(RadzenChart chart)
    {
        if (chart.ShouldInvertAxes())
        {
            return AxisMeasurer.YAxis(chart.ValueScale, chart.CategoryAxis, chart.CategoryAxis.Title);
        }
        else if (Visible == false)
        {
            return 0;
        }
        else
        {
            return AxisMeasurer.YAxis(chart.ValueScale, chart.ValueAxis, Title);
        }
    }

    internal double Measure(RadzenChart chart, ScaleBase scale)
    {
        if (Visible == false)
        {
            return 0;
        }

        return AxisMeasurer.YAxis(scale, this, Title);
    }

    internal override double Size
    {
        get
        {
            return Chart != null ? Measure(Chart) : 0;
        }
    }

    protected override void Initialize()
    {
        if (Chart != null)
        {
            if (string.IsNullOrEmpty(Name))
            {
                Chart.ValueAxis = this;
            }
            else
            {
                Chart.AddValueAxis(Name, this);
            }
        }
    }

    public void Dispose()
    {
        if (Chart != null && !string.IsNullOrEmpty(Name))
        {
            Chart.RemoveValueAxis(Name);
        }
    }
}
