import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
import {
  SETTINGS_ID,
  SETTINGS_KEY,
  SettingsAction,
  meta
} from "./chunk-ZX63QUGE.mjs";
import {
  Capabilities,
  contributes,
  createIntent
} from "./chunk-XJZGUJ3H.mjs";

// src/plugin-settings/app-graph-builder.ts
import { Atom } from "@effect-atom/atom-react";
import * as Function from "effect/Function";
import * as Option from "effect/Option";
import { ROOT_ID, createExtension } from "@dxos/app-graph";
import { isNonNullable } from "@dxos/util";
var app_graph_builder_default = ((context) => contributes(Capabilities.AppGraphBuilder, [
  createExtension({
    id: `${meta.id}/action`,
    actions: (node) => Atom.make((get) => Function.pipe(get(node), Option.flatMap((node2) => node2.id === ROOT_ID ? Option.some(node2) : Option.none()), Option.map(() => [
      {
        id: meta.id,
        data: async () => {
          const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
          await dispatch(createIntent(SettingsAction.Open));
        },
        properties: {
          label: [
            "open settings label",
            {
              ns: meta.id
            }
          ],
          icon: "ph--gear--regular",
          disposition: "menu",
          keyBinding: {
            macos: "meta+,",
            windows: "alt+,"
          }
        }
      }
    ]), Option.getOrElse(() => [])))
  }),
  createExtension({
    id: `${meta.id}/core`,
    connector: (node) => Atom.make((get) => Function.pipe(get(node), Option.flatMap((node2) => node2.id === ROOT_ID ? Option.some(node2) : Option.none()), Option.map(() => [
      {
        id: SETTINGS_ID,
        type: meta.id,
        properties: {
          label: [
            "app settings label",
            {
              ns: meta.id
            }
          ],
          icon: "ph--gear--regular",
          disposition: "pin-end",
          position: "hoist",
          testId: "treeView.appSettings"
        }
      }
    ]), Option.getOrElse(() => [])))
  }),
  createExtension({
    id: `${meta.id}/core-plugins`,
    connector: (node) => Atom.make((get) => Function.pipe(get(node), Option.flatMap((node2) => node2.id !== SETTINGS_ID ? Option.none() : Option.some(node2)), Option.map(() => {
      const manager = get(context.capability(Capabilities.PluginManager));
      const [settingsStore] = get(context.capabilities(Capabilities.SettingsStore));
      return [
        ...manager.plugins.filter((plugin) => manager.core.includes(plugin.meta.id)).map((plugin) => {
          const settings = settingsStore?.getStore(plugin.meta.id);
          if (!settings) {
            return null;
          }
          return [
            plugin.meta,
            settings
          ];
        }).filter(isNonNullable).map(([meta2, settings]) => ({
          id: `${SETTINGS_KEY}:${meta2.id.replaceAll("/", ":")}`,
          type: "category",
          data: settings,
          properties: {
            label: meta2.name ?? meta2.id,
            icon: meta2.icon ?? "ph--circle--regular"
          }
        })),
        {
          id: `${SETTINGS_KEY}:custom-plugins`,
          type: "category",
          properties: {
            label: [
              "custom plugins label",
              {
                ns: meta.id
              }
            ],
            icon: "ph--squares-four--regular",
            role: "branch",
            disposition: "collection"
          }
        }
      ];
    }), Option.getOrElse(() => [])))
  }),
  createExtension({
    id: `${meta.id}/custom-plugins`,
    connector: (node) => Atom.make((get) => Function.pipe(get(node), Option.flatMap((node2) => node2.id !== `${SETTINGS_KEY}:custom-plugins` ? Option.none() : Option.some(node2)), Option.map(() => {
      const manager = get(context.capability(Capabilities.PluginManager));
      const [settingsStore] = get(context.capabilities(Capabilities.SettingsStore));
      return manager.plugins.filter((plugin) => !manager.core.includes(plugin.meta.id)).map((plugin) => {
        const settings = settingsStore?.getStore(plugin.meta.id);
        if (!settings) {
          return null;
        }
        return [
          plugin.meta,
          settings
        ];
      }).filter(isNonNullable).map(([meta2, settings]) => ({
        id: `${SETTINGS_KEY}:${meta2.id.replaceAll("/", ":")}`,
        type: "category",
        data: settings,
        properties: {
          label: meta2.name ?? meta2.id,
          icon: meta2.icon ?? "ph--circle--regular"
        }
      }));
    }), Option.getOrElse(() => [])))
  })
]));
export {
  app_graph_builder_default as default
};
//# sourceMappingURL=app-graph-builder-EBU4NVWD.mjs.map
