<?php
namespace SabaiApps\Directories\Component\Display\Controller\Admin;

use SabaiApps\Directories\Controller;
use SabaiApps\Directories\Context;

class DeleteDisplay extends Controller {

	protected function _doExecute( Context $context ) {
		if ( $this->_application->isDemoMode() ) {
			$context->setForbiddenError( null, 'This action is not allowed in demo mode.' );
			return;
		}

		if ( ! $context->getRequest()->isPostMethod()
			|| ! $this->_checkToken( $context, 'display_admin_displays', true )
			|| ( ! $display_type = $context->getRequest()->asStr( 'display_type' ) )
			|| ( ! $display_name = $context->getRequest()->asStr( 'display_name' ) )
		) {
			$context->setBadRequestError();
			return;
		}

		// Delete display
		$this->Display_Create_delete( $context->bundle, $display_name, $display_type );

		$context->setSuccess();
	}
}
