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

namespace Xsolla
{
	public class StatusVPElemController: MonoBehaviour
	{
		public Image mItemIcon;
		public Text mTextIcon;
		public Text mName;
		public Text mDesc;
		public ImageLoader mLoader;

		public StatusVPElemController ()
		{
		}

		public void init(String pName, String pDesc, String pUrl = null, String pTextIcon = null)
		{
			mTextIcon.text = pTextIcon;
			mTextIcon.gameObject.SetActive(pTextIcon != null);

			String lUrl = pUrl;

			// Загружаем картинку 
			if (lUrl != null)
			{
				if (!lUrl.Contains("http"))
				{
					if (lUrl.Contains("//")) 
						lUrl = "https:" + lUrl;
					else
						lUrl = "https://" + lUrl;
				}

				mLoader.LoadImage(mItemIcon, lUrl);		
			}
			else
				mItemIcon.gameObject.SetActive(false);

			mName.text = pName;

			if (pDesc != "")
				mDesc.text = pDesc;
			else
				mDesc.gameObject.SetActive(false);

		}
	}
}

