import constants from "./constants";

export default (dc, label, type) => {
  const defaultType = dc.getType("default");
  const defaultModel = defaultType.model;
  const defaultView = defaultType.view;

  const {
    attrAccordionContent,
    classAccordionContent,
    attrAccordionContainer,
    accordionContentProps,
  } = constants;

  const attrKey = attrAccordionContent;
  const classKey = classAccordionContent;

  dc.addType(type, {
    model: defaultModel.extend(
      {
        defaults: {
          ...defaultModel.prototype.defaults,
          name: label,
          draggable: `[${attrAccordionContainer}]`,
          copyable: false,
          removable: false,
          selectable: true,
          ...accordionContentProps,
        },

        init() {
          const attrs = this.getAttributes();
          attrs[attrKey] = 1;
          this.setAttributes(attrs);
          classKey && this.addClass(classKey);
        },
      },
      {
        isComponent(el) {
          if (el.hasAttribute && el.hasAttribute(attrKey)) {
            return { type };
          }
        },
      }
    ),

    view: defaultView,
  });
};
