/* Generated by MyraPad at 29/11/2020 23:50:42 */
using System;
using Myra.Graphics2D.UI;
using Sledgemapper.Shared.Entities;

namespace Sledgemapper.UI
{
    public partial class NoteWindow
    {
        private readonly Window Window;
        private readonly CommunicationManager CommunicationManager;
        private readonly Note Note;
        public NoteWindow(CommunicationManager communicationManager, Window window, Note note)
        {
            BuildUI();
            NoteText.Text = note.Text;
            Note = note;
            Window = window;
            CommunicationManager = communicationManager;
            BtnOk.Click += OnButtonNoteOkClick;
            BtnCancel.Click += OnButtonNoteCancelClick;
        }

        private void OnButtonNoteOkClick(object sender, EventArgs e)
        {
            var button = ((TextButton)sender);
            var localContent = button.GetParentContentInWindow<NoteWindow>();
            var note = new Note
            {
                X = State.Instance.SelectedNote.X,
                Y = State.Instance.SelectedNote.Y,
                Text = localContent.Content.NoteText.Text
            };
            CommunicationManager.SessionData.NewNote(note);
            localContent.Window.Close();
        }

        private void OnButtonNoteCancelClick(object sender, EventArgs e)
        {
            var button = ((TextButton)sender);
            var content = button.GetParentContentInWindow<Widget>();
            content.Window.Close();
        }
    }
}