using Managers;
using Offers;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace UI
{
    public class OfferCellController : MonoBehaviour
    {
        [SerializeField] TextMeshProUGUI durationText;
        [SerializeField] TextMeshProUGUI dateText;
        [SerializeField] TextMeshProUGUI rewardText;
        [SerializeField] TextMeshProUGUI animatorsCount;
        [SerializeField] TextMeshProUGUI clientName;
        [SerializeField] Image clientIcon;

        Offer offerData;

        public void SetData(Offer offer)
        {
            offerData = offer;

            int eventDurationValue = (int)(offer.EndTime - offer.StartTime).TotalMinutes;

            durationText.text = NumbersFormatter.FormatNumber(eventDurationValue / 60) + "h "
                + NumbersFormatter.FormatNumber(eventDurationValue % 60) + "m"; ;
            dateText.text = NumbersFormatter.FormatNumber(offer.StartTime.Day) + "."
                + NumbersFormatter.FormatNumber(offer.StartTime.Month) + "."
                + NumbersFormatter.FormatNumber(offer.StartTime.Year); 
            rewardText.text = offer.Reward.ToString() + "$";
            animatorsCount.text = offer.AnimatorsCount.ToString();
            clientName.text = offer.ClientName;
            clientIcon.sprite = offer.CustomerIcon;
        }

        public void CloseOffer()
        {
            GameManager.Instance.CloseOffer(offerData);
            gameObject.SetActive(false);
            Sound.SoundController.Instance.Play(SoundType.UIClick);
        }

        public void CancelOffer()
        {
            GameManager.Instance.CancelOffer(offerData);
            gameObject.SetActive(false);
            Sound.SoundController.Instance.Play(SoundType.UIClick);
        }
    }
}