url := "http://localhost:3000"

view:
    loupe dithered.png&

dither size="500" *args:
    #!/usr/bin/env bash
    
    yazi --chooser-file=/tmp/chosen ~/Pictures/Wallpapers/grid/assets
    path=$(cat /tmp/chosen)
    rm test.png 
    ln -s "$path" test.png
    output="dithered.png"
    # method="cluster8"
    method="bayer8x8"
    palette=$(cargo run -r --features rerun --bin dither -- -i "$path" -o "$output" -m "$method" -s {{size}} {{args}} 2> /dev/null)
    echo -e "$palette"
    
    read -rp "Save as (empty to discard): " name
    if [[ -n "$name" ]]; then
        mkdir -p saved
        /usr/bin/vendor_perl/exiftool -overwrite_original -Comment="original: $path" -ImageDescription="original: $path" "$output" -o "saved/${name}.png"
        echo "$palette" > "saved/${name}.palette"
    fi

[no-cd]
palette file:
    #!/usr/bin/env bash
    magick {{file}} -unique-colors txt:- | grep -oP '#[0-9A-Fa-f]{6}' | while read hex; do
        r=$((16#${hex:1:2}))
        g=$((16#${hex:3:2}))
        b=$((16#${hex:5:2}))
        echo -e "\e[48;2;${r};${g};${b}m  \e[0m #${hex:1}"
    done

view-server:
    loupe out.webp&

upload:
    #!/usr/bin/env bash

    yazi --chooser-file=/tmp/chosen ~/Pictures/Wallpapers/grid/assets
    path=$(cat /tmp/chosen)
    
    curl -F "file=@${path}" {{url}}/images | jq -r '.uuid' | wl-copy

get image width style:
    curl "{{url}}/images/{{image}}?width={{width}}&style={{style}}" -o out.webp
