import escapeHtml from 'escape-html';
import { getLyricsApi } from '@jellyfin/sdk/lib/utils/api/lyrics-api';
import { toApi } from 'utils/jellyfin-apiclient/compat';
import dialogHelper from '../dialogHelper/dialogHelper';
import layoutManager from '../layoutManager';
import globalize from 'lib/globalize';
import { ServerConnections } from 'lib/jellyfin-apiclient';
import loading from '../loading/loading';
import focusManager from '../focusManager';
import dom from '../../scripts/dom';
import '../../elements/emby-select/emby-select';
import '../listview/listview.scss';
import '../../elements/emby-button/paper-icon-button-light';
import '../formdialog.scss';
import 'material-design-icons-iconfont';
import './lyricseditor.scss';
import '../../elements/emby-button/emby-button';
import '../../styles/flexstyles.scss';
import toast from '../toast/toast';
import template from './lyricseditor.template.html';
import templatePreview from './lyricspreview.template.html';
import { deleteLyrics } from '../../scripts/deleteHelper';
let currentItem;
let hasChanges;
function downloadRemoteLyrics(context, id) {
const api = toApi(ServerConnections.getApiClient(currentItem.ServerId));
const lyricsApi = getLyricsApi(api);
lyricsApi.downloadRemoteLyrics({
itemId: currentItem.Id,
lyricId: id
}).then(function () {
hasChanges = true;
toast(globalize.translate('MessageDownloadQueued'));
focusManager.autoFocus(context);
});
}
function getLyricsText(lyricsObject) {
return lyricsObject.reduce((htmlAccumulator, lyric) => {
if (lyric.Start || lyric.Start === 0) {
const minutes = Math.floor(lyric.Start / 600000000);
const seconds = Math.floor((lyric.Start % 600000000) / 10000000);
const hundredths = Math.floor((lyric.Start % 10000000) / 100000);
htmlAccumulator += '[' + String(minutes).padStart(2, '0') + ':' + String(seconds).padStart(2, '0') + '.' + String(hundredths).padStart(2, '0') + '] ';
}
htmlAccumulator += escapeHtml(lyric.Text) + '
';
return htmlAccumulator;
}, '');
}
function renderSearchResults(context, results) {
let lastProvider = '';
let html = '';
if (!results.length) {
context.querySelector('.noSearchResults').classList.remove('hide');
context.querySelector('.lyricsResults').innerHTML = '';
loading.hide();
return;
}
context.querySelector('.noSearchResults').classList.add('hide');
for (let i = 0, length = results.length; i < length; i++) {
const result = results[i];
const provider = result.ProviderName;
const metadata = result.Lyrics.Metadata;
const lyrics = getLyricsText(result.Lyrics.Lyrics);
if (provider !== lastProvider) {
if (i > 0) {
html += '';
}
html += '