# Init widget script: https://ovp.sohatv.vn/lib/widget-script/ovpWidget.js
# Init embed script: https://ovp.sohatv.vn/lib/embed/ovpEmbed.js
# Init player script: https://player.sohatv.vn/resource/init-script/playerInitScript.js

$(function () {
	$("#btn-ovp-video-widget").click(function () {
		var { appkey, token } = this.dataset;
		var getToken = (cb) => cb(null, token);
		ovpWidget.init({
			appkey,
			token: getToken,
			onCallback: (value) => {
				console.log('=====onInsertVideo=============', value);
				let embedCode = Array.isArray(value.data) ? ovpWidget.embedData() : value.data.embedCode;
				if (value.type === 'insertVideo' || value.type === 'insertVideoLive') $("#video-inserted-container").append(embedCode);
			}
		});
	});
})
$(function() {
	$("#ovp-upload-input").change(function() {
		const {appkey, token} = this.dataset
		const {files} = this
		const getToken = cb => cb(null, token)
		ovpWidget.uploadVideo({
			appkey,
			token: getToken,
			files,
			onCallback: (value) => {
				console.log('=====onUploadVideo=============', value);
			}
		});
		$("#ovp-upload-input").val('')
	})
})