import { s as R } from "./source-identity-qAmkNtEK.js";
function t(e, i, s) {
  return s ? { code: e, message: i, path: s } : { code: e, message: i };
}
function T(e) {
  for (let i = 0; i < e.length; i += 1) {
    const s = e[i];
    if (e.some(
      (r, o) => o !== i && S(r, s)
    ))
      return !1;
  }
  return !0;
}
function I(e, i) {
  return R(e, i);
}
function S(e, i) {
  return I(e, i) && y(e) === y(i);
}
function F(e) {
  return `Metric intent has duplicate metric "${e.name}" with the same aggregate (${y(e)}). Use different aggregates to request both, or remove one entry.`;
}
function D(e, i) {
  return g(e, i).length === 1;
}
function j(e, i) {
  return g(e, i).length === 1;
}
function g(e, i) {
  return i.filter(
    (r) => O(e, r)
  );
}
function O(e, i) {
  return C(e, i) ? e.source ? I(i, e) : !0 : !1;
}
function C(e, i) {
  return !(i.name !== e.name || e.role !== void 0 && i.role !== void 0 && i.role !== e.role || E(e, i) && y(i) !== y(e));
}
function E(e, i) {
  return e.role === "measure" || i.role === "measure" || e.aggregate !== void 0 || i.aggregate !== void 0;
}
function y(e) {
  return (e.aggregate || "SUM").toUpperCase();
}
const q = /^(\d{4})-(\d{2})-(\d{2})$/, U = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/;
function A(e) {
  if (typeof e != "string")
    return null;
  const i = e.trim(), s = q.exec(i);
  if (s) {
    const [, v, b, w] = s;
    return M(v, b, w) ? new Date(
      Date.UTC(Number(v), Number(b) - 1, Number(w))
    ) : null;
  }
  const r = U.exec(i);
  if (!r)
    return null;
  const [, o, a, n, p, c, l = "00", , f] = r;
  if (!M(o, a, n) || !_(p, 0, 23) || !_(c, 0, 59) || !_(l, 0, 59) || !P(f))
    return null;
  const h = new Date(i);
  return Number.isFinite(h.getTime()) ? h : null;
}
function M(e, i, s) {
  const r = Number(e), o = Number(i), a = Number(s);
  if (!Number.isInteger(r) || !Number.isInteger(o) || !Number.isInteger(a) || o < 1 || o > 12)
    return !1;
  const n = new Date(Date.UTC(r, o - 1, a));
  return n.getUTCFullYear() === r && n.getUTCMonth() === o - 1 && n.getUTCDate() === a;
}
function _(e, i, s) {
  const r = Number(e);
  return Number.isInteger(r) && r >= i && r <= s;
}
function P(e) {
  if (e === "Z")
    return !0;
  const i = /^([+-])(\d{2}):(\d{2})$/.exec(e);
  return !!(i && _(i[2], 0, 23) && _(i[3], 0, 59));
}
function d(e) {
  return typeof e == "string" && e.trim().length > 0;
}
function u(e) {
  return !!(e && typeof e == "object" && !Array.isArray(e));
}
function $(e) {
  const i = /* @__PURE__ */ new Set();
  for (const s of e) {
    if (i.has(s))
      return s;
    i.add(s);
  }
  return null;
}
const G = /* @__PURE__ */ new Set([
  "SUM",
  "COUNT",
  "AVG",
  "MIN",
  "MAX",
  "MEDIAN",
  "DISTINCT"
]);
function k(e, i, s) {
  if (!e || typeof e != "object") {
    s.push(t("missing_source", "Analytics intent needs a source.", i));
    return;
  }
  if (e.kind === "semantic") {
    d(e.domainId) || s.push(
      t(
        "missing_semantic_domain",
        "Semantic source needs a domainId.",
        `${i}.domainId`
      )
    ), d(e.datasetName) || s.push(
      t(
        "missing_dataset_name",
        "Semantic source needs a datasetName.",
        `${i}.datasetName`
      )
    );
    return;
  }
  if (e.kind === "physical") {
    d(e.connectionId) || s.push(
      t(
        "missing_connection_id",
        "Physical source needs a connectionId.",
        `${i}.connectionId`
      )
    ), d(e.tableName) || s.push(
      t(
        "missing_table_name",
        "Physical source needs a tableName.",
        `${i}.tableName`
      )
    );
    return;
  }
  if (e.kind === "sql") {
    d(e.connectionId) || s.push(
      t(
        "missing_connection_id",
        "SQL source needs a connectionId.",
        `${i}.connectionId`
      )
    );
    return;
  }
  s.push(t("invalid_source_kind", "Source kind is not supported.", i));
}
function m(e, i, s, r = {}) {
  if (!e || !u(e)) {
    r.required && s.push(
      t("missing_field_ref", "Field reference needs a name.", i)
    );
    return;
  }
  d(e.name) || s.push(
    t("missing_field_ref", "Field reference needs a name.", `${i}.name`)
  ), e.source !== void 0 && k(e.source, `${i}.source`, s), H(e.aggregate, `${i}.aggregate`, s);
}
function H(e, i, s) {
  e !== void 0 && (typeof e != "string" || !G.has(e)) && s.push(
    t(
      "invalid_aggregate",
      "Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",
      i
    )
  );
}
function L(e, i) {
  if (e.analysis === void 0)
    return;
  if (!u(e.analysis)) {
    i.push(
      t(
        "invalid_metric_analysis",
        "Metric analysis must be a structured object.",
        "analysis"
      )
    );
    return;
  }
  if (e.analysis.kind !== "period_change") {
    i.push(
      t(
        "invalid_metric_analysis",
        "Metric analysis kind is not supported.",
        "analysis.kind"
      )
    );
    return;
  }
  e.dateField || i.push(
    t(
      "missing_analysis_date_field",
      "Period-change analysis needs a dateField.",
      "dateField"
    )
  ), e.timeGrain || i.push(
    t(
      "missing_analysis_time_grain",
      "Period-change analysis needs a timeGrain.",
      "timeGrain"
    )
  ), e.analysis.orderBy !== void 0 && e.analysis.orderBy !== "absolute_change" && e.analysis.orderBy !== "positive_change" && e.analysis.orderBy !== "negative_change" && e.analysis.orderBy !== "period" && i.push(
    t(
      "invalid_metric_analysis",
      "Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.",
      "analysis.orderBy"
    )
  );
  const { timeWindow: s } = e.analysis;
  s !== void 0 && N(s, "analysis.timeWindow", i);
}
function N(e, i, s) {
  if (!u(e)) {
    s.push(
      t(
        "invalid_time_window",
        "Time window must be a structured object.",
        i
      )
    );
    return;
  }
  if (e.kind !== void 0 && e.kind !== "relative" && e.kind !== "absolute" && s.push(
    t(
      "invalid_time_window",
      "Time window kind must be relative or absolute.",
      `${i}.kind`
    )
  ), e.kind === "absolute") {
    if (d(e.start) || s.push(
      t(
        "invalid_time_window",
        "Absolute time window start must be a non-empty ISO date or timestamp string.",
        `${i}.start`
      )
    ), d(e.end) || s.push(
      t(
        "invalid_time_window",
        "Absolute time window end must be a non-empty ISO date or timestamp string.",
        `${i}.end`
      )
    ), d(e.start) && d(e.end)) {
      const r = A(e.start), o = A(e.end);
      r || s.push(
        t(
          "invalid_time_window",
          "Absolute time window start must be a valid ISO date or timestamp.",
          `${i}.start`
        )
      ), o || s.push(
        t(
          "invalid_time_window",
          "Absolute time window end must be a valid ISO date or timestamp.",
          `${i}.end`
        )
      ), r && o && r.getTime() > o.getTime() && s.push(
        t(
          "invalid_time_window",
          "Absolute time window start must be before or equal to end.",
          i
        )
      );
    }
    return;
  }
  e.unit !== "second" && e.unit !== "minute" && e.unit !== "hour" && e.unit !== "day" && e.unit !== "week" && e.unit !== "month" && e.unit !== "quarter" && e.unit !== "year" && s.push(
    t(
      "invalid_time_window",
      "Time window unit must be second, minute, hour, day, week, month, quarter, or year.",
      `${i}.unit`
    )
  ), (typeof e.value != "number" || !Number.isFinite(e.value) || e.value <= 0) && s.push(
    t(
      "invalid_time_window",
      "Time window value must be a positive number.",
      `${i}.value`
    )
  ), e.anchor !== void 0 && e.anchor !== "now" && e.anchor !== "latest_available" && s.push(
    t(
      "invalid_time_window",
      "Time window anchor must be now or latest_available.",
      `${i}.anchor`
    )
  ), e.completeness !== void 0 && e.completeness !== "include_partial" && e.completeness !== "complete_periods" && s.push(
    t(
      "invalid_time_window",
      "Time window completeness must be include_partial or complete_periods.",
      `${i}.completeness`
    )
  );
}
function V(e, i, s) {
  if (e !== void 0) {
    if (!Array.isArray(e)) {
      s.push(
        t(
          "invalid_analytics_filters",
          "Analytics filters must be an array.",
          i
        )
      );
      return;
    }
    e.forEach((r, o) => {
      var c;
      const a = `${i}.${o}`;
      if (!u(r)) {
        s.push(
          t(
            "invalid_analytics_filter",
            "Analytics filter must be a structured object.",
            a
          )
        );
        return;
      }
      const n = r;
      m(n.field, `${a}.field`, s, {
        required: !0
      }), n.scope !== void 0 && n.scope !== "row" && n.scope !== "aggregate" && s.push(
        t(
          "invalid_analytics_filter_scope",
          "Analytics filter scope must be row or aggregate.",
          `${a}.scope`
        )
      ), n.scope === "aggregate" && ((c = n.field) == null ? void 0 : c.role) !== void 0 && n.field.role !== "measure" && s.push(
        t(
          "invalid_analytics_filter_scope",
          "Aggregate-scope analytics filters must target a measure field.",
          `${a}.scope`
        )
      );
      const p = n.operator === "is_null" || n.operator === "is_not_null";
      if (n.operator !== void 0 && n.operator !== "=" && n.operator !== "!=" && n.operator !== "in" && n.operator !== "not_in" && n.operator !== "contains" && n.operator !== "not_contains" && n.operator !== "between" && n.operator !== "not_between" && n.operator !== ">" && n.operator !== ">=" && n.operator !== "<" && n.operator !== "<=" && n.operator !== "is_null" && n.operator !== "is_not_null" && s.push(
        t(
          "invalid_analytics_filter_operator",
          "Analytics filter operator is not supported.",
          `${a}.operator`
        )
      ), n.values === void 0 && !p && s.push(
        t(
          "missing_analytics_filter_value",
          "Analytics filter needs values unless it is a null check.",
          a
        )
      ), p && n.values !== void 0) {
        s.push(
          t(
            "invalid_analytics_filter_values",
            "Null-check analytics filters must not include values.",
            `${a}.values`
          )
        );
        return;
      }
      if (n.values !== void 0 && !Array.isArray(n.values)) {
        s.push(
          t(
            "invalid_analytics_filter_values",
            "Analytics filter values must be an array when provided.",
            `${a}.values`
          )
        );
        return;
      }
      if (n.values !== void 0) {
        const l = n.values.length;
        if (n.operator === "between" || n.operator === "not_between") {
          l !== 2 && s.push(
            t(
              "invalid_analytics_filter_values",
              "Between analytics filters must include exactly two values.",
              `${a}.values`
            )
          );
          return;
        }
        (n.operator === "contains" || n.operator === "not_contains" || n.operator === "=" || n.operator === "!=" || n.operator === ">" || n.operator === ">=" || n.operator === "<" || n.operator === "<=" || n.operator === void 0) && l !== 1 && s.push(
          t(
            "invalid_analytics_filter_values",
            "Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",
            `${a}.values`
          )
        );
      }
    });
  }
}
function B(e) {
  var r;
  const i = [], s = [];
  if (!e || typeof e != "object")
    return {
      ok: !1,
      errors: [
        t(
          "invalid_analytics_intent",
          "Analytics intent must be a structured object."
        )
      ],
      warnings: s,
      repairHints: [
        {
          code: "invalid_analytics_intent",
          recommendedNextStep: "Send one structured analytics intent object with kind, source, and required fields."
        }
      ]
    };
  if (e.version !== void 0 && e.version !== 1 && i.push(
    t("invalid_version", "Analytics intent version must be 1.", "version")
  ), k(e.source, "source", i), e.kind === "metric") {
    const o = Array.isArray(e.metrics) ? e.metrics.filter(
      (a) => u(a) && d(a.name)
    ) : [];
    if (!Array.isArray(e.metrics) || e.metrics.length === 0 ? i.push(
      t("missing_metric", "Metric intent needs at least one metric.", "metrics")
    ) : e.metrics.some(
      (a) => !u(a) || !d(a.name)
    ) && i.push(
      t(
        "invalid_metric_list",
        "Metric intent metrics must be an array of field references with names.",
        "metrics"
      )
    ), o.forEach((a, n) => {
      m(a, `metrics.${n}`, i, {
        required: !0
      });
    }), o.length > 0 && !T(o)) {
      const a = o.find(
        (n, p) => o.some(
          (c, l) => l !== p && S(c, n)
        )
      );
      a && i.push(
        t(
          "duplicate_metric",
          F(a),
          "metrics"
        )
      );
    }
    if (u(e.primaryMetric) && d(e.primaryMetric.name) && g(
      e.primaryMetric,
      o
    ).length > 1 && i.push(
      t(
        "ambiguous_primary_metric",
        "Metric intent primaryMetric must identify exactly one selected metric.",
        "primaryMetric"
      )
    ), e.primaryMetric !== void 0 && (m(e.primaryMetric, "primaryMetric", i, {
      required: !0
    }), u(e.primaryMetric) && d(e.primaryMetric.name) && o.length > 0 && !D(
      e.primaryMetric,
      o
    ) && i.push(
      t(
        "invalid_primary_metric",
        "Metric intent primaryMetric must match one metric field reference.",
        "primaryMetric"
      )
    )), e.dimensions !== void 0 && !Array.isArray(e.dimensions) ? i.push(
      t(
        "invalid_metric_dimensions",
        "Metric intent dimensions must be an array of field references.",
        "dimensions"
      )
    ) : Array.isArray(e.dimensions) && e.dimensions.some(
      (a) => !u(a) || !d(a.name)
    ) && i.push(
      t(
        "invalid_metric_dimensions",
        "Metric intent dimensions must be an array of field references with names.",
        "dimensions"
      )
    ), e.dateField !== void 0 && m(e.dateField, "dateField", i), e.timeWindow !== void 0 && (N(e.timeWindow, "timeWindow", i), e.dateField || i.push(
      t(
        "missing_time_window_date_field",
        "Metric timeWindow needs a dateField.",
        "dateField"
      )
    )), V(e.filters, "filters", i), Array.isArray(e.dimensions) && e.dimensions.forEach((a, n) => {
      m(a, `dimensions.${n}`, i);
    }), e.orderBy !== void 0) {
      if (!u(e.orderBy))
        i.push(
          t(
            "invalid_metric_order_by",
            "Metric intent orderBy must be a structured object.",
            "orderBy"
          )
        );
      else if (m(e.orderBy.field, "orderBy.field", i, {
        required: !0
      }), e.orderBy.direction !== "asc" && e.orderBy.direction !== "desc" && i.push(
        t(
          "invalid_metric_order_direction",
          "Metric intent orderBy direction must be asc or desc.",
          "orderBy.direction"
        )
      ), u(e.orderBy.field) && d(e.orderBy.field.name)) {
        const a = [
          ...o,
          ...e.timeGrain && e.dateField && u(e.dateField) ? [e.dateField] : [],
          ...Array.isArray(e.dimensions) ? e.dimensions.filter(
            (n) => u(n) && d(n.name)
          ) : []
        ];
        a.length > 0 && !j(
          e.orderBy.field,
          a
        ) && i.push(
          t(
            "invalid_metric_order_by",
            "Metric intent orderBy.field must match one selected metric, grouped dateField, or dimension.",
            "orderBy.field"
          )
        );
      }
    }
    L(e, i);
  } else e.kind === "records" ? (!Array.isArray(e.fields) || e.fields.length === 0 ? i.push(
    t(
      "missing_record_fields",
      "Records intent needs at least one field.",
      "fields"
    )
  ) : e.fields.some(
    (o) => !u(o) || !d(o.name)
  ) && i.push(
    t(
      "invalid_record_fields",
      "Records intent fields must be field references with names.",
      "fields"
    )
  ), Array.isArray(e.fields) && e.fields.forEach((o, a) => {
    m(o, `fields.${a}`, i);
  }), e.dateField !== void 0 && m(e.dateField, "dateField", i), e.orderBy !== void 0 && (u(e.orderBy) ? (m(e.orderBy.field, "orderBy.field", i, {
    required: !0
  }), e.orderBy.direction !== "asc" && e.orderBy.direction !== "desc" && i.push(
    t(
      "invalid_record_order_direction",
      "Records intent orderBy direction must be asc or desc.",
      "orderBy.direction"
    )
  )) : i.push(
    t(
      "invalid_record_order_by",
      "Records intent orderBy must be a structured object.",
      "orderBy"
    )
  ))) : e.kind === "inputOptions" ? ((!e.field || !d(e.field.name)) && i.push(
    t(
      "missing_input_options_field",
      "Input options intent needs a field.",
      "field"
    )
  ), m(e.field, "field", i, { required: !0 })) : e.kind === "sql" ? (((r = e.source) == null ? void 0 : r.kind) !== "sql" && i.push(
    t(
      "invalid_sql_source",
      "SQL analytics intent must use a SQL execution source.",
      "source"
    )
  ), d(e.sql) || i.push(t("missing_sql", "SQL analytics intent needs SQL text.", "sql")), Array.isArray(e.fields) && e.fields.forEach((o, a) => {
    m(o, `fields.${a}`, i);
  })) : i.push(
    t("invalid_analytics_kind", "Analytics kind is not supported.", "kind")
  );
  return {
    ok: i.length === 0,
    errors: i,
    warnings: s,
    repairHints: X(i)
  };
}
function Q(e) {
  const i = [], s = [];
  if (!e || typeof e != "object")
    return {
      ok: !1,
      errors: [
        t(
          "invalid_operation_intent",
          "Operation intent must be a structured object."
        )
      ],
      warnings: s,
      repairHints: [
        {
          code: "invalid_operation_intent",
          recommendedNextStep: "Send one typed operation intent with version, kind, and required operation fields."
        }
      ]
    };
  if (e.version !== 1 && i.push(
    t("invalid_version", "Operation intent version must be 1.", "version")
  ), e.kind === "answer_obligations")
    !Array.isArray(e.obligations) || e.obligations.length === 0 ? i.push(
      t(
        "missing_obligations",
        "Answer-obligations operation intent needs at least one obligation.",
        "obligations"
      )
    ) : e.obligations.forEach((r, o) => {
      d(r.id) || i.push(
        t(
          "missing_obligation_id",
          "Each analytics obligation needs an id.",
          `obligations.${o}.id`
        )
      ), d(r.prompt) || i.push(
        t(
          "missing_obligation_prompt",
          "Each analytics obligation needs a prompt.",
          `obligations.${o}.prompt`
        )
      );
    });
  else if (e.kind === "dashboard_change" || e.kind === "data_app_change") {
    if (d(e.instruction) || i.push(
      t(
        "missing_instruction",
        "Change operation intent needs an instruction.",
        "instruction"
      )
    ), e.analyticsIntent) {
      const r = B(
        e.analyticsIntent
      );
      i.push(...r.errors), s.push(...r.warnings);
    }
  } else
    i.push(
      t(
        "invalid_operation_kind",
        "Operation intent kind is not supported.",
        "kind"
      )
    );
  return {
    ok: i.length === 0,
    errors: i,
    warnings: s,
    repairHints: x(i)
  };
}
function z(e) {
  const i = [], s = [];
  if (!e || typeof e != "object")
    return {
      ok: !1,
      errors: [
        t(
          "invalid_recovery_plan",
          "Analytics recovery plan must be a structured object."
        )
      ],
      warnings: s,
      repairHints: [
        {
          code: "invalid_recovery_plan",
          recommendedNextStep: "Return a typed recovery plan with operationIntent and plannedToolCalls."
        }
      ]
    };
  e.version !== 1 && i.push(
    t("invalid_version", "Recovery plan version must be 1.", "version")
  ), e.kind !== "analytics_recovery_plan" && i.push(
    t(
      "invalid_recovery_plan_kind",
      "Recovery plan kind must be analytics_recovery_plan.",
      "kind"
    )
  );
  const r = Q(e.operationIntent);
  return i.push(...r.errors), s.push(...r.warnings), Array.isArray(e.plannedToolCalls) || i.push(
    t(
      "invalid_planned_tool_calls",
      "Recovery plan plannedToolCalls must be an array.",
      "plannedToolCalls"
    )
  ), {
    ok: i.length === 0,
    errors: i,
    warnings: s,
    repairHints: x(i)
  };
}
function x(e) {
  return e.map((i) => ({
    code: i.code,
    recommendedNextStep: i.code === "missing_obligations" ? "Normalize the user request into one or more typed analytics obligations before recovery planning." : "Correct the operation/recovery contract shape before planning execution."
  }));
}
function X(e) {
  return e.map((i) => {
    switch (i.code) {
      case "missing_source":
        return {
          code: i.code,
          fieldRole: "source",
          recommendedNextStep: "Provide a semantic, physical, or SQL source before executing analytics."
        };
      case "missing_metric":
        return {
          code: i.code,
          fieldRole: "metric",
          recommendedNextStep: "Choose one exact metric from the grounded schema candidates."
        };
      case "missing_record_fields":
        return {
          code: i.code,
          fieldRole: "dimension",
          recommendedNextStep: "Provide at least one field for the records intent."
        };
      case "missing_input_options_field":
        return {
          code: i.code,
          fieldRole: "input",
          recommendedNextStep: "Provide the exact field whose option values should be listed."
        };
      case "missing_sql":
        return {
          code: i.code,
          fieldRole: "sql",
          recommendedNextStep: "Provide bounded read-only SQL with an explicit outer LIMIT."
        };
      case "conflicting_sql":
        return {
          code: i.code,
          fieldRole: "sql",
          recommendedNextStep: "Use one canonical SQL text location for the intent; prefer top-level sql."
        };
      case "missing_semantic_domain":
      case "missing_dataset_name":
      case "missing_connection_id":
      case "missing_table_name":
        return {
          code: i.code,
          fieldRole: "source",
          recommendedNextStep: "Use grounded catalog metadata to fill the missing source reference."
        };
      default:
        return;
    }
  }).filter((i) => !!i);
}
function Y(e, i, s, r) {
  if (!e || typeof e != "object") {
    s.push(t("invalid_view", "Dashboard view must be an object.", i));
    return;
  }
  if (d(e.title) || s.push(t("missing_view_title", "Dashboard view needs a title.", i)), !e.presentation || typeof e.presentation != "object") {
    s.push(
      t(
        "missing_presentation",
        "Dashboard view needs a presentation.",
        `${i}.presentation`
      )
    );
    return;
  }
  if (e.presentation.kind === "text") {
    d(e.text) || r.push(
      t(
        "missing_text_content",
        "Text views should include text content.",
        `${i}.text`
      )
    );
    return;
  }
  if (!e.analytics) {
    s.push(
      t(
        "missing_view_analytics",
        "Non-text dashboard views need analytics intent.",
        `${i}.analytics`
      )
    );
    return;
  }
  const o = B(e.analytics);
  for (const a of o.errors)
    s.push(
      t(a.code, a.message, `${i}.analytics${a.path ? `.${a.path}` : ""}`)
    );
  for (const a of o.warnings)
    r.push(
      t(
        a.code,
        a.message,
        `${i}.analytics${a.path ? `.${a.path}` : ""}`
      )
    );
}
function J(e) {
  const i = [], s = [];
  if (!e || typeof e != "object")
    return {
      ok: !1,
      errors: [
        t(
          "invalid_dashboard_intent",
          "Dashboard intent must be a structured object."
        )
      ],
      warnings: s
    };
  e.version !== 1 && i.push(t("invalid_version", "Dashboard intent version must be 1.")), e.kind !== "dashboard" && i.push(t("invalid_kind", "Experience intent kind must be dashboard.")), d(e.title) || i.push(t("missing_title", "Dashboard intent needs a title.", "title"));
  const r = Array.isArray(e.inputs) ? e.inputs : [], o = $(
    r.filter(u).map((c) => c.id).filter((c) => typeof c == "string")
  );
  o && i.push(
    t(
      "duplicate_input_id",
      `Duplicate input id: ${o}.`,
      "inputs"
    )
  );
  for (const [c, l] of r.entries()) {
    const f = `inputs.${c}`;
    if (!u(l)) {
      i.push(t("invalid_input", "Dashboard input must be an object.", f));
      continue;
    }
    d(l.id) || i.push(t("missing_input_id", "Input needs an id.", `${f}.id`)), d(l.label) || i.push(
      t("missing_input_label", "Input needs a label.", `${f}.label`)
    ), !l.field || !d(l.field.name) ? i.push(
      t("missing_input_field", "Input needs a field.", `${f}.field`)
    ) : m(l.field, `${f}.field`, i);
  }
  const a = Array.isArray(e.sections) ? e.sections : [];
  a.length === 0 && i.push(
    t(
      "missing_sections",
      "Dashboard intent needs at least one section.",
      "sections"
    )
  );
  const n = a.flatMap(
    (c) => c && typeof c == "object" && Array.isArray(c.views) ? c.views.filter(u).map((l) => l.id).filter((l) => !!l) : []
  ), p = $(n);
  p && i.push(
    t(
      "duplicate_view_id",
      `Duplicate dashboard view id: ${p}.`,
      "sections"
    )
  );
  for (const [c, l] of a.entries()) {
    const f = `sections.${c}`;
    if (!l || typeof l != "object") {
      i.push(
        t("invalid_section", "Dashboard section must be an object.", f)
      );
      continue;
    }
    if (d(l.title) || i.push(
      t("missing_section_title", "Dashboard section needs a title.", f)
    ), !Array.isArray(l.views) || l.views.length === 0) {
      i.push(
        t(
          "missing_section_views",
          "Dashboard section needs at least one view.",
          `${f}.views`
        )
      );
      continue;
    }
    for (const [h, v] of l.views.entries())
      Y(
        v,
        `${f}.views.${h}`,
        i,
        s
      );
  }
  return { ok: i.length === 0, errors: i, warnings: s };
}
export {
  Q as a,
  z as b,
  J as c,
  A as p,
  B as v
};
