"use client";
let d = 0;
const o = () => `col-${Date.now()}-${++d}`;
function s(e, t) {
  const r = e.id ?? e.accessorKey ?? o(), a = e.headerLabel ?? (typeof e.header == "string" ? e.header : r);
  return {
    id: r,
    header: typeof e.header == "string" ? e.header : () => e.header,
    ...e.accessorKey ? { accessorKey: e.accessorKey } : {},
    ...e.cell ? {
      cell: ({ row: n }) => {
        const i = e.accessorKey ? n.getValue(r) : void 0;
        return e.cell(i, n.original, n);
      }
    } : {},
    meta: {
      type: t,
      headerLabel: a,
      sortable: e.sortable ?? !1,
      filterable: e.filterable ?? !1,
      searchable: e.searchable ?? !1,
      pinned: e.pinned,
      cellClassName: e.cellClassName,
      headerClassName: e.headerClassName
    }
  };
}
function h(e) {
  return s(e, "string");
}
function y(e) {
  return s(e, "number");
}
function _(e) {
  return s(e, "boolean");
}
function C(e) {
  return s(e, "date");
}
function q(e) {
  return s(e, "datetime");
}
function F(e) {
  const t = Array.isArray(e.options) ? typeof e.options[0] == "string" ? e.options.map((a) => ({ value: a, label: a })) : e.options : [], r = s(
    e,
    "list_single_select"
  );
  return {
    ...r,
    meta: {
      ...r.meta,
      type: "list_single_select",
      listOptions: t
    }
  };
}
function K(e) {
  const t = Array.isArray(e.options) ? typeof e.options[0] == "string" ? e.options.map((a) => ({ value: a, label: a })) : e.options : [], r = s(
    e,
    "list_multi_select"
  );
  return {
    ...r,
    meta: {
      ...r.meta,
      type: "list_multi_select",
      listOptions: t
    }
  };
}
function L(e) {
  const t = e.headerLabel ?? (typeof e.header == "string" ? e.header : e.id);
  return {
    id: e.id,
    header: typeof e.header == "string" ? e.header : () => e.header,
    cell: ({ row: r }) => e.cell(r.original),
    meta: {
      type: "other",
      headerLabel: t,
      sortable: !1,
      filterable: !1,
      searchable: !1,
      pinned: e.pinned
    }
  };
}
function v(e) {
  const t = e.id ?? o(), r = e.headerLabel ?? (typeof e.header == "string" ? e.header : t);
  return {
    id: t,
    header: typeof e.header == "string" ? e.header : () => e.header,
    cell: ({ row: a }) => e.cell(a.original),
    meta: {
      type: "other",
      headerLabel: r,
      sortable: !1,
      filterable: !1,
      searchable: e.searchable ?? !1,
      pinned: e.pinned
    }
  };
}
function S(e) {
  const t = e.id ?? o(), r = e.headerLabel ?? (typeof e.header == "string" ? e.header : t);
  return {
    id: t,
    header: typeof e.header == "string" ? e.header : () => e.header,
    cell: ({ row: a }) => e.cell(a.original),
    meta: {
      type: e.type,
      headerLabel: r,
      sortable: e.sortable ?? !1,
      filterable: e.filterable ?? !1,
      searchable: e.searchable ?? !1,
      pinned: e.pinned
    }
  };
}
let m = 0;
const c = () => `filter-${Date.now()}-${++m}`;
function u(e) {
  return {
    id: c(),
    columnId: e.columnId,
    columnAccessorKey: e.columnAccessorKey,
    columnLabel: e.columnLabel,
    columnType: e.columnType,
    operator: e.operator,
    value: e.value,
    listOptions: e.listOptions
  };
}
function O(e) {
  return e.map((t) => u(t));
}
function T(e, t, r, a, l) {
  return u({
    columnId: e,
    columnAccessorKey: t,
    columnLabel: r,
    columnType: "string",
    operator: a,
    value: l
  });
}
function I(e, t, r, a, l) {
  return u({
    columnId: e,
    columnAccessorKey: t,
    columnLabel: r,
    columnType: "number",
    operator: a,
    value: l
  });
}
function B(e, t, r, a, l) {
  return u({
    columnId: e,
    columnAccessorKey: t,
    columnLabel: r,
    columnType: "boolean",
    operator: a,
    value: l
  });
}
function A(e, t, r, a, l) {
  return u({
    columnId: e,
    columnAccessorKey: t,
    columnLabel: r,
    columnType: "date",
    operator: a,
    value: l
  });
}
function D(e, t, r, a, l) {
  return u({
    columnId: e,
    columnAccessorKey: t,
    columnLabel: r,
    columnType: "datetime",
    operator: a,
    value: l
  });
}
function N(e, t, r, a, l, n, i) {
  return u({
    columnId: e,
    columnAccessorKey: t,
    columnLabel: r,
    columnType: a,
    operator: l,
    value: n,
    listOptions: i
  });
}
function p(e) {
  return {
    sort_by: e.map((t) => t.column),
    sort_order: e.map((t) => t.order)
  };
}
function V(e) {
  return {
    ...e.filters && {
      filters: {
        filterBadges: e.filters
      }
    },
    ...e.searchbarFilter && {
      filters: {
        ...e.filters && { filterBadges: e.filters } || {},
        searchbarFilter: e.searchbarFilter
      }
    },
    ...e.sorting && { sorting: p(e.sorting) },
    ...e.pagination && { pagination: e.pagination },
    ...e.columnVisibility && {
      columnVisibility: e.columnVisibility
    }
  };
}
function b(e) {
  return e.map((t) => ({ value: t, label: t }));
}
function k(e, t, r) {
  return e.map((a) => ({
    value: String(a[t]),
    label: String(a[r])
  }));
}
function $(e, t, r) {
  return e.map((a) => {
    if (a.accessorKey === t) {
      const n = typeof r[0] == "string" ? b(r) : r;
      return {
        ...a,
        meta: {
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          ...a.meta,
          listOptions: n
        }
      };
    }
    return a;
  });
}
function M(e, t) {
  return e.map((r) => {
    const a = r.accessorKey || r.id, l = t.left?.includes(a) ? "left" : t.right?.includes(a) ? "right" : void 0;
    return l ? {
      ...r,
      meta: {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        ...r.meta,
        pinned: l
      }
    } : r;
  });
}
function f(e) {
  return e.map((t) => t.accessorKey || t.id).filter(Boolean);
}
function w(e, t) {
  return {
    string: [
      "like",
      "n_like",
      "starts_with",
      "ends_with",
      "eq",
      "ne",
      "eq_null",
      "n_eq_null"
    ],
    number: ["eq", "ne", "lt", "le", "gt", "ge", "eq_null", "n_eq_null"],
    boolean: ["eq", "ne", "checked", "unchecked"],
    date: ["eq", "date_before", "date_after", "eq_null", "n_eq_null"],
    datetime: ["date_time_before", "date_time_after", "eq_null", "n_eq_null"],
    list_single_select: [
      "array_overlap",
      "n_array_overlap",
      "eq_null",
      "n_eq_null"
    ],
    list_multi_select: [
      "array_overlap",
      "n_array_overlap",
      "eq_null",
      "n_eq_null"
    ],
    other: []
  }[t]?.includes(e) ?? !1;
}
export {
  L as createActionColumn,
  _ as createBooleanColumn,
  B as createBooleanFilter,
  S as createComputedColumn,
  C as createDateColumn,
  A as createDateFilter,
  q as createDateTimeColumn,
  D as createDateTimeFilter,
  v as createDisplayColumn,
  u as createFilterBadge,
  O as createFilterBadges,
  V as createInitialState,
  N as createListFilter,
  K as createMultiSelectColumn,
  y as createNumberColumn,
  I as createNumberFilter,
  F as createSingleSelectColumn,
  p as createSorting,
  h as createStringColumn,
  T as createStringFilter,
  f as getColumnIds,
  w as isValidOperatorForType,
  M as pinColumns,
  b as toSelectOptions,
  k as toSelectOptionsFromObjects,
  $ as updateColumnListOptions
};
