import React from "react";
import { SelectRuleBlock } from "../../RuleBlocks";
import { SegmentAttributeComparator } from "@komi-app/fans-sdk";
import { SelectOption } from "../../../types/select";
import {  getDateRangeComparatorOptions } from "../../../constants/segments/dateRangeComparator";

export interface DateRangeComparatorBlockProps {
  value?: SegmentAttributeComparator;
  onValueChange: (value: SegmentAttributeComparator) => void;
}
export const DateRangeComparatorBlock: React.FC<DateRangeComparatorBlockProps> = ({
  value = SegmentAttributeComparator.Eq,
  onValueChange,
}) => {
  const handleComparatorChange = ([comparator]: SelectOption<SegmentAttributeComparator>[]) => {
    onValueChange(comparator.value);
  };

  return (
    <SelectRuleBlock<string>
      selectedValues={value}
      options={getDateRangeComparatorOptions()}
      onOptionSelectionChange={handleComparatorChange}
    />
  );
};
