using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace qtcnet_client.Controls
{
    public partial class RoomControl : UserControl
    {
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string RoomId { get; set; } = string.Empty;
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string RoomName { get; set; } = "Room";
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int UserCount { get; set; } = 0;
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public bool IsUserCountVisible { get; set; } = true;

        public event EventHandler? OnRoomDoubleClicked;

        bool _isHovering = false;
        public RoomControl()
        {
            InitializeComponent();

            AutoSize = false;
            Height = 59;
        }

        private void RoomControl_Load(object sender, EventArgs e)
        {
            lblRoomName.Text = RoomName;
            lblRoomUserCount.Text = UserCount.ToString();
            lblRoomUserCount.Visible = IsUserCountVisible;
        }

        private void lblRoomName_MouseHover(object sender, EventArgs e)
        {
            if (!_isHovering)
            {
                lblRoomName.ForeColor = Color.LightGray;
                _isHovering = true;
            }
        }

        private void lblRoomName_MouseLeave(object sender, EventArgs e)
        {
            if (_isHovering)
            {
                lblRoomName.ForeColor = Color.Black;
                _isHovering = false;
            }
        }

        private void lblRoomName_DoubleClick(object sender, EventArgs e) => OnRoomDoubleClicked?.Invoke(this, EventArgs.Empty);
    }
}
