/**
 * 
 * @source http://tilde.club/~chmod777/ts/base.ts
 * 
 * @license AGPL-3.0-only
 * @licstart
 * Copyright (c) 2021 chmod777
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 * @licend
 */

let pong;
window.onload = function() {
    pong = new Pong(document);
}

function error(id: string, elementName: string): string {
    return `Failed to find ${elementName} element with id "${id}"`;
}
function getHTMLInput(id: string): HTMLInputElement {
    const element = document.getElementById(id);
    if (element instanceof HTMLInputElement)
        return element;
    throw error(id, 'html button');
}
function getHTMLSpan(id: string): HTMLSpanElement {
    const element = document.getElementById(id);
    if (element instanceof HTMLSpanElement)
        return element;
    throw error(id, 'html span');
}

function getSVGRectElement(svgDocument: Document, id: string): SVGRectElement {
    const element = svgDocument.getElementById(id);
    if (element instanceof SVGRectElement)
        return element;
    throw error(id, 'svg rect');
}
function getSVGTextElement(svgDocument: Document, id: string): SVGTextElement {
    const element = svgDocument.getElementById(id);
    if (element instanceof SVGTextElement)
        return element;
    throw error(id, 'svg text');
}
function getSVGCircleElement(svgDocument: Document, id: string): SVGCircleElement {
    const element = svgDocument.getElementById(id);
    if (element instanceof SVGCircleElement)
        return element;
    throw error(id, 'svg circle');
}
function getSVGAnimateMotionElement(svgDocument: Document, id: string): SVGAnimateMotionElement {
    const element = svgDocument.getElementById(id);
    if (element instanceof SVGAnimateMotionElement)
        return element;
    throw error(id, 'svg animate motion');
}
function getSVGPathElement(svgDocument: Document, id: string): SVGPathElement {
    const element = svgDocument.getElementById(id);
    if (element instanceof SVGPathElement)
        return element;
    throw error(id, 'svg path');
}