<?php
namespace SabaiApps\Directories\Component\Payment\Controller;

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

class CancelSubscription extends Form\Controller {

	protected function _doGetFormSettings( Context $context, array &$formStorage ) {
		$this->_submitButtons['submit'] = array(
			'#btn_label' => __( 'Cancel subscription', 'directories-pro' ),
			'#btn_color' => 'danger',
			'#btn_size'  => 'lg',
		);
		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 cancel this subscription?', 'directories-pro' ) )
				),
			),
			'#header_class' => DRTS_BS_PREFIX . 'mb-0',
		);
	}

	public function submitForm( Form\Form $form, Context $context ) {
		$this->Payment_Components_impl( $this->Payment_Plan( $context->subscription )->paymentPlanComponent() )->paymentCancelSubscription( $context->subscription, true );
		$context->setSuccess( $this->Dashboard_Panels_panelUrl( 'payment_payments', 'subscriptions', '/payment_subscriptions/' ) )
			->addFlash( __( 'Your subscription was cancelled.', 'directories-pro' ) );
	}
}
