using System;
using Pathfinding;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x020000AD RID: 173
public class GroundItemText : MonoBehaviour, IPointerUpHandler, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler
{
	// Token: 0x06000FCB RID: 4043 RVA: 0x0013093C File Offset: 0x0012EB3C
	private void Awake()
	{
		this.tr = base.transform;
		this.normalTextColor = this.txt.color;
		this.normalTextColor.a = 0.75f;
		this.txt.color = this.normalTextColor;
		this.imgColor = this.img.color;
		this.imgHoverColor = this.img.color;
		this.imgHoverColor.a = 0.75f;
	}

	// Token: 0x06000FCC RID: 4044 RVA: 0x001309B9 File Offset: 0x0012EBB9
	private void OnDisable()
	{
		this.active = false;
		this.worldPosition = Vector3.zero;
	}

	// Token: 0x06000FCD RID: 4045 RVA: 0x001309CD File Offset: 0x0012EBCD
	private void OnEnable()
	{
	}

	// Token: 0x06000FCE RID: 4046 RVA: 0x001309CF File Offset: 0x0012EBCF
	private void Update()
	{
		if (this.item && !this.item.destroying && this.item.active)
		{
			this.ItemText();
		}
	}

	// Token: 0x06000FCF RID: 4047 RVA: 0x00130A00 File Offset: 0x0012EC00
	public void ItemText()
	{
		this.str.Clear();
		bool flag = this.item.forSale;
		bool flag2 = false;
		bool flag3 = false;
		if (Links.x.main.body.sneaking)
		{
			flag2 = true;
		}
		if (flag2)
		{
			this.item.GetLinkedCharacter();
			if (this.item.linkedCharacter)
			{
				flag3 = this.item.CheckToSteal(false);
			}
			else
			{
				flag2 = false;
			}
		}
		if (this.item.forSale)
		{
			this.item.GetLinkedCharacter();
			if (!this.item.linkedCharacter)
			{
				this.item.forSale = false;
				flag = false;
			}
			if (this.item.linkedCharacter)
			{
				if (this.item.linkedCharacter.dead)
				{
					this.item.forSale = false;
					flag = false;
				}
				else if (this.item.linkedCharacter.stunned)
				{
					flag = false;
				}
			}
			if (flag2)
			{
				flag = false;
			}
		}
		this.str.Append(this.item.invRow._DisplayName);
		if (this.item.stackSize > 1)
		{
			this.str.Append(" (");
			this.str.Append(this.item.stackSize);
			this.str.Append(") ");
		}
		if (flag)
		{
			this.item.GetLinkedCharacter();
			float cost = this.item.GetCost(false, Links.x.main, this.item.linkedCharacter);
			if ((float)Links.x.inventory.emeralds < cost)
			{
				this.str.Append(" <color=#BF493B>(");
			}
			else
			{
				this.str.Append(" <color=#92C861>(");
			}
			this.txt.color = this.normalTextColor;
			this.str.Append(cost);
			this.str.Append("em");
			this.str.Append(")</color>");
		}
		else if (flag2)
		{
			if (flag3)
			{
				this.str.Append(" <color=#629AA4>(Steal)</color>");
			}
			else
			{
				this.str.Append(" <color=#BF493B>(Stealing would be seen or heard)</color>");
			}
			this.txt.color = this.normalTextColor;
		}
		else
		{
			this.txt.color = this.normalTextColor;
		}
		int length = this.txt.text.Length;
		if (length != this.letterCount)
		{
			this.letterCount = length;
			this.GetSize(length);
		}
		this.textColor = this.txt.color;
		this.txt.text = this.str.ToString();
	}

	// Token: 0x06000FD0 RID: 4048 RVA: 0x00130CA6 File Offset: 0x0012EEA6
	private void GetSize(int c)
	{
		this.rt.sizeDelta = new Vector2(this.txt.preferredWidth + 12f, this.rt.sizeDelta.y);
	}

	// Token: 0x06000FD1 RID: 4049 RVA: 0x00130CDC File Offset: 0x0012EEDC
	public void Set()
	{
		if (!this.item)
		{
			return;
		}
		this.ItemText();
		this.item.label = this;
		int length = this.txt.text.Length;
		this.img.enabled = true;
		this.worldPosition = Vector3.zero;
		this.screenPosition = Vector3.zero;
		this.GetSize(length);
		this.letterCount = length;
		if (Records.x.editor)
		{
			base.gameObject.name = this.item.gameObject.name;
		}
		this.active = true;
	}

