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

use SabaiApps\Directories\Context;
use SabaiApps\Directories\Component\Form;

class DeleteNotification extends Form\Controller {

	protected function _doGetFormSettings( Context $context, array &$storage ) {
		$this->_cancelUrl               = dirname( dirname( $context->getRoute() ) );
		$this->_submitButtons['submit'] = array(
			'#btn_label' => __( 'Delete Notification', 'directories-pro' ),
			'#btn_color' => 'danger',
			'#btn_size'  => 'lg',
		);
		// Highlight and remove row on success
		$this->_ajaxOnSuccessDelete = '.drts-notification-admin-notifications tr[data-row-id=\'' . $context->notification->id . '\']';

		return array(
			'#header'       => array(
				sprintf(
					'<div class="%1$salert %1$salert-warning %1$smb-0">%2$s</div>',
					DRTS_BS_PREFIX,
					$this->H( __( 'Are you sure you want to delete this?', 'directories-pro' ) )
				),
			),
			'#header_class' => DRTS_BS_PREFIX . 'mb-0',
		);
	}

	public function submitForm( Form\Form $form, Context $context ) {
		$context->notification->markRemoved()->commit();
		$context->setSuccess();

		// Clear action to event map cache
		$this->getPlatform()->deleteCache( 'notification_action_event_map' );
	}
}
