<?php

namespace KupShop\POSBundle\Admin\Tabs;

use KupShop\AdminBundle\Admin\WindowTab;

class PosTerminalSettingsTab extends WindowTab
{
    protected $title = 'flapPosTerminalSettings';
    protected $template = 'window/PosTerminalSettings.tpl';

    public function handleUpdate(): void
    {
        $data = getVal('data');
        if ($data['data']['terminal']['ip'] && !filter_var($data['data']['terminal']['ip'] ?? false, FILTER_VALIDATE_IP) !== false) {
            $this->getWindow()->addError(translate('invalid_ip', 'posSettings'));
        }
    }

    public function getLabel()
    {
        return translate($this->title, 'posSettings');
    }

    public static function getTypes(): array
    {
        return [
            'posSettings' => 1,
        ];
    }

    public static function isAllowed()
    {
        return findModule(\Modules::NEW_POS, \Modules::SUB_TERMINAL);
    }
}
