<?php
namespace Wpupgrader\WordPress\Plugins\GdprConsentLite\Blocks;

class AbstractConsentsBlock extends \Wpupgrader\Libraries\WordPress\Plugins\Core\Blocks\Block
{
    protected $settings;

    public function getSetting($name, $default = null)
    {
        $settings = $this->getSettings();

        if (!empty($settings[$name])) {
            return $settings[$name] !== '' ? $settings[$name] : $default;
        }

        return $default;
    }

    protected function _getUnitSetting($name, $unit, $default = '')
    {
        $settings = $this->getSettings();

        if (!empty($settings[$name]) && !empty($settings[$name][$unit])) {
            return $settings[$name][$unit];
        }
        return $default;
    }

    public function getUnitsSetting($name, $options = [], $default = 'inherit')
    {
        $unit = $this->_getUnitSetting($name, 'unit', 'rem');
        if (empty($options)) {
            $options = ['top', 'right', 'bottom', 'left'];
        }
        $style = '';
        foreach ($options as $option) {
            $style .= trim($this->_getUnitSetting($name, $option)) !== '' ? $this->_getUnitSetting($name, $option).$unit.' ' : (string)$default.' ';
        }
        return trim($style);
    }

    private function getSettings()
    {
        if ($this->settings === null) {
            $this->settings = \get_option('gdpr-consent-settings');
        }

        return $this->settings;
    }

    public function getEffectsClasses()
    {
        return '';
    }
}