<?php
namespace apexl\Io\modules\subscriptionDisplay\controllers;

use apexl\Io\includes\Controller;
use apexl\Io\includes\Routes;
use apexl\Io\includes\System;
use apexl\Io\modules\display\components\CardEntityFilteredDisplayTable;
use apexl\Io\modules\display\components\EntityFilteredDisplayTable;
use apexl\Io\modules\display\components\Modal;
use apexl\Io\modules\display\services\Render;
use apexl\Io\modules\subscription\entities\subscriptionEntity;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;


class cancellationsController extends Controller
{
    /** @var Render */
    protected $render;

    public function __construct(Render $render)
    {
        parent::__construct();
        $this->render = $render;
    }

    public function selectSubscriptionToCancel(Request $request, Response $response)
    {

        $table = (new CardEntityFilteredDisplayTable(new subscriptionEntity(), [], false))
            ->addTitle('Cancel a Subscription')
            ->addClass('subscription-cancellation-table')
            ->src(Routes::getRoutePattern('subscription.data.cancellations-list'))
            ->addClass('subscription-table')
            ->addProperty('refreshButton', '<i class="fa-light fa-arrows-rotate"></i>')
            ->addComponent(
                (new Modal())->setButtonContent('<i class="fa-solid fa-ban"></i> cancel subscription')->setButtonClass('btn btn-sm btn-danger')->setContentSrc('subscriptionDisplay.suspend')->setTitle('Cancel Subscription')->addClass('order-edit-address')
            )
        ;


        //render
        $this->render::setPageTitle('Cancel Subscriptions');
        $this->output::addResponse($request, $this->render::build($table));
        return System::asJson($response);
    }
}