using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;

public class SellScreenController : MonoBehaviour {

    private UIDocument _document;
    
    private Label _itemNameLabel;
    private Label _paidPriceLabel;
    private TextField _YourPriceInputfield;
    
    private SellCounter _counter;
    private Object _sellingObject;

    
    //Becase we set the gameobject to active false, we need to use Awake
    private void Awake() {
        _document = GetComponent<UIDocument>();
        _itemNameLabel = _document.rootVisualElement.Q<Label>("ItemName");
        _document.rootVisualElement.Q<Button>("SellButton").clicked += SellItem;
        
        _paidPriceLabel = _document.rootVisualElement.Q<Label>("PriceLabel");
        _YourPriceInputfield = _document.rootVisualElement.Q<TextField>("YourPrice");

        if (_itemNameLabel == null) {
            Debug.LogError("Item name not found");
        }
    }
    //TODO: ask how to do this, since the gameobjec that renders the ui is not active
    public void SetItem(SellCounter counter, Object @object) {
        _counter = counter;
        _sellingObject = @object;
        _paidPriceLabel.text = @object.ObjectSo.basePrice.ToString();
        _itemNameLabel.text = @object.ObjectSo.objectName;
    }

    public void SellItem() {
        _counter.ConfirmSell(_sellingObject);
        HUDManager.Instance.HideCurrentHUD();
        //Sell the item
        //Trigger an event that the item was sold
        
        Debug.Log("Selling: " + _itemNameLabel.text);
    }

}