"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var states_module_exports = {};
__export(states_module_exports, {
  StateModule: () => StateModule,
  StatePayloadModule: () => StatePayloadModule,
  StatesModule: () => StatesModule
});
module.exports = __toCommonJS(states_module_exports);
var consts = __toESM(require("../../consts"));
var gen = __toESM(require("../../generators"));
var import_module = require("../../module");
var strings = __toESM(require("../../strings"));
class StatePayloadModule extends import_module.Module {
  constructor(_state) {
    super({
      path: "payload.ts",
      exportName: strings.typeName("Payload")
    });
    this._state = _state;
  }
  async getContent() {
    return gen.zuiSchemaToTypeScriptType(this._state.schema, "Payload");
  }
}
class StateModule extends import_module.Module {
  constructor(_name, _state) {
    super({
      path: consts.INDEX_FILE,
      exportName: strings.typeName(_name)
    });
    this._name = _name;
    this._state = _state;
    this._payloadModule = new StatePayloadModule(_state);
    this.pushDep(this._payloadModule);
  }
  _payloadModule;
  async getContent() {
    const { _payloadModule } = this;
    const payloadImport = _payloadModule.import(this);
    const exportName = strings.typeName(this._name);
    return [
      consts.GENERATED_HEADER,
      `import * as ${_payloadModule.name} from './${payloadImport}'`,
      `export type ${exportName} = {`,
      `  type: ${gen.primitiveToTypescriptValue(this._state.type)},`,
      `  payload: ${_payloadModule.name}.${_payloadModule.exportName}`,
      "}"
    ].join("\n");
  }
}
class StatesModule extends import_module.ReExportTypeModule {
  constructor(states) {
    super({ exportName: strings.typeName("states") });
    for (const [stateName, state] of Object.entries(states)) {
      const module2 = new StateModule(stateName, state);
      module2.unshift(stateName);
      this.pushDep(module2);
    }
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  StateModule,
  StatePayloadModule,
  StatesModule
});
//# sourceMappingURL=states-module.js.map
