import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  DashboardMenuPluginAction,
  ExtensionDataClient,
  VALID_PATH_REGEX,
  createCustomElementFolderValidation,
  createDashboardMenuPluginValidation,
  createDashboardPluginValidation,
  createDashboardRouteValidation,
  createEmbeddedScriptFolderValidation,
  createReactComponentFolderValidation,
  createServicePluginValidation,
  generateCustomElement,
  generateDashboardMenuPlugin,
  generateDashboardModal,
  generateDashboardPage,
  generateDashboardPlugin,
  generateDataCollection,
  generateEditorReactComponent,
  generateEmbeddedScript,
  generateEvent,
  generateServicePlugin,
  generateSitePlugin,
  getBackendDataCollectionsExtensionsDir,
  getBackendEventExtensionsDir,
  getBackendPluginExtensionsDir,
  getDashboardMenuPluginExtensionsDir,
  getDashboardModalExtensionsDir,
  getDashboardPluginExtensionsDir,
  getEcomRequiredApps,
  pathAvailableValidation
} from "./chunk-H5GIJ5WD.js";
import {
  getEmbeddedScriptExtensionsDir,
  getSitePluginExtensionsDir,
  getSiteWidgetExtensionsDir
} from "./chunk-D5GYKQIG.js";
import {
  DevCenterClient
} from "./chunk-6GQQXLEJ.js";
import {
  ComponentType
} from "./chunk-BYP4JZFS.js";
import {
  external_exports
} from "./chunk-SDLCFZRL.js";
import {
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-astro-commands/src/components/GenerateCommand/extensionHandlers.ts
init_esm_shims();

// ../cli-astro-commands/src/components/GenerateCommand/dashboard-page/extension.ts
init_esm_shims();

// ../cli-astro-commands/src/components/GenerateCommand/generate-schema/definitions.ts
init_esm_shims();
function defineField(field) {
  return JSON.stringify(field);
}

// ../cli-astro-commands/src/components/GenerateCommand/dashboard-page/extension.ts
var schema = external_exports.object({
  extensionType: external_exports.literal("DASHBOARD_PAGE"),
  title: external_exports.string().describe(
    defineField({ title: "Page title", description: "The Page Title" })
  ),
  route: external_exports.string().regex(VALID_PATH_REGEX).describe(
    defineField({
      title: "Page route",
      description: "Lowercase alphanumeric, hyphens, and slashes"
    })
  )
});
var dashboardPage = {
  title: "Dashboard Page",
  description: "A Dashboard page",
  group: "Dashboard",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/dashboard-extensions/dashboard-pages/add-dashboard-page-extensions",
  zodSchema: schema,
  validate: async (projectFolder, data) => {
    const result = createDashboardRouteValidation(projectFolder)(data.route);
    return result.valid ? null : result.reason;
  },
  generate: ({ projectFolder, data }) => generateDashboardPage(projectFolder, data.route, data.title)
};

// ../cli-astro-commands/src/components/GenerateCommand/dashboard-modal/extension.ts
init_esm_shims();
var schema2 = external_exports.object({
  extensionType: external_exports.literal("DASHBOARD_MODAL"),
  title: external_exports.string().describe(defineField({ title: "Modal title" })),
  folder: external_exports.string().regex(VALID_PATH_REGEX).describe(
    defineField({
      title: "Modal folder",
      description: "Lowercase alphanumeric and hyphens only."
    })
  )
});
var dashboardModal = {
  title: "Dashboard Modal",
  description: "A Dashboard modal dialog",
  group: "Dashboard",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/dashboard-extensions/dashboard-modals/add-dashboard-modal-extensions",
  zodSchema: schema2,
  validate: async (projectFolder, data) => {
    const isAvailable = pathAvailableValidation(
      getDashboardModalExtensionsDir(projectFolder)
    )(data.folder);
    return isAvailable ? null : "The modal folder must be unique, please choose a folder that has not been used yet in your application.";
  },
  generate: ({ projectFolder, data }) => generateDashboardModal(projectFolder, data.folder, data.title)
};

// ../cli-astro-commands/src/components/GenerateCommand/plugins/dashboard-plugin/extension.ts
init_esm_shims();
function buildSlotIdField(containers) {
  if (containers.length === 0) {
    return external_exports.string().describe(
      defineField({
        title: "Slot to extend",
        description: "Component ID of the back-office extension container to extend. Obtain from the Dev Center."
      })
    );
  }
  const literals = containers.map(
    (c) => external_exports.literal(c.component.componentId).describe(
      defineField({
        title: c.component.data.backOfficeExtensionContainer.slotData?.displayName ?? c.component.name
      })
    )
  );
  const field = literals.length === 1 ? literals[0] : external_exports.union(
    literals
  );
  return field.describe(
    defineField({
      title: "Slot to extend",
      description: "Component ID of the back-office extension container to extend."
    })
  );
}
var dashboardPlugin = {
  title: "Dashboard Plugin",
  description: "A plugin that extends a back-office page with a custom widget",
  group: "Dashboard",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/dashboard-extensions/dashboard-plugins/add-dashboard-plugin-extensions",
  zodSchema: async (httpClient) => {
    const client = new ExtensionDataClient(httpClient);
    const containers = await client.getBackofficeExtensionWidgets();
    return external_exports.object({
      extensionType: external_exports.literal("DASHBOARD_PLUGIN"),
      extendsSlotId: buildSlotIdField(containers),
      title: external_exports.string().describe(defineField({ title: "Plugin title" })),
      folder: external_exports.string().regex(VALID_PATH_REGEX).describe(
        defineField({
          title: "Plugin folder",
          description: "Lowercase alphanumeric and hyphens only. Must be unique within src/dashboard/plugins/."
        })
      )
    }).transform((data) => ({
      ...data,
      slotsAppId: containers.find(
        (c) => c.component.componentId === data.extendsSlotId
      )?.appId
    }));
  },
  validate: async (projectFolder, data) => {
    const result = createDashboardPluginValidation(
      getDashboardPluginExtensionsDir(projectFolder)
    )(data.folder);
    return result.valid ? null : result.reason;
  },
  generate: async ({ projectFolder, data, httpClient }) => {
    const client = new ExtensionDataClient(httpClient);
    const sdkSlotData = data.slotsAppId ? await client.getSdkSlotData({
      slotId: data.extendsSlotId,
      appId: data.slotsAppId
    }).catch(() => {
    }) : void 0;
    return generateDashboardPlugin(
      projectFolder,
      data.extendsSlotId,
      data.folder,
      data.title,
      sdkSlotData?.importData
    );
  }
};

// ../cli-astro-commands/src/components/GenerateCommand/plugins/dashboad-menu-plugin/extension.ts
init_esm_shims();
var actionSchema = external_exports.union([
  external_exports.object({
    pageId: external_exports.string().uuid().describe(defineField({ title: "Page ID" }))
  }).describe(JSON.stringify({ title: "Navigate to a page" })),
  external_exports.object({
    modalId: external_exports.string().uuid().describe(defineField({ title: "Modal ID" }))
  }).describe(JSON.stringify({ title: "Open a modal" }))
]).describe(
  defineField({
    title: "Action",
    description: "The action performed when the menu item is clicked. Provide either pageId to navigate to a dashboard page or modalId to open a dashboard modal."
  })
);
function buildSlotIdField2(containers) {
  if (containers.length === 0) {
    return external_exports.string().describe(
      defineField({
        title: "Slot to extend",
        description: "Component ID of the back-office menu extension container to extend. Obtain from the Dev Center."
      })
    );
  }
  const literals = containers.map(
    (c) => external_exports.literal(c.component.componentId).describe(
      defineField({
        title: c.component.data.backOfficeExtensionContainer.slotData?.displayName ?? c.component.name
      })
    )
  );
  const field = literals.length === 1 ? literals[0] : external_exports.union(
    literals
  );
  return field.describe(
    defineField({
      title: "Slot to extend",
      description: "Component ID of the back-office menu extension container to extend."
    })
  );
}
var dashboardMenuPlugin = {
  title: "Dashboard Menu Plugin",
  description: "A plugin that adds a menu item to a back-office page navigation",
  group: "Dashboard",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/dashboard-extensions/dashboard-menu-plugins/add-dashboard-menu-plugin-extensions",
  zodSchema: async (httpClient) => {
    const client = new ExtensionDataClient(httpClient);
    const containers = await client.getBackofficeMenuItems();
    return external_exports.object({
      extensionType: external_exports.literal("DASHBOARD_MENU_PLUGIN"),
      extendsSlotId: buildSlotIdField2(containers),
      action: actionSchema,
      title: external_exports.string().describe(defineField({ title: "Menu item title" })),
      folder: external_exports.string().regex(VALID_PATH_REGEX).describe(
        defineField({
          title: "Plugin folder",
          description: "Lowercase alphanumeric and hyphens only. Must be unique within src/dashboard/menu-plugins/."
        })
      )
    });
  },
  validate: async (projectFolder, data) => {
    const result = createDashboardMenuPluginValidation(
      getDashboardMenuPluginExtensionsDir(projectFolder)
    )(data.folder);
    return result.valid ? null : result.reason;
  },
  generate: ({ projectFolder, data }) => {
    const actionType = "pageId" in data.action ? DashboardMenuPluginAction.NavigateToPage() : DashboardMenuPluginAction.OpenModal();
    const action = "pageId" in data.action ? { navigateToPage: { pageId: data.action.pageId } } : { openModal: { componentId: data.action.modalId } };
    return generateDashboardMenuPlugin(
      projectFolder,
      data.extendsSlotId,
      actionType,
      action,
      data.folder,
      data.title
    );
  }
};

// ../cli-astro-commands/src/components/GenerateCommand/event/extension.ts
init_esm_shims();
var schema3 = external_exports.object({
  extensionType: external_exports.literal("EVENT"),
  folder: external_exports.string().regex(VALID_PATH_REGEX).describe(
    defineField({
      title: "Event folder",
      description: "Lowercase alphanumeric and hyphens only"
    })
  )
});
var event = {
  title: "Event",
  description: "A backend event handler",
  group: "Backend",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/events/add-event-extensions",
  zodSchema: schema3,
  validate: async (projectFolder, data) => {
    const isAvailable = pathAvailableValidation(
      getBackendEventExtensionsDir(projectFolder)
    )(data.folder);
    return isAvailable ? null : "The event folder must be unique, please choose a folder that has not been used yet in your application.";
  },
  generate: ({ projectFolder, data }) => generateEvent(projectFolder, data.folder)
};

// ../cli-astro-commands/src/components/GenerateCommand/service-plugin/extension.ts
init_esm_shims();
var schema4 = external_exports.object({
  extensionType: external_exports.literal("SERVICE_PLUGIN"),
  pluginType: external_exports.union([
    external_exports.literal(ComponentType.ECOM_ADDITIONAL_FEES).describe(defineField({ title: "Ecom Additional Fees" })),
    external_exports.literal(ComponentType.ECOM_SHIPPING_RATES).describe(defineField({ title: "Ecom Shipping Rates" })),
    external_exports.literal(ComponentType.ECOM_DISCOUNTS_TRIGGER).describe(defineField({ title: "Ecom Discount Triggers" })),
    external_exports.literal(ComponentType.ECOM_VALIDATIONS).describe(defineField({ title: "Ecom Validations" })),
    external_exports.literal(ComponentType.ECOM_PAYMENT_SETTINGS).describe(defineField({ title: "Ecom Payment Settings" })),
    external_exports.literal(ComponentType.GIFT_CARDS_PROVIDER).describe(defineField({ title: "Ecom Gift Cards Provider" })),
    external_exports.literal(ComponentType.STAFF_SORTING_PROVIDER).describe(defineField({ title: "Staff Sorting Provider" })),
    external_exports.literal(ComponentType.REALTIME_PERMISSIONS_PROVIDER).describe(defineField({ title: "Realtime Permissions Provider" }))
  ]).describe(defineField({ title: "Plugin type" })),
  name: external_exports.string().regex(VALID_PATH_REGEX).max(19).describe(
    defineField({
      title: "Plugin name",
      description: "Lowercase alphanumeric and hyphens only."
    })
  )
});
var servicePlugin = {
  title: "Service Plugin",
  description: "A backend service plugin that extends a Wix service",
  group: "Backend",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/service-plugins/add-service-plugin-extensions",
  zodSchema: schema4,
  validate: async (projectFolder, data) => {
    const result = createServicePluginValidation(
      getBackendPluginExtensionsDir(projectFolder)
    )(data.name);
    return result.valid ? null : result.reason;
  },
  generate: ({ projectFolder, data }) => generateServicePlugin(projectFolder, data.pluginType, data.name)
};

// ../cli-astro-commands/src/components/GenerateCommand/embedded-script/extension.ts
init_esm_shims();
var schema5 = external_exports.object({
  extensionType: external_exports.literal("EMBEDDED_SCRIPT"),
  name: external_exports.string().describe(defineField({ title: "Script name" })),
  folder: external_exports.string().regex(VALID_PATH_REGEX).describe(
    defineField({
      title: "Script folder",
      description: "Lowercase alphanumeric and hyphens only. Must be unique within src/site/embedded-scripts/."
    })
  ),
  scriptType: external_exports.union([
    external_exports.literal("ESSENTIAL").describe(defineField({ title: "Essential" })),
    external_exports.literal("FUNCTIONAL").describe(defineField({ title: "Functional" })),
    external_exports.literal("ANALYTICS").describe(defineField({ title: "Analytics" })),
    external_exports.literal("ADVERTISING").describe(defineField({ title: "Advertising" }))
  ]).describe(
    defineField({
      title: "Script type",
      description: "Determines the consent category of the script."
    })
  ),
  placement: external_exports.union([
    external_exports.literal("HEAD").describe(defineField({ title: "Head" })),
    external_exports.literal("BODY_START").describe(defineField({ title: "Body Start" })),
    external_exports.literal("BODY_END").describe(defineField({ title: "Body End" }))
  ]).describe(
    defineField({
      title: "Placement",
      description: "Where in the page HTML the script is injected."
    })
  )
});
var embeddedScript = {
  title: "Embedded Script",
  description: "A script embedded into site pages",
  group: "Site",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/embedded-scripts/about-embedded-scripts",
  zodSchema: schema5,
  validate: async (projectFolder, data) => {
    const result = createEmbeddedScriptFolderValidation(
      getEmbeddedScriptExtensionsDir(projectFolder)
    )(data.folder);
    return result.valid ? null : result.reason;
  },
  // scriptType and placement are Zod string literals but generateEmbeddedScript expects TypeScript enums
  generate: ({ projectFolder, data }) => generateEmbeddedScript(
    projectFolder,
    data.folder,
    data.name,
    data.scriptType,
    data.placement
  )
};

// ../cli-astro-commands/src/components/GenerateCommand/custom-element/extension.ts
init_esm_shims();
var schema6 = external_exports.object({
  extensionType: external_exports.literal("CUSTOM_ELEMENT"),
  name: external_exports.string().describe(defineField({ title: "Widget name" })),
  folder: external_exports.string().regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)+$/).describe(
    defineField({
      title: "Widget folder",
      description: "Must be a valid custom element name: lowercase, starts with a letter, contains at least one hyphen."
    })
  )
});
var customElement = {
  title: "Custom Element",
  description: "A site widget built as a custom HTML element",
  group: "Site",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/site-widgets/add-a-site-widget-extension",
  zodSchema: schema6,
  validate: async (projectFolder, data) => {
    const result = createCustomElementFolderValidation(
      getSiteWidgetExtensionsDir(projectFolder)
    )(data.folder);
    return result.valid ? null : result.reason;
  },
  generate: ({ projectFolder, data }) => generateCustomElement(projectFolder, data.folder, data.name)
};

