import { CollapsibleListData_InitialExpandedItems, Node_Type } from "./../ricos-schema/legacy/wix/rich_content/v1/index.js";
const collapsibleListConverter = {
  toPm: {
    types: [Node_Type.COLLAPSIBLE_LIST],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => ({
      type: Node_Type.COLLAPSIBLE_LIST,
      attrs: {
        ...node.collapsibleListData,
        id: node.id
      },
      content: node.nodes.map((collapsibleItem, index) => {
        const expandState = node.collapsibleListData?.initialExpandedItems;
        return {
          type: Node_Type.COLLAPSIBLE_ITEM,
          attrs: {
            id: collapsibleItem.id,
            isExpanded: expandState === CollapsibleListData_InitialExpandedItems.ALL || index === 0 && expandState === CollapsibleListData_InitialExpandedItems.FIRST,
            expandOnlyOne: !!node.collapsibleListData?.expandOnlyOne
          },
          content: visit(collapsibleItem)
        };
      })
    })
  },
  fromPm: {
    types: [Node_Type.COLLAPSIBLE_LIST],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => {
      const { attrs = {} } = node;
      const { id, ...collapsibleListData } = attrs;
      return {
        type: Node_Type.COLLAPSIBLE_LIST,
        id,
        nodes: visit(node),
        collapsibleListData: {
          ...collapsibleListData,
          expandOnlyOne: collapsibleListData.expandOnlyOne || void 0
        }
      };
    }
  }
};
const collapsibleItemConverter = {
  toPm: {
    types: [Node_Type.COLLAPSIBLE_ITEM],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => ({
      type: Node_Type.COLLAPSIBLE_ITEM,
      attrs: {
        id: node.id
      },
      content: visit(node)
    })
  },
  fromPm: {
    types: [Node_Type.COLLAPSIBLE_ITEM],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => {
      const { attrs = {} } = node;
      const { id } = attrs;
      return {
        type: Node_Type.COLLAPSIBLE_ITEM,
        id,
        nodes: visit(node)
      };
    }
  }
};
const collapsibleItemTitleConverter = {
  toPm: {
    types: [Node_Type.COLLAPSIBLE_ITEM_TITLE],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => ({
      type: Node_Type.COLLAPSIBLE_ITEM_TITLE,
      attrs: {
        id: node.id
      },
      content: visit(node)
    })
  },
  fromPm: {
    types: [Node_Type.COLLAPSIBLE_ITEM_TITLE],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => {
      const { attrs = {} } = node;
      const { id } = attrs;
      return {
        type: Node_Type.COLLAPSIBLE_ITEM_TITLE,
        id,
        nodes: visit(node)
      };
    }
  }
};
const collapsibleItemBodyConverter = {
  toPm: {
    types: [Node_Type.COLLAPSIBLE_ITEM_BODY],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => ({
      type: Node_Type.COLLAPSIBLE_ITEM_BODY,
      attrs: {
        id: node.id
      },
      content: visit(node)
    })
  },
  fromPm: {
    types: [Node_Type.COLLAPSIBLE_ITEM_BODY],
    // @ts-ignore $TSFixMe
    convert: (node, visit) => {
      const { attrs = {} } = node;
      const { id } = attrs;
      return {
        type: Node_Type.COLLAPSIBLE_ITEM_BODY,
        id,
        nodes: visit(node)
      };
    }
  }
};
export {
  collapsibleItemBodyConverter,
  collapsibleItemConverter,
  collapsibleItemTitleConverter,
  collapsibleListConverter
};
//# sourceMappingURL=collapsible-list-converters.js.map
