﻿using AsmodeeDigital.PlayReal.Plugin.Utils;
using AsmodeeDigital.PlayReal.Samples.Views;
using com.daysofwonder;
using System;
using UnityEngine;
using UnityEngine.UI;

namespace AsmodeeDigital.PlayReal.Samples.UI.LobbyPlayers
{
    /// <summary>
    /// Player lobby frame
    /// </summary>
    public class LobbyPlayerItem : MonoBehaviour
    {
        /// <summary>
        /// UI references of ChatItem
        /// </summary>
        [Serializable]
        public class UI
        {
            public Text PlayerName;
            public Button BuddyListButton;
            public Draggable Draggable;
        }

        /// <summary>
        /// UI instance
        /// </summary>
        public UI ui;

        /// <summary>
        /// Player associated to the UI player item
        /// </summary>
        public IPlayer Player;

        /// <summary>
        /// True if the LobbyPlayerItem is active in the view. If false, the instance is pooled
        /// </summary>
        public bool IsActive { get; set; }

        public void ShowPopupChangeBuddyState()
        {
            LobbyPlayersView.Instance.ShowPopupBudddy(Player.w_w_w_id);
        }

        public void OnPlayerPortraitCreated(Draggable draggableSource, Draggable draggableCreated)
        {
            Image playerPortrait = draggableCreated.GetComponent<Image>();
            draggableCreated.Data = Player;

            AvatarPortraitLoader.LoadPlayerAvatar((Player)Player, playerPortrait);
        }
    }
}
