import { Link } from "react-router";
import {
  PageTitle,
  WizardDirectory,
  usePlatformUiCapabilities,
  wizardEntriesForContext,
  type ApiSettings,
  type AuthInfo,
  type WizardDirectoriesUiCapability
} from "@govoplan/core-webui";

import { campaignWizardDirectories } from "./directory";

export default function WizardDirectoryPage({
  settings,
  auth,
  campaignId
}: {
  settings: ApiSettings;
  auth: AuthInfo;
  campaignId: string;
}) {
  const contributed = usePlatformUiCapabilities<WizardDirectoriesUiCapability>(
    "wizard.directories"
  );
  const capabilities = contributed.some((capability) =>
    capability.directories.some(
      (directory) => directory.id === "campaigns.resource"
    )
  )
    ? contributed
    : [...contributed, campaignWizardDirectories];
  const entries = wizardEntriesForContext(capabilities, {
    settings,
    auth,
    contextId: "campaign.resource",
    resourceId: campaignId
  });

  return (
    <div className="content-pad workspace-data-page">
      <div className="page-heading split workspace-heading">
        <PageTitle>i18n:govoplan-campaign.guided_workflows</PageTitle>
        <Link className="btn btn-secondary" to="../">
          i18n:govoplan-campaign.back_to_overview.ec986cba
        </Link>
      </div>
      <WizardDirectory
        entries={entries}
        auth={auth}
        emptyText="i18n:govoplan-campaign.no_guided_workflows"
      />
    </div>
  );
}
