﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace Xsolla
{
	public class SummaryItemView: MonoBehaviour
	{
		public Image mImgItem;
		public Text mItemName;
		public Text mAmount;
		public Text mDesc;

		public SummaryItemView ()
		{
		}
		
		public void init(XsollaUtils pUtils, IXsollaSummaryItem pItem, ImageLoader pLoader)
		{
			if (pItem is XsollaSummaryItem)
			{
				mItemName.text = pItem.GetName();
				String lUrl = (pItem.GetImgUrl()=="")?pUtils.GetProject().virtualCurrencyIconUrl:pItem.GetImgUrl();
				if (!lUrl.Contains("http"))
				{
					if (lUrl.Contains("//"))
						lUrl = "http:" + lUrl;
					else
						lUrl = "http://" + lUrl;
				}
				pLoader.LoadImage(mImgItem, lUrl);
				mAmount.text = pItem.GetPrice();
				mDesc.text = pItem.GetDescription();
				return;
			}

			if (pItem is XsollaSummarySubscription)
			{
				mImgItem.gameObject.SetActive(false);
				mItemName.text = pUtils.GetTranslations().Get("") + (pItem as XsollaSummarySubscription).GetName();
				mDesc.text = String.Format(StringHelper.PrepareFormatString(pUtils.GetTranslations().Get("subscription_charge_note_date")), pItem.GetDescription());
				return;
			}
		}
	}
}

