/* eslint-disable @typescript-eslint/no-unsafe-return */

/* eslint-disable @typescript-eslint/no-unsafe-argument */

/* eslint-disable @typescript-eslint/restrict-template-expressions */

/* eslint-disable @typescript-eslint/ban-ts-comment */
function parseObjectValue(object) {
  return Object.values(object).reduce(function (acc, value) {
    return "" + (acc === '' ? '' : acc + " ") + value;
  }, '');
}

function parseArrayValue(array) {
  // @ts-ignore
  return array.reduce(function (acc, value) {
    return "" + (acc === '' ? '' : acc + ",") + value;
  }, '');
}

function isArray(value) {
  // @ts-ignore
  return typeof value.reduce !== 'undefined';
}

export default function parse(propValue) {
  if (propValue === null || propValue === undefined) {
    return '';
  }

  if (typeof propValue !== 'object') return "" + propValue;

  if (isArray(propValue)) {
    return parseArrayValue(propValue);
  }

  var guessXYZ = propValue;

  if (guessXYZ.x !== undefined && guessXYZ.y !== undefined && guessXYZ.z !== undefined) {
    return guessXYZ.x + " " + guessXYZ.y + " " + guessXYZ.z;
  }

  return Object.entries(propValue).reduce(function (acc, _ref) {
    var key = _ref[0],
        value = _ref[1];

    if (value === undefined) {
      return acc;
    }

    if (typeof value !== 'object') return "" + acc + key + ":" + value + ";";
    var parsedValue = isArray(value) ? parseArrayValue(value) : parseObjectValue(value);
    return "" + acc + key + ":" + parsedValue + ";";
  }, '');
}