66 lines
2.9 KiB
JavaScript
66 lines
2.9 KiB
JavaScript
|
|
import { money } from "../../lib/constants";
|
||
|
|
import FilterableRow from "../FilterableRow";
|
||
|
|
|
||
|
|
// Barras Gana/Pierde apiladas por categoría + motivo de pérdida más frecuente — puerto de
|
||
|
|
// comparePanelMotivo() (App Informe/assets/js/tables.js). `cats` viene de catsWonLost() (derive.js).
|
||
|
|
// `dimKey` opcional: si se pasa, cada categoría es clicleable y filtra la página (ver Panel.js).
|
||
|
|
export default function ComparePanelMotivo({ title, hint, cats, dimKey }) {
|
||
|
|
const max = Math.max(...cats.flatMap((c) => [c.ganaV, c.pierdeV]), 0.1);
|
||
|
|
const fmtV = (v) => (v < 20 ? `$${v.toFixed(2)}` : money(v));
|
||
|
|
const Row = dimKey ? FilterableRow : "div";
|
||
|
|
const rowProps = (k) => (dimKey ? { as: "div", pairs: [[dimKey, k]] } : {});
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="panel">
|
||
|
|
<h3>{title}</h3>
|
||
|
|
<p className="hint">{hint}</p>
|
||
|
|
{cats.length === 0 ? (
|
||
|
|
<p className="hint">Sin datos en este período.</p>
|
||
|
|
) : (
|
||
|
|
cats.map((c) => (
|
||
|
|
<Row
|
||
|
|
key={c.k}
|
||
|
|
{...rowProps(c.k)}
|
||
|
|
className={dimKey ? "cwm-row" : undefined}
|
||
|
|
style={{ padding: "7px 4px", borderBottom: "1px solid var(--linea)" }}
|
||
|
|
>
|
||
|
|
<div style={{ fontSize: 12.5, marginBottom: 5, fontWeight: 700 }}>{c.k}</div>
|
||
|
|
<div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 3 }}>
|
||
|
|
<span style={{ fontSize: 10, color: "var(--gana)", width: 52 }}>Gana</span>
|
||
|
|
<div className="bar-cell">
|
||
|
|
<div className="bar-fill" style={{ width: `${((c.ganaV / max) * 100).toFixed(1)}%` }} />
|
||
|
|
</div>
|
||
|
|
<span className="v">
|
||
|
|
{fmtV(c.ganaV)}
|
||
|
|
<span style={{ color: "var(--tinta-suave)" }}> ({c.ganaN})</span>
|
||
|
|
</span>
|
||
|
|
</div>
|
||
|
|
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||
|
|
<span style={{ fontSize: 10, color: "var(--pierde)", width: 52 }}>Pierde</span>
|
||
|
|
<div className="bar-cell">
|
||
|
|
<div className="bar-fill pierde" style={{ width: `${((c.pierdeV / max) * 100).toFixed(1)}%` }} />
|
||
|
|
</div>
|
||
|
|
<span className="v">
|
||
|
|
{fmtV(c.pierdeV)}
|
||
|
|
<span style={{ color: "var(--tinta-suave)" }}> ({c.pierdeN})</span>
|
||
|
|
</span>
|
||
|
|
</div>
|
||
|
|
{(c.topMotivo || c.depu > 0) && (
|
||
|
|
<p className="hint" style={{ margin: "4px 0 0" }}>
|
||
|
|
{c.topMotivo ? (
|
||
|
|
<>
|
||
|
|
Motivo principal de pérdida: <b>{c.topMotivo}</b> ({c.topMotivoN} de {c.pierdeN})
|
||
|
|
{c.depu ? ` · ${c.depu} más son depuración sin motivo real` : ""}
|
||
|
|
</>
|
||
|
|
) : (
|
||
|
|
<>{c.depu} de {c.pierdeN} pérdidas son depuración sin motivo real — no hay una razón de negocio clara aquí</>
|
||
|
|
)}
|
||
|
|
</p>
|
||
|
|
)}
|
||
|
|
</Row>
|
||
|
|
))
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|