/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#ifndef DDWECATEGORY_H
#define DDWECATEGORY_H

#include <ddmapptr.h>
#include <dditem.h>
#include <ddwebview.h>

using namespace std;

class ddwebcategorymap;
struct ddwebcategory;

/// ddwebcategorymap: Hilfsklasse, die Kategorien speichert.
/**
	ddwebcategorymap: Hilfsklasse, die Kategorien speichert.
*/

class ddwebcategorymap : public ddmapptr<ddwebcategory>
{

public:

	void init_data( const ddwebview& table );
	
	void dump() const;
	
	
	void render_path( dditem& item, ddstring& result, const ddstring& idpath );

	const ddwebcategory& find_category_by_id_path( const ddstring& path ) const;
	const ddwebcategory& find_category_by_key( const ddstring& path ) const;
};


/// sxpagefaqcategory : Hilfsklasse, die eine Kategorie abbildet.
/**
	sxpagefaqcategory, diesmal ohne  code-zauberei 
	eine direktabbildung der DB Inhalte der Kategorien-Tabelle
*/

struct ddwebcategory : public ddbaseobject
{

	ddstring id;
	ddstring parent;	
	ddstring name;
	ddstring key;
	ddstring title;
	ddstring path;
	ddstring idpath;
	
	//ddmapptr<ddwebcategory> children;
	ddwebcategorymap children;
	
	ddwebcategory( const ddstring& aid, const ddstring& aparent, const ddstring& aname, const ddstring& akey, const ddstring& atitle )
	{
		id 		 = aid;
		parent = aparent;
		name   = aname;
		key    = akey;
		title  = atitle;
	}
	
	const ddstring& create_path( ddwebcategorymap& tmptree );
	void 						calculate_path( ddwebcategorymap& tmptree, ddstring& fullpath, ddstring& fullidpath );
	void 						render( dditem& item, ddstring& result, int indent, bool highlight = false ) const;	
	void 						render_tree( dditem& item, ddstring& result, int indent )const ;	
	void 						render_children( dditem& item, ddstring& result, int indent ) const;
	void 						render_path( dditem& item, ddstring& result, size_t indent, const ddstringrow& splitpath  ) const;	
	void						collect_siblings( ddstring& result );
	
	ddstring to_string() const
	{
		return "-- ID: " +  id + " Parent: " + parent + " Name: " + name + " Key: " + key; //" Title: " + title + endl;
	}
		
	void dump() const
	{
		cout << to_string() << endl; //" Title: " << title << endl;
	}
	
	
	void dump_tree() const
	{
		cout << to_string() << endl; //" Title: " << title << endl;
		for( int i=0; i<children.size(); ++i )
			children[i]->dump_tree();
	}
};


#endif


