
$( document ).ready(function() {
  $('.chat-content figure[data-trix-content-type^="video/"]').each(function(i, obj) {
    if(!$(this).find('video').length && !$(this).find('progress').length) {
      var tipo = $(this).data('trix-content-type');
      var linkelement = $(this).find('a');
      var link = linkelement.attr('href');
      $(this).prepend('<video controls width="500"> <source src="' + link + '" type="' + tipo + '"></video>');
      $('#content').val($('.trix-content').html());
    }
  });

  $('.chat-content a[href^="http"]').each(function(i, obj) {
    $('a[href^="http"]').attr('target','_blank');
  });
});

addEventListener("trix-file-accept", function(event) {
  const acceptedTypes = [
    'audio/aac',
    'application/x-abiword',
    'application/vnd.amazon.ebook',
    'application/octet-stream',
    'application/x-bzip',
    'application/x-bzip2',
    'application/x-rar-compressed',
    'application/x-7z-compressed',
    'application/msword',
    'application/vnd.ms-fontobject',
    'application/rtf',
    'application/x-tar',
    'image/x-icon',
    'text/calendar',
    'image/jpeg',
    'image/png',
    'image/gif',
    'image/tiff',
    'image/webp',
    'video/mp4',
    'video/mov',
    'video/webm',
    'video/mpeg',
    'video/ogg',
    'video/x-msvideo',
    'application/zip',
    'application/pdf',
    'application/vnd.ms-powerpoint',
    'text/csv',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    'application/vnd.ms-excel',
    'application/vnd.oasis.opendocument.presentation',
    'application/vnd.oasis.opendocument.spreadsheet',
    'application/vnd.oasis.opendocument.text',
    'audio/ogg',
    'audio/x-wav',
    'audio/webm'
  ]

  if (!acceptedTypes.includes(event.file.type)) {
    event.preventDefault();
    alert("Ficheiro não suportado");
  }
});
