import { makeBbox } from './utils';

export function happenedToday(change) {
    return change.neu && (
        new Date(change.neu.timestamp).toDateString() ===
        new Date().toDateString()
    );
}

export function userNotIgnored(change) {
    const ignore = ['bot-mode'];
    return (change.old && ignore.indexOf(change.old.user) === -1)
        || (change.neu && ignore.indexOf(change.neu.user) === -1);
}

export function wayLongEnough(change) {
    return (change.old && change.old.linestring && change.old.linestring.length > 4)
        || (change.neu && change.neu.linestring && change.neu.linestring.length > 4);
}

export function acceptableType(change) {
    return (change.old && change.old.type)
        || (change.neu && change.neu.type) !== 'relation';
}

export function withinBbox(change, bbox) {
    const c = change;
    const type = (c.old && c.old.type) || (c.neu && c.neu.type);
    let within = false;

    if (type == 'way') {
        const bbox_intersects_old = (c.old && c.old.bounds && bbox.intersects(makeBbox(c.old.bounds)));
        const bbox_intersects_new = (c.neu && c.neu.bounds && bbox.intersects(makeBbox(c.neu.bounds)));
        within = (bbox_intersects_old || bbox_intersects_new);
    } else if (type == 'node') {
        const bbox_contains_old = (c.old && c.old.lat && c.old.lon && bbox.contains(new L.LatLng(c.old.lat, c.old.lon)));
        const bbox_contains_new = (c.neu && c.neu.lat && c.neu.lon && bbox.contains(new L.LatLng(c.neu.lat, c.neu.lon)));
        within = (bbox_contains_old || bbox_contains_new);
    } else {
        console.error('no bbox check for this geometry type');
    }

    return within;
}

export function hasTags(change) {
    return (change.neu && Object.keys(change.neu.tags || {}).length > 0) 
        || (change.old && Object.keys(change.old.tags || {}).length > 0);
}

@@ -445,38 +445,44 @@
 h(change) %7B%0A    
-return
+const type =
  (change.old && 
@@ -473,32 +473,135 @@
  (change.old && 
+change.old.type) %7C%7C (change.neu && change.neu.type);%0A    if (type !== 'way') return true;%0A%0A    return (
 change.old.lines
@@ -665,30 +665,16 @@
 ange.neu
- && change.neu
 .linestr

Fix bug that only allowed linestrings