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

@Pipe({
    name: 'checkinrangeallseat'
})
export class CheckinrangeallseatPipe implements PipeTransform {

    transform(AllSeat: any): any {
        const ArrayAllSeat = AllSeat;
        if (!ArrayAllSeat) return false;
        let isInRange = false;
        if (ArrayAllSeat){
            for (let i = 0; i < ArrayAllSeat.length; i++ ){
                const ArraySeatlist = ArrayAllSeat[i].testing_seat_subjects
                for (let j = 0; j < ArraySeatlist.length; j++ ){
                    if (isInRange === false){
                        isInRange = this.checkInrange(ArraySeatlist , ArraySeatlist[j].start_seat_no , ArraySeatlist[j].end_seat_no)
                    }
                }
            }
        }
        return isInRange;
    }

    checkInrange(Array , Start , End ){
        const ArrayStart = Array.map(x => {
            return x.start_seat_no;
        });
        const ArrayEnd = Array.map(x => {
            return x.end_seat_no;
        });
        let isInRange = false;
        // console.log(ArrayStart)
        // console.log(ArrayEnd)
        for (let i = 0; i < Array.length; i++ ){
            const StartNo = ArrayStart[i];
            const EndNo = ArrayEnd[i];
            for (let j = 0; j < Array.length; j++ ){
                // console.log('Start No: ', StartNo)
                // console.log('End No: ', EndNo)
                // console.log('start_seat_no: ', Array[j].start_seat_no)
                // console.log('end_seat_no: ', Array[j].end_seat_no)
                // console.log(StartNo > Array[i].start_seat_no && StartNo < Array[i].end_seat_no , 'Start Range')
                // console.log(EndNo > Array[i].start_seat_no && EndNo < Array[i].start_seat_no , 'End Range')
                if (isInRange === false){
                    if (StartNo > Array[j].start_seat_no && StartNo <= Array[j].end_seat_no || EndNo > Array[j].start_seat_no && EndNo < Array[j].end_seat_no) {
                        isInRange = true;
                    }
                }
            }
        }
        // console.log(isInRange);
        return isInRange
    }

}
