import * as util from '../util';
let zIndexSort = function( a, b ){
let cy = a.cy();
let hasCompoundNodes = cy.hasCompoundNodes();
function getDepth(ele){
let style = ele.pstyle( 'z-compound-depth' );
if ( style.value === 'auto' ){
return hasCompoundNodes ? ele.zDepth() : 0;
} else if ( style.value === 'bottom' ){
return -1;
} else if ( style.value === 'top' ){
return util.MAX_INT;
}
return 0;
}
let depthDiff = getDepth(a) - getDepth(b);
if ( depthDiff !== 0 ){
return depthDiff;
}
function getEleDepth(ele){
let style = ele.pstyle( 'z-index-compare' );
if ( style.value === 'auto' ){
return ele.isNode() ? 1 : 0;
}
return 0;
}
let eleDiff = getEleDepth(a) - getEleDepth(b);
if ( eleDiff !== 0 ){
return eleDiff;
}
let zDiff = a.pstyle( 'z-index' ).value - b.pstyle( 'z-index' ).value;
if ( zDiff !== 0 ){
return zDiff;
}
return a.poolIndex() - b.poolIndex();
};
export default zIndexSort;