import { h as e } from "./p-9b9ccd0c.js";

const n = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];

const daysFromToday = e => {
  const n = new Date;
  // To calculate the time difference of two dates
    const t = n.getTime() - e.getTime();
  // To calculate the no. of days between two dates
    const s = t / (1e3 * 3600 * 24);
  return Math.floor(s);
};

// - - - - - - - - - - - -
// Date Functions
// - - - - - - - - - - - -
const isToday = e => {
  const n = new Date;
  if (n.toDateString() === e.toDateString()) {
    return true;
  }
  return false;
};

const isYesterday = e => {
  const n = new Date;
  n.setDate(n.getDate() - 1);
  if (n.toDateString() === e.toDateString()) {
    return true;
  }
  return false;
};

const formatDate = (e, t = "date-time") => {
  var s;
  let o;
  // validate date
  // undefined or null
    if (e === undefined || e === null) {
    return "";
  }
  // If the date object is invalid it will return 'NaN' on getTime() and NaN is never equal to itself
    const r = e.getTime() === e.getTime();
  if (!r) {
    return "Invalid date";
  }
  let c = "en-US";
  const a = (s = document.getElementsByTagName("html")[0].getAttribute("lang")) === null || s === void 0 ? void 0 : s.valueOf();
  if (a === "es") {
    c = "es-ES";
  }
  o = e.toLocaleDateString(c);
  const i = e.getFullYear();
  const l = String(e.getMonth() + 1).padStart(2, "0");
  const u = String(e.getDate()).padStart(2, "0");
  const d = String(e.getHours()).padStart(2, "0");
  const $ = String(e.getMinutes()).padStart(2, "0");
  const f = `${d}:${$}`;
  if (t === "date-time") {
    o += `  ${e.toLocaleTimeString()}`;
  } else if (t === "date-time-short") {
    // No seconds
    o = `${i}/${l}/${u} ${f}`;
  } else {
    // pretty
    const t = daysFromToday(e);
    const s = new Date;
    const r = s.getFullYear();
    if (isToday(e)) {
      return `Today ${f}`;
    } else if (isYesterday(e)) {
      return `Yesterday ${f}`;
    } else if (t <= 7) {
      // If one week or less, just show the day of the week, and the time
      const t = n[e.getDay()];
      return `${t} ${f}`;
    } else if (r === i) {
      // If current year, show day number and month name. Example: November 17th
      if (c === "es-ES") {
        o = `${u} de ${e.toLocaleString("es-ES", {
          month: "long"
        })} ${f}`;
      } else {
        o = `${e.toLocaleString("en-US", {
          month: "long"
        })} ${u} ${f}`;
      }
    } else {
      // Display date as usual
      o = formatDate(e, "date-time-short");
    }
  }
  return o;
};

const escapeRegExp = e => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

/**
 * @description this function highlights the character(s) that match(es) the filter value.
 * hiChar comes from (hi)light (Char)acters
 * @param text the string to find the filter value on
 * @param filterValue the filter value
 * @returns a span element
 */ const hiChar = function(n, t) {
  if (n && t) {
    const s = escapeRegExp(t);
    const o = new RegExp(s, "gi");
    return e("span", {
      innerHTML: n.replace(o, '<span class="hiChar">$&</span>')
    });
  } else {
    return n;
  }
};

const mapOptionsToComboBoxItemModel = e => e.map((e => ({
  value: e.id,
  caption: e.label
})));

const renderChCheckboxItems = (n, t, s) => n === null || n === void 0 ? void 0 : n.map((n => {
  const o = s === null || s === void 0 ? void 0 : s.find((e => n.value === e || n.id === e));
  return e("ch-checkbox", {
    name: n.name,
    class: "checkbox",
    checkedValue: n.value || n.id,
    caption: n.label,
    disabled: n.disabled,
    value: o,
    onInput: t,
    startImgSrc: n.iconName,
    key: n.value || n.id
  });
}));

export { formatDate as f, hiChar as h, mapOptionsToComboBoxItemModel as m, renderChCheckboxItems as r };
//# sourceMappingURL=p-4d330836.js.map