/* eslint-disable no-unused-vars */
import React from 'react'
import { translateURL } from "./utils"

const PageExplorerMenuItem = window.telepath.constructors["wagtail.sidebar.PageExplorerMenuItem"]


export class ProperlyNavigatingPageExplorerMenuItemDefinition extends PageExplorerMenuItem {
  constructor(config, startPageId, currentLanguage, LANGUAGE_CODE, LANGUAGES) {
    super(config, startPageId)
    this.currentLanguage = currentLanguage
    this.LANGUAGE_CODE = LANGUAGE_CODE
    this.LANGUAGES = LANGUAGES
    this.attrs = {}
  }

  render({ path, slim, state, dispatch, navigate }) {
    const { currentLanguage, LANGUAGE_CODE, LANGUAGES } = this

    return super.render({ path, slim, state, dispatch, navigate: url => navigate(translateURL(url, currentLanguage, LANGUAGE_CODE, LANGUAGES))})
  }
}

window.telepath.register('ocyan.sidebar.ProperlyNavigatingPageExplorerMenuItem', ProperlyNavigatingPageExplorerMenuItemDefinition)
