using CtrEditor.ObjetosSim;
using Ookii.Dialogs.Wpf;
using System.Windows;
using System.Windows.Controls;
using Xceed.Wpf.Toolkit.PropertyGrid;

namespace CtrEditor.Controls
{
    public partial class PanelEdicionControl : UserControl
    {
        public PanelEdicionControl()
        {
            InitializeComponent();
        }

        public void CargarPropiedades(osBase selectedObject)
        {
            UserControlFactory.CargarPropiedadesosDatos(selectedObject, PropertyGridControl);
        }

        // Add a new method to clear properties
        public void ClearProperties()
        {
            UserControlFactory.LimpiarPropiedadesosDatos(PropertyGridControl);
        }

        public bool IsKeyboardFocusWithin => PropertyGridControl.IsKeyboardFocusWithin;
        
        public PropertyGrid PropertyGrid => PropertyGridControl;

        private void ImagePathButton_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new VistaOpenFileDialog
            {
                Filter = "Image files (*.png;*.jpg;*.bmp)|*.png;*.jpg;*.bmp|All files (*.*)|*.*"
            };

            if (dlg.ShowDialog() == true)
            {
                // El DataContext de este botón es el PropertyItem asociado
                if ((sender as Button)?.DataContext is PropertyItem propertyItem)
                {
                    propertyItem.Value = dlg.FileName;
                }
            }
        }
    }
}
