import { Item } from "../../items/types/Item" ; import { layout } from "../layout" ; import { PlugyStash } from "../../plugy-stash/types" ; import { makeIndex } from "../../plugy-stash/makeIndex" ; import { sortAndGroupBy } from "./sortAndGroupBy" ; import { addPage } from "../../plugy-stash/addPage" ; import { moveItem } from "../../items/moving/safeMove" ; export const UBERS = [ "pk1" , "pk2" , "pk3" , "dhn" , "bey" , "mbr" , "std" ] ; export function organizeUbers ( stash , items ) { if ( items . length === 0 ) return ; const groups = sortAndGroupBy ( items , ( item ) => UBERS . indexOf ( item . code ) ) ; const offset = stash . pages . length ; const { nbPages , positions } = layout ( "lines" , groups ) ; for ( let i = 0 ; i < nbPages ; i ++ ) { const page = addPage ( stash , "Ubers" ) ; if ( i === 0 ) { makeIndex ( page , false ) ; } } for ( const [ item , { page , rows , cols } ] of positions . entries ( ) ) { moveItem ( stash , item , offset + page , rows [ 0 ] , cols [ 0 ] ) ; } }