define(['dom', 'dialogHelper', 'loading', 'connectionManager', 'globalize', 'actionsheet', 'emby-input', 'paper-icon-button-light', 'emby-button', 'listViewStyle', 'material-icons', 'formDialogStyle'], function (dom, dialogHelper, loading, connectionManager, globalize, actionsheet) { 'use strict'; return function (options) { function mapChannel(button, channelId, providerChannelId) { loading.show(); var providerId = options.providerId; connectionManager.getApiClient(options.serverId).ajax({ type: 'POST', url: ApiClient.getUrl('LiveTv/ChannelMappings'), data: { providerId: providerId, tunerChannelId: channelId, providerChannelId: providerChannelId }, dataType: 'json' }).then(function (mapping) { var listItem = dom.parentWithClass(button, 'listItem'); button.setAttribute('data-providerid', mapping.ProviderChannelId); listItem.querySelector('.secondary').innerHTML = getMappingSecondaryName(mapping, currentMappingOptions.ProviderName); loading.hide(); }); } function onChannelsElementClick(e) { var btnMap = dom.parentWithClass(e.target, 'btnMap'); if (btnMap) { var channelId = btnMap.getAttribute('data-id'); var providerChannelId = btnMap.getAttribute('data-providerid'); var menuItems = currentMappingOptions.ProviderChannels.map(function (m) { return { name: m.Name, id: m.Id, selected: m.Id.toLowerCase() === providerChannelId.toLowerCase() }; }).sort(function (a, b) { return a.name.localeCompare(b.name); }); actionsheet.show({ positionTo: btnMap, items: menuItems }).then(function (newChannelId) { mapChannel(btnMap, channelId, newChannelId); }); } } function getChannelMappingOptions(serverId, providerId) { var apiClient = connectionManager.getApiClient(serverId); return apiClient.getJSON(apiClient.getUrl('LiveTv/ChannelMappingOptions', { providerId: providerId })); } function getMappingSecondaryName(mapping, providerName) { return (mapping.ProviderChannelName || '') + ' - ' + providerName; } function getTunerChannelHtml(channel, providerName) { var html = ''; html += '