<?php

/**

 * @package     pkg_dearflip
 * @subpackage  com_dearflip
 * @since       1.0.0
 * @copyright   Copyright © 2007 Free Software Foundation, Inc. All rights reserved.
 * @license   GNU General Public License version 3 or later; see https://www.gnu.org/licenses/gpl-3.0.en.html

 */

// No direct access to this file
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Document\Document;

/**
 * Dearflipsetting View
 *
 * @since  0.0.1
 */
class DearflipViewDearflipsetting extends JViewLegacy {
    /**
     * View form
     *
     * @var         form
     */
    protected $form = null;

    /**
     * Display the Dearflipsetting view
     *
     * @param string $tpl The name of the template file to parse; automatically searches through the template paths.
     *
     * @return  void
     */
    public function display( $tpl = null ) {
        // Get the Data
        $this->form = $this->get( 'Form' );
        $this->item = $this->get( 'Item' );


        // Check for errors.
        if ( count( $errors = $this->get( 'Errors' ) ) ) {
            JFactory::getApplication()->enqueueMessage();

            return false;

        }


        // Set the toolbar
        $this->addToolBar();

        // Display the template
        parent::display( $tpl );

        // Set the document
        $document =JFactory::getDocument();
        $this->setDocument($document);
    }





    protected function addToolBar() {
        $input = JFactory::getApplication()->input;

        // Hide Joomla Administrator Main menu
        $input->set( 'hidemainmenu', true );

        $isNew = ( $this->item->id == 0 );

     
        $title = JText::_( 'COM_DEARFLIP_MANAGER_DEARFLIP_SETTING_EDIT' );
        

        JToolbarHelper::title( $title, 'dearflipsetting' );
        JToolbarHelper::apply('dearflipsetting.apply');
      //  JToolbarHelper::save( 'dearflipsetting.save' );
     /*   JToolbarHelper::cancel(
            'dearflipsetting.cancel',
            $isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE'
        );*/


        if(method_exists('JToolBarHelper' , 'link')){

            JToolbarHelper::link(JRoute::_('index.php?option=com_dearflip&view=dearflips'), 'Back to Books', 'goto_books');


        }
        else{

            JToolbarHelper::back('Back to Books', JRoute::_('index.php?option=com_dearflip&view=dearflips') );

        }
    }

    /**
     * Method to set up the document properties
     *
     * @return void
     */
    public function setDocument(Document $document): void
    {
        $this->item = $this->get( 'Item' );
        $isNew = ($this->item->id < 1);
        $document = JFactory::getDocument();
        $document->setTitle($isNew ? JText::_('COM_DEARFLIP_DEARFLIP_CREATING') :
            JText::_('COM_DEARFLIP_DEARFLIP_GLOBAL_EDITING'));
    }
}
?>

