#pragma once

#include <Widgets/Definitions.h>
#include <Widgets/TabpanelBlueprint.h>
#include "../Base.h"
#include "../File.h"
#include "Placeholder.h"
#include "../Game/Animation.h"
#include "ResizableObject.h"

namespace gorgon { namespace widgets {

	class Tabpanel;

	Tabpanel *LoadTabpanel(Base *parent, File &file, std::istream &in, int Size);

	class Tabpanel : public gge::widgets::tabpanel::Blueprint, public Base {
		friend Tabpanel *LoadTabpanel(gorgon::Base *parent, File &file, std::istream &in, int Size);
	public:

		Tabpanel() {
			gge::utils::CheckAndDelete(Placeholder);
			Placeholder=new gorgon::widgets::Placeholder;
		}

		virtual void Save(std::ostream &out) {
			auto start=WriteObjectStart(out, *this);


			auto propstart=WriteSectionStart(out, gge::widgets::GID::Tabpanel_Props);

			WriteTo(out, DefaultSize);
			WriteLink(Panel, out);
			WriteLink(Radio, out);
			WriteLink(Placeholder, out);

			WriteEnd(out, propstart);

			WriteNames(out, *this, gge::widgets::GID::Tabpanel_Names, gge::widgets::GID::Tabpanel_Name);
			WriteSubItems(out, *this);


			WriteEnd(out, start);
		}

		virtual GID::Type GetGID() const {
			return gge::widgets::tabpanel::Blueprint::GetGID();
		}

		virtual void Prepare(gge::GGEMain &main, File &file) {
			Base::Prepare(main,file);

			if(Panel || Radio)
				return;

			file.FindObject(panel, Panel);
			file.FindObject(radio, Radio);
			gorgon::widgets::Placeholder *p;
			file.FindObject(placeholder, p);
			if(p) {
				gge::utils::CheckAndDelete(Placeholder);
				Placeholder=p;
			}
		}

		using gorgon::Base::Subitems;

	};	


}}
