import { Pipe, PipeTransform } from '@angular/core';
import {unwrapFirst} from 'codelyzer/util/function';

@Pipe({
    name: 'checkdupicateseat'
})
export class CheckdupicateseatPipe implements PipeTransform {

    transform(arr: any): unknown {
        if(!arr) return false
        let isDucp = false
        const ArrayStart = [];
        const ArrayEnd = [];
        const ArrayAllseat = [];
        for (let i = 0; i < arr.length; i++ ){
                if (arr[i].start_seat_no !== null){
                    ArrayStart.push(arr[i].start_seat_no);
                    ArrayAllseat.push(arr[i].start_seat_no);
                }
                if (arr[i].end_seat_no !== null){
                    ArrayEnd.push(arr[i].end_seat_no);
                    ArrayAllseat.push(arr[i].end_seat_no);
                }
        }
        // console.log(ArrayStart, 'ArrayStart');
        // console.log(ArrayEnd, 'ArrayEnd');
        // console.log(ArrayAllseat, 'ArrayAllseat');
        const checkUniqueArraystart = [...new Set(ArrayStart)];
        const checkUniqueArrayend = [...new Set(ArrayEnd)];
        const checkUniqueArrayAll = [...new Set(ArrayAllseat)];
        if (ArrayAllseat.length !== 0){

            if (ArrayAllseat.length !== 1){
                if (ArrayAllseat.length !== checkUniqueArrayAll.length){
                    isDucp = true;
                }
            }else {
                // console.log(ArrayAllseat[0])
                // console.log(checkUniqueArrayAll[0])
                if(ArrayAllseat[0] === checkUniqueArrayend[0] || ArrayAllseat[0] === checkUniqueArrayend[0]){
                    isDucp = true;
                }
            }
        }
        return isDucp
    }

}
