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

@Pipe({
    name: 'checkdupicateallseat'
})
export class CheckdupicateallseatPipe implements PipeTransform {

    transform(arrs: any): unknown {
        if(!arrs) return false
        let isDucp = false
        console.log('------START------')
        console.log(arrs);
        for (let i = 0; i < arrs.length; i++ ){
            console.log('INDEX: ',i);
            const arr = arrs[i].testing_seat_subjects;
            const ArrayStart = [];
            const ArrayEnd = [];
            const ArrayAllseat = [];
            for (let j = 0; j < arr.length; j++ ){
                // console.log('arr: ',arr[j]);

                    if (arr[j].start_seat_no !== null){
                        ArrayStart.push(arr[j].start_seat_no);
                        ArrayAllseat.push(arr[j].start_seat_no);
                    }
                    if (arr[j].end_seat_no !== null){
                        ArrayEnd.push(arr[j].end_seat_no);
                        ArrayAllseat.push(arr[j].end_seat_no);
                    }

            }
            const checkUniqueArraystart = [...new Set(ArrayStart)];
            const checkUniqueArrayend = [...new Set(ArrayEnd)];
            const checkUniqueArrayAll = [...new Set(ArrayAllseat)];
            console.log('ArrayAllseat: ',ArrayAllseat)
            console.log('checkUniqueArraystart: ',checkUniqueArraystart)
            console.log('checkUniqueArrayend: ',checkUniqueArrayend)
            console.log('checkUniqueArrayAll: ',checkUniqueArrayAll)
            if (ArrayAllseat.length !== 0){
                if (checkUniqueArraystart.length !== 0 && checkUniqueArrayend.length !== 0 && checkUniqueArrayAll.length !== 0) {
                    if (ArrayAllseat.length !== 1){
                        if (ArrayAllseat.length !== checkUniqueArrayAll.length){
                            isDucp = true;
                        }
                    }else {
                        if(ArrayAllseat[0] === checkUniqueArraystart[0] || ArrayAllseat[0] === checkUniqueArrayend[0]){
                            isDucp = true;
                        }
                    }
                }
            }
        }
        console.log('------END------')
        return isDucp

    }

}
