using System;
using Mirror;
using TMPro;
using UnityEngine;

public class MyNetworkPlayer : NetworkBehaviour
{
    [Header("Connections")]
    [SerializeField] private TMP_Text _playerNameObject;
    [Header("Variables")]
    [SyncVar(hook = nameof(SetPlayerNameTagText))]
    [SerializeField]
    private string _displayName = "Missing Name";

    [SyncVar(hook = nameof(SetPlayerNameTagColor))]
    [SerializeField]
    private Color _playerColor = Color.black;
    
    [Server]
    public void SetDisplayName(string newDisplayName)
    {
        _displayName = newDisplayName;
    }

    [Server]
    public void SetPlayerColor(Color newPlayerColor)
    {
        _playerColor = newPlayerColor;
    }

    private void SetPlayerNameTagText(string oldText, string newText)
    {
        if (_playerNameObject != null)
        {
            _playerNameObject.text = newText;
        }
    }

    private void SetPlayerNameTagColor(Color oldColor, Color newColor)
    {
        if (_playerNameObject != null)
        {
            _playerNameObject.color = newColor;
        }
    }
}