import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: "orderBy"
})

export class OrderByPipe {

    types: any = ['Occasional Table', 'Seating']; // TODO: should probably be dynamic
    result: any = [];

    constructor() {}

    transform(array: any): any {
        
        for(let type of this.types) {
            for(let product of array) {
                for(let attribute of product.attributes) {
                    if(attribute.code == 'type') {
                        if(type == attribute.value) {
                            this.result.push(product);
                        }
                    }
                }
            }
        }

        return this.result;
    }
}