import { __exports as $ } from "../../../../../../../../_virtual/format.js";
import { __require as x } from "../../compile/codegen/index.js";
var v;
function S() {
  if (v) return $;
  v = 1, Object.defineProperty($, "__esModule", { value: !0 });
  const t = x(), w = {
    keyword: "format",
    type: ["number", "string"],
    schemaType: "string",
    $data: !0,
    error: {
      message: ({ schemaCode: s }) => (0, t.str)`must match format "${s}"`,
      params: ({ schemaCode: s }) => (0, t._)`{format: ${s}}`
    },
    code(s, _) {
      const { gen: n, data: i, $data: F, schema: u, schemaCode: l, it: E } = s, { opts: c, errSchemaPath: k, schemaEnv: y, self: m } = E;
      if (!c.validateFormats)
        return;
      F ? R() : b();
      function R() {
        const o = n.scopeValue("formats", {
          ref: m.formats,
          code: c.code.formats
        }), a = n.const("fDef", (0, t._)`${o}[${l}]`), f = n.let("fType"), e = n.let("format");
        n.if((0, t._)`typeof ${a} == "object" && !(${a} instanceof RegExp)`, () => n.assign(f, (0, t._)`${a}.type || "string"`).assign(e, (0, t._)`${a}.validate`), () => n.assign(f, (0, t._)`"string"`).assign(e, a)), s.fail$data((0, t.or)(d(), p()));
        function d() {
          return c.strictSchema === !1 ? t.nil : (0, t._)`${l} && !${e}`;
        }
        function p() {
          const g = y.$async ? (0, t._)`(${a}.async ? await ${e}(${i}) : ${e}(${i}))` : (0, t._)`${e}(${i})`, r = (0, t._)`(typeof ${e} == "function" ? ${g} : ${e}.test(${i}))`;
          return (0, t._)`${e} && ${e} !== true && ${f} === ${_} && !${r}`;
        }
      }
      function b() {
        const o = m.formats[u];
        if (!o) {
          d();
          return;
        }
        if (o === !0)
          return;
        const [a, f, e] = p(o);
        a === _ && s.pass(g());
        function d() {
          if (c.strictSchema === !1) {
            m.logger.warn(r());
            return;
          }
          throw new Error(r());
          function r() {
            return `unknown format "${u}" ignored in schema at path "${k}"`;
          }
        }
        function p(r) {
          const q = r instanceof RegExp ? (0, t.regexpCode)(r) : c.code.formats ? (0, t._)`${c.code.formats}${(0, t.getProperty)(u)}` : void 0, h = n.scopeValue("formats", { key: u, ref: r, code: q });
          return typeof r == "object" && !(r instanceof RegExp) ? [r.type || "string", r.validate, (0, t._)`${h}.validate`] : ["string", r, h];
        }
        function g() {
          if (typeof o == "object" && !(o instanceof RegExp) && o.async) {
            if (!y.$async)
              throw new Error("async format in sync schema");
            return (0, t._)`await ${e}(${i})`;
          }
          return typeof f == "function" ? (0, t._)`${e}(${i})` : (0, t._)`${e}.test(${i})`;
        }
      }
    }
  };
  return $.default = w, $;
}
export {
  S as __require
};
//# sourceMappingURL=format.js.map
