// FeedbackPresenter.jsx — shared rendering for loading/error/success/empty states. (function () { const STATE_DEFAULTS = { loading: { icon: "ri-loader-4-line", message: "Загрузка…", tone: "neutral", ariaBusy: true, }, error: { icon: "ri-error-warning-line", message: "Не удалось выполнить действие", tone: "danger", ariaBusy: false, }, warning: { icon: "ri-alert-line", message: "Требуется внимание", tone: "warning", ariaBusy: false, }, info: { icon: "ri-information-line", message: "Информация", tone: "neutral", ariaBusy: false, }, success: { icon: "ri-checkbox-circle-line", message: "Операция выполнена", tone: "success", ariaBusy: false, }, empty: { icon: "ri-inbox-line", message: "Данных пока нет", tone: "muted", ariaBusy: false, }, }; function resolveState(state) { if (typeof state !== "string") return "empty"; const normalized = state.trim().toLowerCase(); return Object.prototype.hasOwnProperty.call(STATE_DEFAULTS, normalized) ? normalized : "empty"; } function FeedbackPresenter(props) { const safeProps = props || {}; const resolvedState = resolveState(safeProps.state); const defaults = STATE_DEFAULTS[resolvedState]; const icon = safeProps.icon || defaults.icon; const message = safeProps.message || defaults.message; const detail = safeProps.detail || ""; const title = safeProps.title || ""; const tone = safeProps.tone || defaults.tone; const compact = !!safeProps.compact; const className = safeProps.className || ""; const showIcon = safeProps.showIcon !== false; const ariaLive = safeProps.ariaLive || (resolvedState === "error" ? "assertive" : "polite"); const id = typeof safeProps.id === "string" && safeProps.id ? safeProps.id : undefined; const onRetry = typeof safeProps.onRetry === "function" ? safeProps.onRetry : null; const retryLabel = typeof safeProps.retryLabel === "string" && safeProps.retryLabel ? safeProps.retryLabel : "Повторить"; const action = safeProps.action || ( onRetry ? ( ) : null ); const detailId = detail && id ? `${id}__detail` : undefined; const classes = ["feedback-presenter", `feedback-presenter--${resolvedState}`, `feedback-presenter--${tone}`]; if (compact) classes.push("feedback-presenter--compact"); if (className) classes.push(className); return (
{showIcon && ( )}
{title &&
{title}
}
{message}
{detail &&
{detail}
}
{action &&
{action}
}
); } window.FeedbackPresenter = FeedbackPresenter; })();