import { MoveStyleUtils, Rock } from "@ruiapp/move-style";
import RapidFileSizeRendererMeta from "./RapidFileSizeRendererMeta";
import { RapidFileSizeRendererConfig } from "./rapid-file-size-renderer-types";
import { isNull, isObject, isUndefined } from "lodash";
import { formatFileSize } from "../../utils/format-utility";

export default {
  $type: "rapidFileSizeRenderer",

  Renderer(context, props) {
    const { value, decimalPlaces, defaultText } = props;
    if (isUndefined(value) || isNull(value)) {
      return defaultText || "";
    }

    return formatFileSize(value, decimalPlaces || 2);
  },

  ...RapidFileSizeRendererMeta,
} as Rock<RapidFileSizeRendererConfig>;
