from .corehelper import *
from .itransformer import InterfaceTransform


# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility


class Jsi18n(InterfaceTransform):
    def __init__(self):
        """ implementation of interface transformation """
        super().__init__("Jsi18n")

    def autoGeneratedTag(self) -> str:
        #  return "// AUTO-GENERATED - DO NOT EDIT THE LINES BELOW "
        return ""

    def autoFileName(self) -> str:
        return "_{}.json"

    def transformComment(self, comment: str) -> str:
        """comment replace"""
        return ""

    # You can manually specify the number of replacements by changing the 4th argument
    def transformKeyValue(self, key: str, value: str, isLast: bool = False) -> str:
        if self.isCommonKey(key):
            return self.transformComment(key)

        if len(key) == 0:
            return ""

        normalizedValue = RegexBoxNewLine(value)
        normalizedValue = RegexBoxDoubleQuote(normalizedValue)
        normalizedValue = RegexBoxDF(normalizedValue)
        normalizedValue = RegexBoxBR(normalizedValue)
        normalizedValue = RegexBoxStrAt(normalizedValue)
        normalizedValue = RegexBoxAmp(normalizedValue)

        line_template = ' "{}": "{}"{}'

        if key == "nan":
            return ""

        if isLast:
            return line_template.format(key, normalizedValue, "")
        else:
            return line_template.format(key, normalizedValue, ",")

    def wrap_file(self, input: str, newValues: list) -> list:
        return ["{"] + newValues + ["}"]
