$(document).ready(function () {
  console.log("keypad.js load start");

  const dials = $(".dials div a");

	dials.click(function () {
	const digit = $(this).contents().filter(function() {
		return this.nodeType === 3;
	}).text().trim();

	switch (digit) {
		case "*":
		case "0":
		case "#":
		addDigit(digit);
		break;
		case "Clear":
		clearNumber();
		break;
		case "Delete":
		deleteDigit();
		break;
		default:
		if (/^[0-9]$/.test(digit)) {
			addDigit(digit);
		}
		break;
	}
	});


  $(document).keydown(function (e) {
    switch (e.which) {
      case 96: case 48: addDigit("0"); break;
      case 97: case 49: addDigit("1"); break;
      case 98: case 50: addDigit("2"); break;
      case 99: case 51: addDigit("3"); break;
      case 100: case 52: addDigit("4"); break;
      case 101: case 53: addDigit("5"); break;
      case 102: case 54: addDigit("6"); break;
      case 103: case 55: addDigit("7"); break;
      case 104: case 56: addDigit("8"); break;
      case 105: case 57: addDigit("9"); break;
      case 106: addDigit("*"); break;
      case 107: addDigit("#"); break;
      case 8: deleteDigit(); break;
      case 27: clearNumber(); break;
      case 13: $(".pad-action").click(); break;
      default: return;
    }
    e.preventDefault();
  });

  $(".action .del").click(function (e) {
    e.preventDefault();
    deleteDigit();
  });
});
