<?php
/* * ********************************************************************
*  ProxmoxVPS Product developed. (27.03.19)
* *
*
*  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
*  CONTACT                        ->       contact@modulesgarden.com
*
*
* This software is furnished under a license and may be used and copied
* only  in  accordance  with  the  terms  of such  license and with the
* inclusion of the above copyright notice.  This software  or any other
* copies thereof may not be provided or otherwise made available to any
* other person.  No title to and  ownership of the  software is  hereby
* transferred.
*
*
* ******************************************************************** */

namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Pages;


use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Buttons\IsoInstallButton;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\Column;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;

trait IsoTrait
{


    public function initContent()
    {
        $this->setInternalAlertMessage("Select the template for reinstallation. If you proceed, all data located on the virtual machine will be lost.");

        $this->unsetShowTitle();
        //Install
        $this->addActionButton(new IsoInstallButton());
    }

    protected function loadHtml()
    {
        $this->addColumn((new Column('name'))->setSearchable(true, "string")->setOrderable('ASC'));
    }

    public function replaceFieldName($key, $row)
    {
        return sl("lang")->abtr("template", $row[$key]);
    }

    protected function loadData()
    {
        $data = [];
        foreach ($this->isoRepository()->fetch() as $entity)
        {

            if ($this->configuration()->isPermissionIsoImages() && !in_array($entity->getVolid(), $this->configuration()->getPermissionIsoImages()))
            {
                continue;
            }
            $data[] = [
                "id"   => $entity->getVolid(),
                "name" => $entity->getFriendlyName(),
            ];
        }
        $dataProv = new ArrayDataProvider();
        $dataProv->setDefaultSorting("name", 'ASC');
        $dataProv->setData($data);
        $this->setDataProvider($dataProv);
    }

}