const sheetTwo = SpreadsheetApp.getActiveSheet();
var now = new Date();
var formatToday = Utilities.formatDate(now, 'America/New_York', 'MM/dd/yyyy');

function newMeetings() {
  var startRow = 2;  // First row of data to process
  var numRows = sheetTwo.getLastRow()-1;   // Number of rows to process
  var dataRange = sheetTwo.getRange(startRow, 1, numRows, sheet.getLastColumn());
  var data = dataRange.getValues();
  var sdrMeeting = [];

  for (i in data) {
    var row = data[i];
    var sdr = row[0];       // Column A
    var date = Utilities.formatDate(row[3],'America/New_York','MM/dd/yyyy');  // Column D
    var company = row[4];   // Column E
    var outbound = row[5]; // Column F
    let sdrMeetingListOne = [sdr, date, company, outbound];
    if ((sdrMeetingListOne[1] == formatToday) && (sdrMeetingListOne[0] != '') && (sdrMeetingListOne[3] == "Outbound")) {
      sdrMeetingListOne.toString();
      sdrMeeting.push(sdrMeetingListOne);
      Logger.log(sdrMeetingListOne)
    } else if ((sdrMeetingListOne[1] == formatToday) && (sdrMeetingListOne[0] != '')) {
        let noMeetingText =
      {
        "blocks": [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": ":star: *C'mon team!* :star:"
            }
          },
          {
            "type": "divider"
          },
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "No new meetings today? We can do better than that! Hustle!"
            }
          },
        ]
      }
        const webhook = "https://hooks.slack.com/services/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";
        const options = {
        method: "post", 
        contentType: "application/json",
        muteHttpExceptions: true,
        payload: JSON.stringify(noMeetingText),
    }
      const sendMsg = UrlFetchApp.fetch(webhook, options);
      var respCode = sendMsg.getResponseCode();
      Logger.log(sendMsg);
      Logger.log(respCode);
    }
  };
  Logger.log(sdrMeeting);
  var toSend = sdrMeeting.splice(1).join('\n');
  var getEm = toSend.replace(/,/g, ' - ')
  Logger.log(getEm)
/*
  let payloadMeetingText =
{
	"blocks": [
		{
			"type": "section",
			"text": {
				"type": "mrkdwn",
				"text": ":star: *Pitter Patter!* :star:"
			}
		},
		{
			"type": "divider"
		},
		{
			"type": "section",
			"text": {
				"type": "mrkdwn",
				"text": "Here's who has meetings today. Get after it boys and girls!"
			}
		},
		{
			"type": "section",
			"text": {
				"type": "mrkdwn",
				"text": getEm
			}
		},
		{
			"type": "image",
			"image_url": "https://media.giphy.com/media/3ohjURBuAtWDV8d3SE/giphy.gif",
			"alt_text": "inspiration"
		}
	]
}
    //(array[0] + ", you still need to fill out the cells for" + array[2] + " from " + array[1] + "!\n");
  const webhook = "https://hooks.slack.com/services/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";
  const options = {
    method: "post", 
    contentType: "application/json",
    muteHttpExceptions: true,
    payload: JSON.stringify(payloadText),
  };
  const sendMsg = UrlFetchApp.fetch(webhook, options);
  var respCode = sendMsg.getResponseCode();
  Logger.log(sendMsg);
  Logger.log(respCode);*/
};