// ../cli-astro-commands/src/components/GenerateCommand/site-plugin/extension.ts
init_esm_shims();
function buildWidgetPluginSlots(plugins) {
  const slotOptions = plugins.flatMap(
    (wp) => wp.component.data.widgetPlugin.placements.map((p) => ({
      value: `${wp.component.componentId}:${p.slotId}`,
      title: `${wp.component.name} \u2014 ${p.slotId}`
    }))
  );
  return slotOptions.map(
    (opt) => external_exports.literal(opt.value).describe(defineField({ title: opt.title }))
  );
}
function parseSitePluginSlotId(slotId) {
  const colonIndex = slotId.indexOf(":");
  return {
    widgetId: slotId.substring(0, colonIndex),
    slotId: slotId.substring(colonIndex + 1)
  };
}
var sitePlugin = {
  title: "Site Plugin",
  description: "A plugin that extends a Wix app widget with a custom component",
  group: "Site",
  documentation: "https://dev.wix.com/docs/wix-cli/guides/extensions/site-extensions/site-plugins/add-a-site-plugin-extension",
  zodSchema: async (httpClient) => {
    const client = new ExtensionDataClient(httpClient);
    const plugins = await client.getWidgetPlugins();
    const slotLiterals = buildWidgetPluginSlots(plugins);
    return external_exports.object({
      extensionType: external_exports.literal("SITE_PLUGIN"),
      slotId: external_exports.union(slotLiterals).describe(
        defineField({
          title: "Slot",
          description: "The widget slot to extend. Format: componentId:slotId."
        })
      ),
      name: external_exports.string().describe(defineField({ title: "Plugin name" })),
      folder: external_exports.string().regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)+$/).describe(
        defineField({
          title: "Plugin folder",
          description: "Must be a valid custom element name: lowercase, starts with a letter, contains at least one hyphen."
        })
      )
    });
  },
  validate: async (projectFolder, data) => {
    const result = createCustomElementFolderValidation(
      getSitePluginExtensionsDir(projectFolder)
    )(data.folder);
    return result.valid ? null : result.reason;
  },
  generate: async ({ projectFolder, appId, data, httpClient }) => {
    const { widgetId, slotId } = parseSitePluginSlotId(data.slotId);
    const plugins = await new ExtensionDataClient(
      httpClient
    ).getWidgetPlugins();
    const widgetPlugin = plugins.find(
      (wp) => wp.component.componentId === widgetId
    );
    const ecomRequiredApps = await getEcomRequiredApps();
    const requireAppId = ecomRequiredApps.appId === widgetPlugin?.appId ? ecomRequiredApps.requiredApps[0].appId : widgetPlugin?.appId;
    const placement = plugins.find((wp) => wp.component.componentId === widgetId)?.component.data.widgetPlugin.placements.find((p) => p.slotId === slotId);
    if (!placement) {
      throw new Error(`Unknown slot: ${data.slotId}`);
    }
    if (requireAppId) {
      await new DevCenterClient(httpClient).addRequiredApp({
        appId,
        appIdToRequire: requireAppId
      });
    }
    return generateSitePlugin(projectFolder, data.folder, data.name, [
      placement
    ]);
  }
};

