<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Modificator\Value;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Modificator\ValueModificator;
/**
 *
 * @package WPDesk\Library\DropshippingExport\Modificator\Value
 */
class PercentValueModificator implements ValueModificator
{
    private $parameter = 0;
    public static function get_name(): string
    {
        return 'percent';
    }
    public static function get_nice_name(): string
    {
        return __('Percent %', 'dropshipping-export-free');
    }
    public function set_parameter($value)
    {
        if (is_numeric($value)) {
            $this->parameter = intval($value);
        }
    }
    public function get_modified_value($value)
    {
        if (empty($this->parameter)) {
            return $value;
        }
        $value = str_replace(',', '.', trim($value));
        if (is_numeric($value)) {
            $value = floatval($value);
            $value = $value + $value * ($this->parameter / 100);
        }
        return \floatval($value);
    }
}
