import { Group } from '@mantine/core';
import dayjs from 'dayjs';
import { RiSubtractLine } from 'react-icons/ri';
import { Button } from '/@/renderer/components/button';
import { TextInput } from '/@/renderer/components/input';
import { Select } from '/@/renderer/components/select';
import { QueryBuilderRule } from '/@/renderer/types';
const operators = [
{ label: 'is', value: 'is' },
{ label: 'is not', value: 'isNot' },
{ label: 'is greater than', value: 'gt' },
{ label: 'is less than', value: 'lt' },
{ label: 'contains', value: 'contains' },
{ label: 'does not contain', value: 'notContains' },
{ label: 'starts with', value: 'startsWith' },
{ label: 'ends with', value: 'endsWith' },
{ label: 'is in the range', value: 'inTheRange' },
{ label: 'before', value: 'before' },
{ label: 'after', value: 'after' },
{ label: 'is in the last', value: 'inTheLast' },
{ label: 'is not in the last', value: 'notInTheLast' },
];
type DeleteArgs = {
groupIndex: number[];
level: number;
uniqueId: string;
};
interface QueryOptionProps {
data: QueryBuilderRule;
filters: { label: string; value: string }[];
groupIndex: number[];
// groupValue: string;
level: number;
noRemove: boolean;
onChangeField: (args: any) => void;
onChangeOperator: (args: any) => void;
onChangeValue: (args: any) => void;
onDeleteRule: (args: DeleteArgs) => void;
}
export const QueryBuilderOption = ({
data,
filters,
level,
onDeleteRule,
groupIndex,
noRemove,
onChangeField,
onChangeOperator,
onChangeValue,
}: QueryOptionProps) => {
const { field, operator, uniqueId, value } = data;
const handleDeleteRule = () => {
onDeleteRule({ groupIndex, level, uniqueId });
};
const handleChangeField = (e: any) => {
onChangeField({ groupIndex, level, uniqueId, value: e });
};
const handleChangeOperator = (e: any) => {
onChangeOperator({ groupIndex, level, uniqueId, value: e });
};
const handleChangeValue = (e: any) => {
console.log('e', e);
const isDirectValue =
typeof e === 'string' ||
typeof e === 'number' ||
typeof e === 'undefined' ||
typeof e === null;
if (isDirectValue) {
return onChangeValue({
groupIndex,
level,
uniqueId,
value: e,
});
}
const isDate = e instanceof Date;
if (isDate) {
return onChangeValue({
groupIndex,
level,
uniqueId,
value: dayjs(e).format('YYYY-MM-DD'),
});
}
return onChangeValue({
groupIndex,
level,
uniqueId,
value: e.currentTarget.value,
});
};
// const filterOperatorMap = {
// date: (
//
// ),
// id: (
//
// ),
// number: (
//
// ),
// string: (
//
// ),
// };
// const filterInputValueMap = {
// 'albumArtists.genres.id': (
//
// ),
// 'albumArtists.name': (
//
// ),
// 'albumArtists.ratings.value': (
//
// ),
// 'albums.dateAdded': (
//
// ),
// 'albums.genres.id': (
//
// ),
// 'albums.name': (
//
// ),
// 'albums.playCount': (
// handleChangeValue(e)}
// />
// ),
// 'albums.ratings.value': (
//
// ),
// 'albums.releaseDate': (
//
// ),
// 'albums.releaseYear': (
//
// ),
// 'artists.genres.id': (
//
// ),
// 'artists.name': (
//
// ),
// 'artists.ratings.value': (
//
// ),
// 'songs.genres.id': (
//
// ),
// 'songs.name': (
//
// ),
// 'songs.playCount': (
//
// ),
// 'songs.ratings.value': (
//
// ),
// };
const ml = (level + 1) * 10;
return (
{field ? (
) : (
)}
{/* // filterOperatorMap[ // OPTIONS_MAP[field as keyof typeof OPTIONS_MAP].type as keyof typeof
filterOperatorMap // ] */}
);
};