// 名前空間
var CHAT_UTIL = {};

CHAT_UTIL.isAndroid = function() {
	return PLATFORM == 'android';
};

CHAT_UTIL.isIOS = function() {
	return PLATFORM == 'ios';
};

CHAT_UTIL.isMobile = function() {
	return IS_MOBILE == 'true';
};

CHAT_UTIL.formatDate = function(date) {
	const REFERENCE = moment();
	const TODAY = REFERENCE.clone().startOf('day');
	let createdAt = moment(date);
	if (date.length == 14) {
	  createdAt = moment(date,'YYYYMMDDhhmmss');
	} else {
	  createdAt = moment(date);
	}

	// #36171
	const createdAtDay = createdAt.format('MMM Do');
	const createdAtTime = createdAt.format('HH:mm');
	if (createdAt.isSame(TODAY, 'd')) {
		createdAt = createdAtTime;
	} else {
		createdAt = createdAtDay;
	}
	let rntDate = new Object();
	rntDate.createdAtDay = createdAtDay;
	rntDate.createdAtTime = createdAtTime;
	rntDate.createdAt = createdAt;
	return rntDate;
}

CHAT_UTIL.htmlDecode = function(input) {
	var e = document.createElement('textarea');
	e.innerHTML = input;
	// handle case of empty input
	return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}

//generates a unique id, not obligator a UUID
CHAT_UTIL.generateUUID = function() {
	var d = new Date().getTime();
	var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		var r = (d + Math.random()*16)%16 | 0;
		d = Math.floor(d/16);
		return (c=='x' ? r : (r&0x3|0x8)).toString(16);
	});
	return uuid;
};
