#!tag "bs.load:process/errors/" + module[3:]

{% include 'bookshelf/header.jinja' %}
# Return early to ensure code runs only on the latest available version
execute unless score ${{ module }}.major load.status matches {{ version.major }} run return 0
execute unless score ${{ module }}.minor load.status matches {{ version.minor }} run return 0
execute unless score ${{ module }}.patch load.status matches {{ version.patch }} run return 0

# Format an error message for conflicting versions
data modify storage bs:data load.errors append value {major:1b,message:{text:"[{{ module }}]",hover_event:{action:"show_text",value:[{text:"[v",color:"#CCCCCC"},{type:"nbt",storage:"bs:data",nbt:"load.modules[{module:'{{ module }}',enabled:1b}].version"},{text:" ("},{text:"✔ enabled",color:"#26BD26"},{text:"), v"},{type:"nbt",storage:"bs:data",nbt:"load.modules[{module:'{{ module }}',enabled:0b}].version","separator":", v"},{text:"]"}]}}}

# Return early if major version conflicts exist
execute if score #{{ module }}.major_versions load.status matches 2.. run return 0

# Mark the error as non major and create a downloadable bundle to resolve the issue
data modify storage bs:data load.errors[-1].major set value 0b
function bs.load:v{{ version.major }}.{{ version.minor }}.{{ version.patch }}/bundle/append {module:"{{ module }}"}
