using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using InABox.Core;

namespace InABox.DynamicGrid
{
    public class ScriptEditorControl : DynamicEditorControl<string>
    {
        private Button Editor;

        private string script = "";

        public ScriptEditorControl()
        {
            SyntaxLanguage = SyntaxLanguage.CSharp;
        }

        public SyntaxLanguage SyntaxLanguage { get; set; }

        protected override FrameworkElement CreateEditor()
        {
            Editor = new Button
            {
                Content = "Edit..",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Stretch,
                VerticalContentAlignment = VerticalAlignment.Center,
                Width = 50
            };
            Editor.Click += Editor_Click;

            return Editor;
        }

        private void Editor_Click(object sender, RoutedEventArgs e)
        {
            var editor = new ScriptEditor(script, SyntaxLanguage);
            if (editor.ShowDialog() == true)
            {
                script = editor.Script;
                CheckChanged();
            }
        }

        public override int DesiredHeight()
        {
            return 25;
        }

        public override int DesiredWidth()
        {
            return 100;
        }

        protected override string RetrieveValue()
        {
            return script;
        }

        protected override void UpdateValue(string value)
        {
            script = value;
        }

        public override void SetFocus()
        {
            Editor.Focus();
        }

        public override void SetColor(Color color)
        {
            //Editor.Background = new SolidColorBrush(color);
        }
    }
}