/**
 * Copyright (c) 2023-present Pi Dash Software, Inc. and contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 * See the LICENSE file for details.
 */

// pi dash imports
import type { TFilterProperty } from "@pi-dash/types";
// local imports
import type { TCreateDateFilterParams, TCreateFilterConfig } from "../shared";
import { createFilterConfig } from "../shared";
import type { TCustomPropertyFilterParams } from "./shared";
import { getSupportedDateOperators } from "./shared";

/**
 * Date property filter specific params
 */
export type TCreateDatePropertyFilterParams = TCustomPropertyFilterParams<Date> & TCreateDateFilterParams;

/**
 * Get the date property filter config
 * @param params - The filter params
 * @returns The date property filter config
 */
export const getDatePropertyFilterConfig =
  <P extends TFilterProperty>(key: P): TCreateFilterConfig<P, TCreateDatePropertyFilterParams> =>
  (params: TCreateDatePropertyFilterParams) =>
    createFilterConfig({
      id: key,
      ...params,
      label: params.propertyDisplayName,
      icon: params.filterIcon,
      allowMultipleFilters: true,
      supportedOperatorConfigsMap: getSupportedDateOperators(params),
    });
