/*************************************
   ____        _      _
  / __ \      (_)    | |
 | |  | |_   _ _  ___| | _____ _   _
 | |  | | | | | |/ __| |/ / _ \ | | |
 | |__| | |_| | | (__|   <  __/ |_| |
  \___\_\\__,_|_|\___|_|\_\___|\__, |
                                __/ |
                               |___/
**************************************/ import Quickey , { IQuickeyOptions , IAction , IActionOptions , ActionCallback , OnDestroyCallback } from "./Quickey" ; const quickeys = [ ] ; function enhanceOptions ( o = { } ) { const destroyCallback = o . onDestroy ; o . onDestroy = ( quickey ) => { destroyCallback && destroyCallback ( quickey ) ; const quickeyLocation = quickeys . indexOf ( quickey ) ; if ( quickeyLocation > - 1 ) { quickeys . splice ( quickeyLocation , 1 ) ; } } ; return o ; } function create ( options ) { return new Quickey ( enhanceOptions ( options ) ) ; } function queryByQuickeyId ( ids , quickey ) { return ( ids instanceof Array ) ? ! ! ~ ids . indexOf ( quickey . id ) : quickey . id === ids ; } function createQuickey ( options ? ) ; function createQuickey ( options ? ) ; function createQuickey ( options ? ) { if ( ! ( options instanceof Array ) ) { const q = create ( options ) ; quickeys . push ( q ) ; return q ; } const qs = options . map ( create ) ; Array . prototype . push . apply ( quickeys , qs ) ; return qs ; } function getQuickeyInstance ( ids ) ; function getQuickeyInstance ( ids ) ; function getQuickeyInstance ( ids ) { const query = queryByQuickeyId . bind ( null , ids ) ; if ( ids instanceof Array ) { return quickeys . filter ( query ) ; } return quickeys . find ( query ) ; } export { IQuickeyOptions , IActionOptions , IAction , ActionCallback , OnDestroyCallback , Quickey , createQuickey , getQuickeyInstance } ;