using System;
using PostCardHitsuji.DataClient.Model;
using Hitsuji.Framework.Utils;

namespace PostCardHitsuji.Ui.RowPanel
{
    public partial class GroupFloatRowPanel : BaseFloatPanel
    {
        public GroupFloatRowPanel()
        {
            InitializeComponent();

            this.Load += new EventHandler(onLoad);
        }

        protected void onLoad(object sender, EventArgs ev)
        {
            this.BackColor = base.BackColor;
            attachAttribute_Color(this.label2);
            attachAttribute_Color(this.checkBoxEnable);

        }

        protected override void notifyModelChanged()
        {
            prepareUiControls();
            modelToUi();
        }

        protected override void notifyPropertyChanged(object sender, EventArgs ev)
        {

        }

        /// <summary>
        /// ＵＩ上のコンボボックスのオブジェクトにアイテム準備
        /// </summary>
        private void prepareUiControls()
        {

        }

        /// <summary>
        /// データ移動　ＵＩからモデルへ
        /// </summary>
        /// <param name="model"></param>
        public void uiToModel(Hitsuji.Framework.DataClient.Model.IContentModel refModel)
        {
            var mod = refModel as GroupContentModel;
            mod.Id = (this.Model as GroupContentModel).Id;
            mod.Enable = checkBoxEnable.Checked.ToString().ToUpper();
            mod.group = textBoxGroup.Text;
        }

        /// <summary>
        /// データ移動　モデルからＵＩへ
        /// </summary>
        private void modelToUi()
        {
            var model_ = Model == null ? new GroupContentModel() : Model as GroupContentModel;
            this.checkBoxEnable.Checked = bool.Parse(model_.Enable);
            this.textBoxGroup.Text = ValueUtil.tryGetString(model_.group);
        }

        protected override void margeUiToModel(Hitsuji.Framework.DataClient.Model.IContentModel refModel)
        {
            uiToModel(refModel);
        }
    }
}
