"use client"

import { DocsEditMenu, type DocsEditMenuActions, type DocsEditMenuState } from "@/components/drive/richtext/docs-edit-menu"
import { DocsFileMenu, type DocsFileMenuActions } from "@/components/drive/richtext/docs-file-menu"
import {
  DocsFormatMenu,
  type DocsFormatMenuActions,
  type DocsFormatMenuState,
} from "@/components/drive/richtext/docs-format-menu"
import { DocsInsertMenu, type DocsInsertMenuActions } from "@/components/drive/richtext/docs-insert-menu"
import { DocsViewMenu, type DocsViewMenuActions, type DocsViewMenuState } from "@/components/drive/richtext/docs-view-menu"
import { DOCS_MENUBAR_CONTENT_PROPS } from "@/components/drive/richtext/docs-menubar-props"
import {
  Menubar,
  MenubarContent,
  MenubarItem,
  MenubarMenu,
  MenubarTrigger,
} from "@/components/ui/menubar"
import { cn } from "@/lib/utils"

const OTHER_MENU_LABELS = ["Outils", "Aide"] as const

export function DocsMenubar({
  viewMenuActions,
  viewMenuState,
  viewMenuDisabled,
  fileMenuActions,
  fileMenuDisabled,
  editMenuActions,
  editMenuState,
  editMenuDisabled,
  insertMenuActions,
  insertMenuDisabled,
  insertMenuPageElementsEnabled,
  formatMenuActions,
  formatMenuState,
  formatMenuDisabled,
  className,
}: {
  viewMenuActions?: DocsViewMenuActions
  viewMenuState?: DocsViewMenuState
  viewMenuDisabled?: boolean
  fileMenuActions?: DocsFileMenuActions
  fileMenuDisabled?: boolean
  editMenuActions?: DocsEditMenuActions
  editMenuState?: DocsEditMenuState
  editMenuDisabled?: boolean
  insertMenuActions?: DocsInsertMenuActions
  insertMenuDisabled?: boolean
  insertMenuPageElementsEnabled?: boolean
  formatMenuActions?: DocsFormatMenuActions
  formatMenuState?: DocsFormatMenuState
  formatMenuDisabled?: boolean
  className?: string
}) {
  return (
    <Menubar
      className={cn(
        "docs-menubar h-auto gap-0 border-0 bg-transparent p-0 shadow-none",
        className
      )}
    >
      {fileMenuActions ? (
        <DocsFileMenu actions={fileMenuActions} disabled={fileMenuDisabled} />
      ) : (
        <MenubarMenu>
          <MenubarTrigger className="docs-menu-trigger">Fichier</MenubarTrigger>
          <MenubarContent {...DOCS_MENUBAR_CONTENT_PROPS} data-docs-menu-surface>
            <MenubarItem disabled className="text-muted-foreground">
              Bientôt disponible
            </MenubarItem>
          </MenubarContent>
        </MenubarMenu>
      )}

      {editMenuActions && editMenuState ? (
        <DocsEditMenu
          actions={editMenuActions}
          state={editMenuState}
          disabled={editMenuDisabled}
        />
      ) : (
        <MenubarMenu>
          <MenubarTrigger className="docs-menu-trigger">Édition</MenubarTrigger>
          <MenubarContent {...DOCS_MENUBAR_CONTENT_PROPS} data-docs-menu-surface>
            <MenubarItem disabled className="text-muted-foreground">
              Bientôt disponible
            </MenubarItem>
          </MenubarContent>
        </MenubarMenu>
      )}

      {viewMenuActions && viewMenuState ? (
        <DocsViewMenu
          actions={viewMenuActions}
          state={viewMenuState}
          disabled={viewMenuDisabled}
        />
      ) : (
        <MenubarMenu>
          <MenubarTrigger className="docs-menu-trigger">Affichage</MenubarTrigger>
          <MenubarContent {...DOCS_MENUBAR_CONTENT_PROPS} data-docs-menu-surface>
            <MenubarItem disabled className="text-muted-foreground">
              Bientôt disponible
            </MenubarItem>
          </MenubarContent>
        </MenubarMenu>
      )}

      {insertMenuActions ? (
        <DocsInsertMenu
          actions={insertMenuActions}
          disabled={insertMenuDisabled}
          pageElementsEnabled={insertMenuPageElementsEnabled}
        />
      ) : (
        <MenubarMenu>
          <MenubarTrigger className="docs-menu-trigger">Insertion</MenubarTrigger>
          <MenubarContent {...DOCS_MENUBAR_CONTENT_PROPS} data-docs-menu-surface>
            <MenubarItem disabled className="text-muted-foreground">
              Bientôt disponible
            </MenubarItem>
          </MenubarContent>
        </MenubarMenu>
      )}

      {formatMenuActions && formatMenuState ? (
        <DocsFormatMenu
          actions={formatMenuActions}
          state={formatMenuState}
          disabled={formatMenuDisabled}
        />
      ) : (
        <MenubarMenu>
          <MenubarTrigger className="docs-menu-trigger">Format</MenubarTrigger>
          <MenubarContent
            {...DOCS_MENUBAR_CONTENT_PROPS}
            className="docs-menu-content overflow-visible"
            data-docs-menu-surface
          >
            <MenubarItem disabled className="text-muted-foreground">
              Bientôt disponible
            </MenubarItem>
          </MenubarContent>
        </MenubarMenu>
      )}

      {OTHER_MENU_LABELS.map((label) => (
          <MenubarMenu key={label}>
            <MenubarTrigger className="docs-menu-trigger">{label}</MenubarTrigger>
            <MenubarContent
              {...DOCS_MENUBAR_CONTENT_PROPS}
              className="docs-menu-content overflow-visible"
              data-docs-menu-surface
            >
              <MenubarItem disabled className="text-muted-foreground">
                Bientôt disponible
              </MenubarItem>
            </MenubarContent>
          </MenubarMenu>
      ))}
    </Menubar>
  )
}
