'use strict';

(({ App }) => {
  const { typeOf } = App.Inspector.utils;

  App.Inspector.components.JsonTreeRoot = {
    name: 'JsonTreeRoot',

    components: { JsonTreeNode: App.Inspector.components.JsonTreeNode },

    props: {
      lengthResolver: {
        type: Function,
        default: ({ length }) => length,
      },

      keysFilter: {
        type: Function,
        default: ({ keys }) => keys,
      },

      maxLength: {
        type: Number,
        default: Number.MAX_SAFE_INTEGER,
      },

      value: {
        required: true,
        validator(value) {
          return ['null', 'date', 'array', 'object', 'number', 'string', 'boolean', 'undefined'].includes(
            typeOf(value)
          );
        },
      },

      name: {
        default: '',
        type: String,
      },
    },

    template: /*html*/ `
      <div class="jt-root">
        <json-tree-node :name="name" :path="[name]" :value="value" :maxLength="maxLength" :keysFilter="keysFilter" :lengthResolver="lengthResolver" />
      </div>
    `,
  };
})(window);
