function handleSelectedItem(event) {
    const itemLi = event.target
    
    //add or remove class automatically
    itemLi.classList.toggle("selected") 

    // console.log(event.target.dataset.id)
    const itemID = itemLi.dataset.id


    // Verify selected items. If true, get items

    const alreadySelected = selectedItems.findIndex( item => {
        const itemFound = item == itemID //true or false
        return itemFound
        }
    )

    // if selected, remove selection

    if( alreadySelected >= 0){
        const filteredItems = selectedItems.filter( item => {
            const itemIsDifferent = item != itemID 
            return itemIsDifferent 
        } )
        selectedItems = filteredItems
    } else {
        selectedItems.push(itemID)
    }

    collectedItems.value = selectedItems
}
// function to select items to collect on create page
function to select items to collect on create page
function to select items to collect on create page
function handleSelectedItem(event) {
    const itemLi = event.target
    itemLi.classList.toggle("selected") 
    const itemID = itemLi.dataset.id
    const alreadySelected = selectedItems.findIndex( item => {
        const itemFound = item == itemID 
        return itemFound
        }
    )
    if( alreadySelected >= 0){
        const filteredItems = selectedItems.filter( item => {
            const itemIsDifferent = item != itemID 
            return itemIsDifferent 
        } )
        selectedItems = filteredItems
    } else {
        selectedItems.push(itemID)
    }
    collectedItems.value = selectedItems
}
function handleSelectedItem ( event ) { const itemLi = event . target itemLi . classList . toggle ( "selected" ) const itemID = itemLi . dataset . id const alreadySelected = selectedItems . findIndex ( item => { const itemFound = item == itemID return itemFound } ) if ( alreadySelected >= 0 ) { const filteredItems = selectedItems . filter ( item => { const itemIsDifferent = item != itemID return itemIsDifferent } ) selectedItems = filteredItems } else { selectedItems . push ( itemID ) } collectedItems . value = selectedItems }
function to select items to collect on create page
function to select items to collect on create page
//add or remove class automatically // console.log(event.target.dataset.id) // Verify selected items. If true, get items //true or false // if selected, remove selection