// 名前空間
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;
};

CHAT_UTIL.systemDay = function(date) {
    let createdAt = moment(date);
    createdAt = moment(date,'YYYYMMDDhhmmss');
    const createdAtDow = createdAt.format('YYYY-MM-DD');

    let systemDay = new Object();
    systemDay.year = createdAt.format('YYYY');
    systemDay.month = createdAt.format('MM');
    systemDay.day = createdAt.format('DD');
    systemDay.dow = moment(createdAtDow).day();

    return systemDay;
}

CHAT_UTIL.findDow = function(data) {
    let dow = "";
    if (data == 0) {
        dow = getLocalizedString('sunday');
    } else if (data == 1) {
        dow = getLocalizedString('monday');
    } else if (data == 2) {
        dow = getLocalizedString('thusday');
    } else if (data == 3) {
        dow = getLocalizedString('wednesday');
    } else if (data == 4) {
        dow = getLocalizedString('thursday');
    } else if (data == 5) {
        dow = getLocalizedString('friday');
    } else if (data == 6) {
        dow = getLocalizedString('sunday');
    }
    return dow;
}
