//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using System.ComponentModel;


namespace CommunityServer.Controls
{
    [
    ParseChildren(true)	
    ]
    /// <summary>
    /// Summary description for Summary.
    /// </summary>
    public abstract class SectionRepeater : Repeater 
    {
        CSContext csContext = CSContext.Current;
        string skinName = null;

        // *********************************************************************
        //  ForumRepeaterControl
        //
        /// <summary>
        /// Constructor
        /// </summary>
        // ***********************************************************************/
        public SectionRepeater() 
        {

            // If we're in design-time we simply return
            if (null == HttpContext.Current)
                return;

            //            // Is the user not availabe - must be anonymous
            //            if (forumContext.User.UserID == 0)
            //                Users.TrackAnonymousUsers();

            // Set the siteStyle for the page
            
                skinName = csContext.User.Theme;
            
        }

        /// <summary>
        /// Each application specific implementation must implement create
        /// </summary>
        protected override void CreateChildControls()
        {
			// if the forum is set to hidden and the admin has turned on collapsing panels and the user
			// has turned on collapsing panels, then don't do anything, if not, render the panel.
			if (HideForums ) {
				return;
			}

            ArrayList sections = GetSections();
            if (( sections != null) && (sections.Count != 0 )) 
            {
                this.DataSource = sections;
                this.DataBind();
            }
        }

        protected abstract ArrayList GetSections();

        
        
		
        [
        Bindable(true),
        Category( "" ),
        Description( "" ),
        DefaultValue( -1 ),
        ]
        public virtual Int32 GroupID 
        {
            get 
            {
                Object state = ViewState["ForumGroupID"];
                if ( state != null ) 
                {
                    return (Int32)state;
                }
                return -1;
            }
            set 
            {
                ViewState["ForumGroupID"] = value;
            }
        }

		
        [
        Bindable(true),
        Category( "" ),
        Description( "" ),
        DefaultValue( false ),
        ]
        public virtual Boolean HideForums 
        {
            get 
            {
                Object state = ViewState["HideForums"];
                if ( state != null ) 
                {
                    return (Boolean)state;
                }
                return false;
            }
            set 
            {
                ViewState["HideForums"] = value;
            }
        }


        [
        Bindable(true),
        Category( "" ),
        Description( "" ),
        DefaultValue( false ),
        ]
        public virtual Boolean IgnorePermissions 
        {
            get 
            {
                Object state = ViewState["IgnorePermissions"];
                if ( state != null ) 
                {
                    return (Boolean)state;
                }
                return false;
            }
            set 
            {
                ViewState["IgnorePermissions"] = value;
            }
        }

		[
		Bindable(true),
		Category( "" ),
		Description( "" ),
		DefaultValue( false ),
		]
		public virtual Boolean FlushSections 
		{
			get 
			{
				Object state = ViewState["FlushSections"];
				if ( state != null ) 
				{
					return (Boolean)state;
				}
				return false;
			}
			set 
			{
				ViewState["FlushSections"] = value;
			}
		}


        [
        Bindable(true),
        Category( "" ),
        Description( "" ),
        DefaultValue( ControlUserMode.User ),
        ]
        public virtual ControlUserMode Mode 
        {
            get 
            {
                Object state = ViewState["Mode"];
                if ( state != null ) 
                {
                    return (ControlUserMode)state;
                }
                return ControlUserMode.User;
            }
            set 
            {
                ViewState["Mode"] = value;
            }
        }


        // *********************************************************************
        //  SkinName
        //
        /// <summary>
        /// Used to construct paths to images, etc. within controls.
        /// </summary>
        /// 
        // ********************************************************************/ 
        protected string SkinName 
        {
            get 
            {
                return skinName;
            }
            set 
            {
                skinName = value;
            }
        }

    }

}
