using System;
using System.Drawing;
using System.Windows.Forms;

namespace PostCardHitsuji.Ui.RowPanel
{
    public partial class InfoRowPanel2 : BaseRowPanel
    {
        public event EventHandler OnButtonUpdateClickedEvent;
        public event EventHandler OnModelChangedEvent;
        public event EventHandler SettingModelToEditPanelEvent;
        

        public string Title
        {
            get { return labelTitle.Text; }
            set 
            { 
                labelTitle.Text = value;
                labelTitleInner.Text = value;
            }
        }
        public string Info
        {
            get { return richTextBoxInfo.Text; }
            set { richTextBoxInfo.Text = value; }
        }

        public Control EditPanel
        {
            get { return panelEditRow.Controls.Count == 0 ? null : panelEditRow.Controls[0]; }
            set
            { 
                panelEditRow.Controls.Clear();
                panelEditRow.Controls.Add(value);
                value.Dock = DockStyle.Fill;
            }
        }

        public InfoRowPanel2(int widthMultiple, int heightMultiple)
        {
            InitializeComponent();
            this.Size = new Size(this.Width * widthMultiple, this.Height * heightMultiple);
            init();

            settingEditDisplay(false);
        }

        public InfoRowPanel2()
        {
            InitializeComponent();
            init();

            settingEditDisplay(false);
        }

        private void init()
        {
            buttonEdit.Click += new EventHandler(buttonEdit_Click);
            buttonEndEdit.Click += new EventHandler(buttonEndEdit_Click);
            buttonUpdate.Click += new EventHandler(buttonUpdate_Click);
        }

        protected override void  OnControlAdded(ControlEventArgs e)
        {
 	         base.OnControlAdded(e);
             this.Margin = new Padding(1);
        }

        private void buttonEdit_Click(object sender, EventArgs ev)
        {
            settingEditDisplay(true);

        }

        private void buttonEndEdit_Click(object sender, EventArgs ev)
        {
            settingEditDisplay(false);

        }

        private void settingEditDisplay(bool isEditDisplay)
        {
            if (isEditDisplay)
            {
                tableLayoutPanel1.ColumnStyles[0].Width = 0;
                tableLayoutPanel1.ColumnStyles[1].Width = this.Width;
                if (SettingModelToEditPanelEvent != null)
                    SettingModelToEditPanelEvent(this, EventArgs.Empty);
            }
            else
            {
                tableLayoutPanel1.ColumnStyles[0].Width = this.Width;
                tableLayoutPanel1.ColumnStyles[1].Width = 0;
            }
        }

        private void buttonUpdate_Click(object sender, EventArgs ev)
        {
            if (OnButtonUpdateClickedEvent != null)
                OnButtonUpdateClickedEvent(this, ev);
        }

        protected override void notifyModelChanged()
        {
            if (OnModelChangedEvent != null)
                OnModelChangedEvent(this, EventArgs.Empty);
        }

    }
}
