// 定义数据行类型
type DataRow = { [key: string]: any };

// 筛选函数
function Filter(data: DataRow[], text: string, columns?: string[]): DataRow[] {
    const dec = parseFloat(text);
    const isDec = !isNaN(dec);
    const time = new Date(text);
    const isTime = !isNaN(time.getTime());

    return data.filter((row) => {
        return Object.entries(row).some(([columnName, value]) => {
            if (columns && !columns.includes(columnName)) {
                return false;
            }

            if (typeof value === 'string') {
                return value.includes(text);
            } else if (value instanceof Date && isTime) {
                const nextDay = new Date(time);
                nextDay.setDate(nextDay.getDate() + 1);
                return value > time && value < nextDay;
            } else if (isDec && (typeof value === 'number')) {
                return value === dec;
            }
            return false;
        });
    });
}

export { Filter };