<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\ProductFields\Nokaut;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductField;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldXml;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldXmlTag;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldStringValue;
use DOMElement;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\ProductFields\CustomProductField;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldDefaultValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\NameProductFieldValue;
class NameProductField extends CustomProductField implements ProductField, ProductFieldXml
{
    public const TAG_NAME = 'name';
    private string $field_name;
    private ProductFieldValue $product_value;
    public function __construct(ProductFieldValue $product_value)
    {
        $this->product_value = $product_value;
    }
    public static function is_allowed_to_change(): bool
    {
        return \true;
    }
    public static function get_default_class_value(): string
    {
        return NameProductFieldValue::class;
    }
    public static function get_default_field_name(): string
    {
        return 'name';
    }
    public static function get_default_field_nice_name(): string
    {
        return sprintf(esc_html__('Product name %s', 'dropshipping-export-free'), '(' . self::TAG_NAME . ')');
    }
    public function get_field_name(): string
    {
        $default = self::get_default_field_name();
        return !empty($this->field_name) ? $this->field_name : $default;
    }
    public function set_field_name(string $string)
    {
        $this->field_name = trim($string);
    }
    public function map_xml_value(DOMElement $element): DOMElement
    {
        $root = $element->ownerDocument;
        $string = $this->get_values_as_string($this->product_value);
        if (\is_string($string)) {
            $name = $element->appendChild($root->createElement(self::TAG_NAME));
            $name->appendChild($root->createCDATASection($string));
        }
        return $element;
    }
}
