// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Windows.Forms.Layout;

namespace System.Windows.Forms;

[DefaultProperty(nameof(FlowDirection))]
public class FlowLayoutSettings : LayoutSettings
{
    internal FlowLayoutSettings(IArrangedElement owner)
        : base(owner)
    {
    }

    public override LayoutEngine LayoutEngine => FlowLayout.Instance;

    [SRDescription(nameof(SR.FlowPanelFlowDirectionDescr))]
    [DefaultValue(FlowDirection.LeftToRight)]
    [SRCategory(nameof(SR.CatLayout))]
    public FlowDirection FlowDirection
    {
        get => FlowLayout.GetFlowDirection(Owner!);
        set
        {
            FlowLayout.SetFlowDirection(Owner!, value);
            Debug.Assert(FlowDirection == value, "FlowDirection should be the same as we set it");
        }
    }

    [SRDescription(nameof(SR.FlowPanelWrapContentsDescr))]
    [DefaultValue(true)]
    [SRCategory(nameof(SR.CatLayout))]
    public bool WrapContents
    {
        get => FlowLayout.GetWrapContents(Owner!);
        set
        {
            FlowLayout.SetWrapContents(Owner!, value);
            Debug.Assert(WrapContents == value, "WrapContents should be the same as we set it");
        }
    }

    public void SetFlowBreak(object child, bool value)
    {
        ArgumentNullException.ThrowIfNull(child);

        IArrangedElement element = LayoutEngine.CastToArrangedElement(child);
        if (GetFlowBreak(child) != value)
        {
            CommonProperties.SetFlowBreak(element, value);
        }
    }

    public bool GetFlowBreak(object child)
    {
        ArgumentNullException.ThrowIfNull(child);

        IArrangedElement element = LayoutEngine.CastToArrangedElement(child);
        return CommonProperties.GetFlowBreak(element);
    }
}
