import {
  useDate
} from "./chunk-UZWFZMOX.js";

// src/components/data-table/helpers/general/use-data-table-date-columns.tsx
import {
  createDataTableColumnHelper,
  Tooltip
} from "@medusajs/ui";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { jsx } from "react/jsx-runtime";
var columnHelper = createDataTableColumnHelper();
var useDataTableDateColumns = () => {
  const { t } = useTranslation();
  const { getFullDate } = useDate();
  return useMemo(() => {
    return [
      columnHelper.accessor("created_at", {
        header: t("fields.createdAt"),
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx(
            Tooltip,
            {
              content: getFullDate({
                date: row.original.created_at,
                includeTime: true
              }),
              children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: row.original.created_at }) })
            }
          );
        },
        enableSorting: true,
        sortAscLabel: t("filters.sorting.dateAsc"),
        sortDescLabel: t("filters.sorting.dateDesc")
      }),
      columnHelper.accessor("updated_at", {
        header: t("fields.updatedAt"),
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx(
            Tooltip,
            {
              content: getFullDate({
                date: row.original.updated_at,
                includeTime: true
              }),
              children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: row.original.updated_at }) })
            }
          );
        },
        enableSorting: true,
        sortAscLabel: t("filters.sorting.dateAsc"),
        sortDescLabel: t("filters.sorting.dateDesc")
      })
    ];
  }, [t, getFullDate]);
};

// src/components/data-table/helpers/general/use-data-table-date-filters.tsx
import { createDataTableFilterHelper } from "@medusajs/ui";
import { subDays, subMonths } from "date-fns";
import { useMemo as useMemo2 } from "react";
import { useTranslation as useTranslation2 } from "react-i18next";
var filterHelper = createDataTableFilterHelper();
var useDateFilterOptions = () => {
  const { t } = useTranslation2();
  const today = useMemo2(() => {
    const date = /* @__PURE__ */ new Date();
    date.setHours(0, 0, 0, 0);
    return date;
  }, []);
  return useMemo2(() => {
    return [
      {
        label: t("filters.date.today"),
        value: {
          $gte: today.toISOString()
        }
      },
      {
        label: t("filters.date.lastSevenDays"),
        value: {
          $gte: subDays(today, 7).toISOString()
          // 7 days ago
        }
      },
      {
        label: t("filters.date.lastThirtyDays"),
        value: {
          $gte: subDays(today, 30).toISOString()
          // 30 days ago
        }
      },
      {
        label: t("filters.date.lastNinetyDays"),
        value: {
          $gte: subDays(today, 90).toISOString()
          // 90 days ago
        }
      },
      {
        label: t("filters.date.lastTwelveMonths"),
        value: {
          $gte: subMonths(today, 12).toISOString()
          // 12 months ago
        }
      }
    ];
  }, [today, t]);
};
var useDataTableDateFilters = (disableRangeOption) => {
  const { t } = useTranslation2();
  const { getFullDate } = useDate();
  const dateFilterOptions = useDateFilterOptions();
  const rangeOptions = useMemo2(() => {
    if (disableRangeOption) {
      return {
        disableRangeOption: true
      };
    }
    return {
      rangeOptionStartLabel: t("filters.date.starting"),
      rangeOptionEndLabel: t("filters.date.ending"),
      rangeOptionLabel: t("filters.date.custom"),
      options: dateFilterOptions
    };
  }, [disableRangeOption, t, dateFilterOptions]);
  return useMemo2(() => {
    return [
      filterHelper.accessor("created_at", {
        type: "date",
        label: t("fields.createdAt"),
        format: "date",
        formatDateValue: (date) => getFullDate({ date }),
        options: dateFilterOptions,
        ...rangeOptions
      }),
      filterHelper.accessor("updated_at", {
        type: "date",
        label: t("fields.updatedAt"),
        format: "date",
        formatDateValue: (date) => getFullDate({ date }),
        options: dateFilterOptions,
        ...rangeOptions
      })
    ];
  }, [t, dateFilterOptions, getFullDate, rangeOptions]);
};

export {
  useDataTableDateColumns,
  useDataTableDateFilters
};