// ../cli-astro-commands/src/components/GenerateCommand/data-collections/extension.ts
init_esm_shims();
import { existsSync } from "node:fs";
import { join } from "node:path";
var schema7 = external_exports.object({
  extensionType: external_exports.literal("DATA_COLLECTION"),
  collectionName: external_exports.string().regex(/^[A-Za-z0-9_-]{1,36}$/).describe(
    defineField({
      title: "Collection name",
      description: "1-36 characters, letters, numbers, underscores, and hyphens only."
    })
  )
});
var dataCollection = {
  title: "Data Collection",
  description: "A backend data collection",
  group: "Backend",
  documentation: "https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/data-collections-extension-object",
  zodSchema: schema7,
  validate: async (projectFolder, data) => {
    const dir = getBackendDataCollectionsExtensionsDir(projectFolder);
    return existsSync(join(dir, `${data.collectionName}.ts`)) ? "Collection name must be unique, please choose a name that has not been used yet in your application." : null;
  },
  generate: ({ projectFolder, data }) => generateDataCollection(projectFolder, data.collectionName)
};

// ../cli-astro-commands/src/components/GenerateCommand/editor-react-component/extension.ts
init_esm_shims();
var schema8 = external_exports.object({
  extensionType: external_exports.literal("EDITOR_REACT_COMPONENT"),
  name: external_exports.string().max(30).describe(defineField({ title: "Component name" })),
  folder: external_exports.string().regex(VALID_PATH_REGEX).describe(
    defineField({
      title: "Component folder",
      description: "Lowercase alphanumeric and hyphens only."
    })
  ),
  description: external_exports.string().min(3).max(300).describe(defineField({ title: "Component description" }))
});
var editorReactComponent = {
  title: "Editor React Component",
  description: "A site widget built as a React component for the Wix editor",
  group: "Site",
  zodSchema: schema8,
  validate: async (projectFolder, data) => {
    const result = createReactComponentFolderValidation(
      getSiteWidgetExtensionsDir(projectFolder)
    )(data.folder);
    return result.valid ? null : result.reason;
  },
  generate: ({ projectFolder, model, data }) => generateEditorReactComponent(
    projectFolder,
    data.folder,
    data.name,
    data.description,
    model.config.projectType === "App" ? model.config.codeIdentifier : void 0
  )
};

// ../cli-astro-commands/src/components/GenerateCommand/extensionHandlers.ts
var extensionHandlers = {
  DASHBOARD_PAGE: dashboardPage,
  DASHBOARD_MODAL: dashboardModal,
  DASHBOARD_PLUGIN: dashboardPlugin,
  DASHBOARD_MENU_PLUGIN: dashboardMenuPlugin,
  EVENT: event,
  SERVICE_PLUGIN: servicePlugin,
  EMBEDDED_SCRIPT: embeddedScript,
  CUSTOM_ELEMENT: customElement,
  SITE_PLUGIN: sitePlugin,
  DATA_COLLECTION: dataCollection,
  EDITOR_REACT_COMPONENT: editorReactComponent
};

// ../cli-astro-commands/src/components/GenerateCommand/generate-schema/types.ts
init_esm_shims();
var extensionFieldDefinitionSchema = external_exports.object({
  title: external_exports.string(),
  description: external_exports.string().optional()
});
var extensionTypeSchema = external_exports.object({
  extensionType: external_exports.string()
});

export {
  extensionHandlers,
  extensionFieldDefinitionSchema,
  extensionTypeSchema
};
//# sourceMappingURL=chunk-H5RUH62H.js.map