<?php

class MBasePanel extends MContainer
{
    public $box;

    public function __construct($name = '', $caption = '', $controls = NULL, $close = '', $icon = '')
    {
        parent::__construct($name, $controls, 'horizontal');
        $this->box = new MBox($caption, $close, $icon);
        if (is_null($caption)) $this->box->setBorderStyle( '0px' );
        $this->setClass('mPanelBody');
    }

    public function setTitle($title)
    {
        $this->box->setCaption($title);
    }

    public function setIcon($icon)
    {
        $this->box->boxTitle->setIcon($icon);
    }

    public function setClose($close)
    {
        $this->box->setClose($close);
    }

    public function addControl($control, $width = '', $float = 'left', $class = '')
    {
        if ( is_array($control) )
        {
            foreach ($control as $c)
            {
                $this->addControl($c, $width, $float);
            }
        }
        else
        {
            $cell = ($control instanceof MDiv) ? $control : new MDiv('',$control);
            $cell->setClass($class . ' ' . 'mPanelCellBox mPanelCell' . ucfirst($float));
            parent::addControl($cell);
        }
    }


    public function insertControl($pos, $control, $width = '', $float = 'left', $class = '')
    {
        $cell = new MDiv('',$control, 'mPanelCellBox mPanelCell' . ucfirst($float) . ' ' . $class);
        parent::insertControl( $cell, $pos );
    }


    public function generate()
    {
        $body = new MDiv( $this->name, $this->getControls(), 'mPanelBody' );
        $this->box->setControls( array($body) );
        return $this->box->generate();
    }

}


class MPanel extends MBasePanel {}

?>