// .zindex(@elementName, @elementList)
//
// Handles z-index contextual by retrieving the elements position from a
// element list and returns the positon as a z-index value.
//
// `@z-index-global` list is shipped with PAM and is empty by default. Add
// element names to appropriate z-index in the list and use the
// .zindex mixin to retrive the z-index value for that element
// in the given context. If more z-index contexts are needed
// add another `@z-index-*` list for that context.
//
//```less
//  // Example
//  @z-index-global: 'overlay', 'dialog', 'notification';
//  zindex('notification', @z-index-global);
//  output: z-index: 3;
//```
//
// @elementName - Find position for given name.
// @elementList - Contextual z-index element list.
//
// Style guide: mixins.zindex

.zindex(@elementName, @elementList) {
    .loop(@elementName, length(@elementList));
}

.loop(@elementName, @counter) when (@counter > 0) {
    .loop(@elementName, @counter - 1);
    .pickIndex(@elementName, @counter);
}

.pickIndex(@elementName, @counter) when (extract(@elementList, @counter) = @elementName) {
    z-index: @counter;
}
