using System;
using System.Windows.Forms;
using FastReport.Utils;

namespace FastReport.AdvMatrix
{
    public partial class MatrixCollapseButton
    {
        private void CreateMenuItems()
        {
            ContextMenuStrip menu = new ContextMenuStrip();
            ToolStripItem collapseAll = menu.Items.Add(Res.Get("Designer,ToolWindow,CollapseAll"));
            collapseAll.Tag = this;
            collapseAll.Click += CollapseAll_Click;
            ToolStripItem expandAll = menu.Items.Add(Res.Get("Designer,ToolWindow,ExpandAll"));
            expandAll.Tag = this;
            expandAll.Click += ExpandAll_Click;
            menu.Show(Cursor.Position);
        }

        private void ExpandAll_Click(object sender, EventArgs e)
        {
            MatrixCollapseButton btn = (sender as ToolStripItem).Tag as MatrixCollapseButton;
            if (Matrix != null)
            {
                if (IsColumn)
                    Matrix.ToggleColumnVisible(btn.Index, false, true);
                else
                    Matrix.ToggleRowVisible(btn.Index, false, true);
            }
            Report.Preview.RefreshReport();
        }

        private void CollapseAll_Click(object sender, EventArgs e)
        {
            MatrixCollapseButton btn = (sender as ToolStripItem).Tag as MatrixCollapseButton;
            if (Matrix != null)
            {
                if (IsColumn)
                    Matrix.ToggleColumnVisible(btn.Index, true, false);
                else
                    Matrix.ToggleRowVisible(btn.Index, true, false);
            }
            Report.Preview.RefreshReport();
        }

        /// <inheritdoc/>
        public override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button == MouseButtons.Right && ShowCollapseExpandMenu)
            {
                CreateMenuItems();
                return;
            }

            if (Matrix != null)
            {
                if (IsColumn)
                    Matrix.ToggleColumnVisible(Index);
                else
                    Matrix.ToggleRowVisible(Index);
                Report.Refresh();
            }
        }
      
    }
    public partial class MatrixSortButton
    {
        /// <inheritdoc/>
        /// <inheritdoc/>
        public override void OnClick(EventArgs e)
        {
            MatrixSortButtonClick();
        }

    }
}