	// Token: 0x06000FD2 RID: 4050 RVA: 0x00130D78 File Offset: 0x0012EF78
	public void TurnOff()
	{
		if (!this.tr)
		{
			this.tr = base.transform;
		}
		this.tr.position = new Vector3(100000f, 100000f, 0f);
		if (this.item)
		{
			this.item.label = null;
		}
		this.active = false;
		this.item = null;
		this.txt.text = "";
		this.worldPosition = Vector3.zero;
		this.screenPosition = Vector3.zero;
		this.uiPosition = Vector3.zero;
		this.hovering = false;
	}

	// Token: 0x06000FD3 RID: 4051 RVA: 0x00130E1C File Offset: 0x0012F01C
	public void OnPointerEnter(PointerEventData eventData)
	{
		Shader.SetGlobalFloat("_HoveringOnItem", 1f);
		if (Links.x.inventory.groundBag.toggle)
		{
			this.item.PostFXRenderers(true);
			this.hovering = true;
			this.img.color = this.imgHoverColor;
			Color color = this.txt.color;
			color.a = 1f;
			this.txt.color = color;
			Shader.SetGlobalFloat("_HoveringOnItem", 1f);
		}
	}

	// Token: 0x06000FD4 RID: 4052 RVA: 0x00130EA8 File Offset: 0x0012F0A8
	public void OnPointerExit(PointerEventData eventData)
	{
		if (!Links.x.inventory.groundBag.toggle)
		{
			Shader.SetGlobalFloat("_HoveringOnItem", 0f);
		}
		if (Links.x.inventory.groundBag.toggle)
		{
			if (this.item)
			{
				this.item.PostFXRenderers(false);
			}
			this.hovering = false;
			this.img.color = this.imgColor;
			Color color = this.txt.color;
			color.a = 0.75f;
			this.txt.color = color;
			return;
		}
		if (this.item && this.item != Links.x.gameplay.hitItem)
		{
			this.item.HoverOut();
		}
	}

	// Token: 0x06000FD5 RID: 4053 RVA: 0x00130F7C File Offset: 0x0012F17C
	public void OnPointerUp(PointerEventData eventData)
	{
		if ((Links.x.inventory.groundBag.toggle || this.hovering || Links.x.inventory.groundBag.IsPopItem(this.item)) && this.active && !Records.x.pocketPause && !Links.x.inventory.dragging && Links.x.hasMain)
		{
			Links.x.gameplay.StoneSoundQuieter();
			GraphNode dropNode = this.item.dropNode;
			if (this.item)
			{
				if (!this.item.destroying && this.item.active)
				{
					this.hovering = false;
				}
			}
			else
			{
				this.hovering = false;
			}
			if (Links.x.joy)
			{
				Links.x.gameplay.ItemPathFinished(this.item, Links.x.main);
			}
			else
			{
				Links.x.main.StartGetPathToTarget(dropNode, null, this.item, null, null, null, null, null, Links.x.main, null, Links.x.gameplay.CanScatterPartyToMakePath("Item"), true, false, "Item", false);
			}
			Links.x.gameplay.clickedCharacter = null;
		}
	}

	// Token: 0x04001A24 RID: 6692
	public Image img;

	// Token: 0x04001A25 RID: 6693
	public Canvas canvas;

	// Token: 0x04001A26 RID: 6694
	public TextMeshProUGUI txt;

	// Token: 0x04001A27 RID: 6695
	public RectTransform rt;

	// Token: 0x04001A28 RID: 6696
	public Item item;

	// Token: 0x04001A29 RID: 6697
	public bool active;

	// Token: 0x04001A2A RID: 6698
	public bool hovering;

	// Token: 0x04001A2B RID: 6699
	public Transform tr;

	// Token: 0x04001A2C RID: 6700
	private StringFast str = new StringFast(64);

	// Token: 0x04001A2D RID: 6701
	public Vector3 uiPosition;

	// Token: 0x04001A2E RID: 6702
	public Vector3 screenPosition;

	// Token: 0x04001A2F RID: 6703
	public Vector3 worldPosition;

	// Token: 0x04001A30 RID: 6704
	public Color normalTextColor;

	// Token: 0x04001A31 RID: 6705
	private Color imgColor;

	// Token: 0x04001A32 RID: 6706
	private Color imgHoverColor;

	// Token: 0x04001A33 RID: 6707
	private int letterCount;

	// Token: 0x04001A34 RID: 6708
	public Color textColor;
}
