#!/usr/bin/env zsh
# Description:
#   Specify the pattern of the files to source or add to `$PATH`

local    arg="$1" package
local -a parsed_zplugs
local    use
local    default="*.zsh"
local -A tags

package="${arg}, ${zplugs[$arg]%, }"
parsed_zplugs=(${(s/, /)package/,  */, })

use="${parsed_zplugs[(k)use:*]#use:*}"
if [[ -z $use ]]; then
    zstyle -s ":zplug:tag" use use
fi

tags[from]="$(
__zplug::core::core::run_interfaces \
    'from' \
    "$arg"
)"
tags[as]="$(
__zplug::core::core::run_interfaces \
    'as' \
    "$arg"
)"

if [[ $tags[from] == "gh-r" ]]; then
    default=""
    if [[ -n $use ]]; then
        use="$(__zplug::utils::shell::glob2regexp "$use")"
    else
        use="$(__zplug::base::base::get_os)"
        if __zplug::base::base::is_osx; then
            use="(darwin|osx)"
        fi
    fi
fi

if [[ $tags[as] == "theme" ]]; then
    default=""
fi

echo "${use:-$default}"
