//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// TypeScript helpers (universal micro-lib.) | Author: Sergei Y.Kitaev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Helpers for HTML element accessed by its identifier (static class):
class HById
{
   static ElementOf<T extends HTMLElement>(id: string, tagName: string|null=null): T {
      let elem = document.getElementById(id);
      if (!elem)
         throw new Error('Element not found by id: "'+id+'".')
      let element = elem as T
      if (!element || tagName && element.tagName!=tagName)
         throw new Error('Element "'+id+'" is not of "'+HObject.TypeName(elem)+'"-type.')
      return element
   }
   static GetElementOf<T extends HTMLElement>(id: string, tagName: string|null=null): T|null {
      return HElement.GetById(id,tagName) as T
   }
   static Exists(id: string, tagName: string|null=null): boolean {
      let element = document.getElementById(id)
      return tagName ?
         element!=null && element.tagName==tagName :
         element!=null
   }

   static InputElement(id: string, tagName: string|null=null): HTMLInputElement {
      return HById.ElementOf<HTMLInputElement>(id,tagName)
   }
   static GetInputElement(id: string, tagName: string|null=null): HTMLInputElement|null {
      return HById.GetElementOf<HTMLInputElement>(id,tagName)
   }
} // HById
