using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using Games.ChatHistory;
using GCGame.Table;
using Games.GlobeDefine;
using GCGame;
using Module.Log;
using Games.Item;

public class ChatInfoLogSysItem : ChatInfoLogItem
{

    public override float GetItemHeight()
    {
        return _ChatInfo.preferredHeight + 20;
    }
    
    protected override bool SetDetailLog()
    {
        ClearChat();
        if (_ChatHistory.ChatInfo[0] == '#')
        {
            _ModifiedStr = StrDictionary.GetServerDictionaryFormatString(_ChatHistory.ChatInfo);
        }
        else
        {
            _ModifiedStr = _ChatHistory.ChatInfo;
        }
        GetAllChatLinks(_ChatHistory);
        _ModifiedStr = GetLinkedStr(_ChatHistory);

        _ChatInfo.text = _ModifiedStr;
        _ChatInfo.CalculateLayoutInputHorizontal();
        _ChatInfo.CalculateLayoutInputVertical();

        LoadAssetBundle.Instance.SetImageSprite(_CannelIcon, GetCannelStr(_ChatHistory.EChannel));

        SetBGWidth();

        StartCoroutine(WaitLayout());
        return true;
    }

    protected override void SetBGWidth()
    {
        if (_LayoutElement == null)
            return;

        float bgWidth = _ChatInfoBGMinSize.x;
        if (_ChatInfo.preferredWidth + 20 > bgWidth && _ChatInfo.preferredWidth + 20 < _ChatInfo.rectTransform.sizeDelta.x)
        {
            bgWidth = _ChatInfo.preferredWidth + 20;
        }
        else if (_ChatInfo.preferredWidth + 20 > _ChatInfo.rectTransform.sizeDelta.x)
        {
            bgWidth = _ChatInfo.rectTransform.sizeDelta.x + 20;
        }

        _LayoutElement.minHeight = _ChatInfo.preferredHeight + 20;
        _LayoutElement.minWidth = gameObject.GetComponent<RectTransform>().sizeDelta.x;
    }


}