import { c as P } from "./index-fFOslvm5.mjs";
import { h as c } from "./moment-h96o7c8I.mjs";
import { E as d } from "./constants-3JiawOc1.mjs";
const g = ({
  tableOptions: e,
  data: r,
  readonly: t,
  createTitle: n,
  tableName: o,
  t: s
}) => ({
  ...e,
  readonly: t,
  tableName: o || s(e.tableName),
  columns: e.columns.map((a) => ({
    ...a,
    header: s(a.header)
  })),
  data: r ?? [],
  createActions: [{ title: s(n), icon: "add_circle" }]
}), u = "YYYY-MM-DD", f = `${u} hh:mm:ss`, i = (e) => e ? c.unix(e).format(u) : null, m = (e) => e ? c(e, f).valueOf() / 1e3 : null, v = (e) => {
  const r = P(e ?? {});
  return {
    ...r,
    bulkAndPromotionPrices: (r.bulkAndPromotionPrices ?? []).map(
      ({ validFrom: t, validTo: n, ...o }) => ({
        ...o,
        validFrom: i(t),
        validTo: i(n)
      })
    )
  };
}, x = (e) => {
  const r = P(e ?? {});
  return {
    ...r,
    bulkAndPromotionPrices: (r.bulkAndPromotionPrices ?? []).map(
      ({ validFrom: t, validTo: n, ...o }) => ({
        ...o,
        validFrom: m(`${t} 00:00:00`),
        validTo: m(`${n} 23:59:59`)
      })
    )
  };
}, p = (e, r) => {
  let t = !0;
  return [
    { startQuantity: 0, price: e.basePrice },
    ...e.bulkAndPromotionPrices.filter(({ validFrom: n, validTo: o }) => !n || n <= r && o >= r ? (t = t && !n, !0) : !1).filter(({ validFrom: n }) => t || n)
  ];
}, A = (e, r = c({ hour: 0 }).valueOf() / 1e3) => {
  const t = p(e, r);
  return t.length ? t.reduce(
    ([n, o], { price: { price: s } }) => [
      Math.min(n, s),
      Math.max(o, s)
    ],
    [1 / 0, -1 / 0]
  ) : [-1, 0];
}, l = (e, r = 2) => typeof e != "number" ? d : e.toFixed(r), D = (e, r, t) => {
  const [n, o] = A(e, t);
  return n < 0 ? "-" : `${l(n, r)} - ${l(o, r)}`;
};
export {
  g as a,
  v as b,
  m as c,
  x as d,
  p as g,
  l as p,
  D as s
};
