#!/bin/bash

LIB_DIR="$( dirname "$( realpath "$0" )" )/../lib"
if [[ -f "$LIB_DIR/eeadmtools/helpers" ]]; then
    # shellcheck source=/dev/null
    source "$LIB_DIR/eeadmtools/helpers"
else
    # shellcheck source=/dev/null
    source "$LIB_DIR/helpers"
fi

function usage() {
    default_usage \
      "[eeid or pattern]" \
      "  eeid or pattern\tEEID or search pattern (optional)"

}
handle_args "$@"

URL="$EEADMIN_URL"
EEID=""
PATTERNS=()
for STR in "$@"; do
    if is_eeid "$STR"; then
        EEID="$STR"
    else
        PATTERNS+=( "$STR" )
    fi
done

if [[ -n "$EEID" ]] || [[ "${#PATTERNS}" -gt 0 ]]; then
    URL="${URL}/contracts?share"
    [[ -n "$EEID" ]] && URL="${URL}&id_customer=$EEID"
    [[ -n "${PATTERNS[*]}" ]] && URL="${URL}&pattern=$(urlencode "${PATTERNS[*]}")"
fi

open_url "$URL"

# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
