using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee;

public class ZigBeeConfigUserControl : UserControlBase, IConfigurable
{
	private ZigBeeConfigSettings zigBeeConfigSettings;

	private IContainer components;

	private Label labelDefault15p4NVMFile;

	private TextBox textBoxDefault15p4NvmFile;

	private Button buttonChooseDefault15p4NvmFile;

	public ZigBeeConfigUserControl(ZigBeeConfigSettings zigBeeConfigSettings)
		: base("Config")
	{
		this.zigBeeConfigSettings = zigBeeConfigSettings;
		InitializeComponent();
	}

	public Configuration GetConfiguration()
	{
		Configuration configuration = new Configuration();
		configuration.SetString("DefaultZigBeeNVMFile", zigBeeConfigSettings.DefaultZigBeeNVMFile);
		return configuration;
	}

	public void SetConfiguration(Configuration configuration)
	{
		zigBeeConfigSettings.DefaultZigBeeNVMFile = configuration.GetString("DefaultZigBeeNVMFile", "");
		textBoxDefault15p4NvmFile.Text = zigBeeConfigSettings.DefaultZigBeeNVMFile;
	}

	private void buttonChooseDefault15p4NvmFile_Click(object sender, EventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.Filter = "NVM Files (*.nvm)|*.nvm| All Files (*.*)|*.*";
		if (openFileDialog.ShowDialog() == DialogResult.OK)
		{
			zigBeeConfigSettings.DefaultZigBeeNVMFile = openFileDialog.FileName;
			textBoxDefault15p4NvmFile.Text = zigBeeConfigSettings.DefaultZigBeeNVMFile;
		}
	}

	private void textBoxDefault15p4NvmFile_TextChanged(object sender, EventArgs e)
	{
		zigBeeConfigSettings.DefaultZigBeeNVMFile = textBoxDefault15p4NvmFile.Text;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.labelDefault15p4NVMFile = new System.Windows.Forms.Label();
		this.textBoxDefault15p4NvmFile = new System.Windows.Forms.TextBox();
		this.buttonChooseDefault15p4NvmFile = new System.Windows.Forms.Button();
		base.SuspendLayout();
		this.labelDefault15p4NVMFile.AutoSize = true;
		this.labelDefault15p4NVMFile.Location = new System.Drawing.Point(29, 34);
		this.labelDefault15p4NVMFile.Name = "labelDefault15p4NVMFile";
		this.labelDefault15p4NVMFile.Size = new System.Drawing.Size(74, 13);
		this.labelDefault15p4NVMFile.TabIndex = 0;
		this.labelDefault15p4NVMFile.Text = "15.4 NVM File";
		this.textBoxDefault15p4NvmFile.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
		this.textBoxDefault15p4NvmFile.Location = new System.Drawing.Point(109, 31);
		this.textBoxDefault15p4NvmFile.Name = "textBoxDefault15p4NvmFile";
		this.textBoxDefault15p4NvmFile.Size = new System.Drawing.Size(320, 20);
		this.textBoxDefault15p4NvmFile.TabIndex = 1;
		this.textBoxDefault15p4NvmFile.TextChanged += new System.EventHandler(textBoxDefault15p4NvmFile_TextChanged);
		this.buttonChooseDefault15p4NvmFile.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
		this.buttonChooseDefault15p4NvmFile.Location = new System.Drawing.Point(435, 29);
		this.buttonChooseDefault15p4NvmFile.Name = "buttonChooseDefault15p4NvmFile";
		this.buttonChooseDefault15p4NvmFile.Size = new System.Drawing.Size(26, 23);
		this.buttonChooseDefault15p4NvmFile.TabIndex = 2;
		this.buttonChooseDefault15p4NvmFile.Text = "...";
		this.buttonChooseDefault15p4NvmFile.UseVisualStyleBackColor = true;
		this.buttonChooseDefault15p4NvmFile.Click += new System.EventHandler(buttonChooseDefault15p4NvmFile_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.buttonChooseDefault15p4NvmFile);
		base.Controls.Add(this.textBoxDefault15p4NvmFile);
		base.Controls.Add(this.labelDefault15p4NVMFile);
		base.Name = "ZigBeeConfigUserControl";
		base.Size = new System.Drawing.Size(525, 300);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
