<?php

namespace ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailAccount\Forms;


use ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailAccount\Providers\DeleteAccountDataProvider;
use ModulesGarden\Servers\OpenXchange\Core\UI\Interfaces\ClientArea;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\BaseForm;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Hidden;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\FormConstants;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Number;
use ModulesGarden\Servers\OpenXchange\App\Models\ProductConfiguration;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 18.09.19
 * Time: 11:28
 * Class DeleteAccountForm
 */
class DeleteAccountForm extends BaseForm implements ClientArea
{
    protected $id    = 'deleteAccountForm';
    protected $name  = 'deleteAccountForm';
    protected $title = 'deleteAccountForm';

    public function initContent()
    {
        $this->setFormType(FormConstants::DELETE);
        $this->dataProvider = new DeleteAccountDataProvider();

        $this->setConfirmMessage('confirmRemoveAccount');

        $field = new Hidden();
        $field->setId('id');
        $field->setName('id');
        $this->addField($field);

        //get the default value for number of days to delete the mailbox
        $hid     = $this->request->getValue('id');
        $hosting = \WHMCS\Service\Service::find($hid);
        $config  = ProductConfiguration::config($hosting->packageid);

        $daysToDelete = new Number('daysToDelete');
        $daysToDelete->setId('daysToDelete');
        $daysToDelete->setName('daysToDelete');
        $daysToDelete->setDescription('daysToDeleteDesc');
        $daysToDelete->setTitle('daysToDelete');
        $daysToDelete->setHtmlAttributes(['required' => true]);
        $daysToDelete->setDefaultValue($config['default_deletion_in_days']);
        $this->addField($daysToDelete);

        $this->loadDataToForm();
    }
}