include ../announcement/components/announcement
include ../newsroom/components/feed-entry-list-item

include ../venue/components/channel-card
include ../venue/components/channel-list-item

- var isLive = !!shingChannelStatus && shingChannelStatus.isLive && !!shingChannelStatus.liveEpisode;

mixin renderSidebarEpisode(episode)
  .uk-card.uk-card-default.uk-card-small.uk-card-hover

    .uk-card-media-top
      a(href= episode.url, target="_blank", title="Watch on Gab TV")
        img(src=episode.image).responsive

    a(
      href= episode.url,
      uk-tooltip=`Watch ${episode.title} on Gab TV`,
      target="_blank",
    ).uk-link-reset.uk-display-block
      .uk-card-body
        .uk-text-bold.uk-text-truncate= episode.title
        .uk-text-small= moment(episode.date_modified).format("MMM DD YYYY HH:MM a")

mixin renderPageSidebar ( )
  //-
  //- Announcements
  //-
  if Array.isArray(announcements) && (announcements.length > 0)
    ul.uk-list.uk-margin-medium
      each announcement in announcements
        li
          +renderAnnouncement(announcement)

  //-
  //- Shing.tv Channel Integration
  //-

  -
    var onlineChannels = venue.channels.filter((channel) => channel.currentStatus && (channel.currentStatus.status === 'live'));
    var offlineChannels = venue.channels.filter((channel) => !channel.currentStatus || (channel.currentStatus.status !== 'live'));

  if Array.isArray(onlineChannels) && (onlineChannels.length > 0)
    each channel of onlineChannels
      .uk-margin-medium
        +renderSectionTitle('Live Now!', {
          label: 'Tune In',
          title: channel.name,
          url: '/venue',
        })
        +renderVenueChannelCard(channel)

  if Array.isArray(offlineChannels) && (offlineChannels.length > 0)
    .uk-margin-medium
      +renderSectionTitle('Offline Channels')
      ul.uk-list.uk-list-divider
        each venueChannel of offlineChannels
          li
            +renderVenueChannelListItem(venueChannel)

  //-
  //- Shing.tv Channel Feed
  //-
  if shingChannelFeed && Array.isArray(shingChannelFeed.items) && (shingChannelFeed.items.length > 0)
    .uk-margin-medium
      +renderSectionTitle(shingChannelFeed.title, {
        label: 'Tune In',
        title: shingChannelFeed.title,
        url: '/venue',
      })
      ul.uk-list
        each item in shingChannelFeed.items.slice(0, 3)
          li
            a(href= item.url, uk-tooltip=`Watch ${item.title} on Shing.tv`).uk-link-reset.uk-display-block
              .uk-card.uk-card-default.uk-card-small
                img(src= item.image.url, width="640", height="360", alt=`Thumbnail image for ${item.title}`).responsive
                .uk-card-body
                  div(uk-grid).uk-grid-small
                    .uk-width-auto
                      img(src=`https://${dtp.services.venue.soapboxDomain}/channel/${site.shingChannelSlug}/app-icon?s=48`)
                    .uk-width-expand
                      .uk-text-bold.uk-text-truncate= item.title
                      .uk-text-small= moment(item.date_modified).format("MMM DD YYYY hh:mm a")
                      //- .uk-text-small!= item.summary

  //-
  //- Gab TV channel integration
  //-
  if gabTvChannel
    .uk-margin-medium
      +renderSectionTitle('Gab TV', {
        label: 'Visit Channel',
        title: gabTvChannel.title,
        url: gabTvChannel.home_page_url,
      })
      ul.uk-list
        each episode in gabTvChannel.items.slice(0, 3)
          li
            +renderSidebarEpisode(episode)

  //-
  //- Newsroom Integration
  //-
  if newsfeed
    .uk-margin-medium
      +renderSectionTitle('Newsfeed', {
        label: 'See All',
        title: 'Browse all news feeds',
        url: '/newsroom',
      })
      .sidebar-widget
        if Array.isArray(newsfeed.entries) && (newsfeed.entries.length > 0)
          ul.uk-list
            each entry in newsfeed.entries
              li
                +renderNewsroomFeedEntryListItem(entry)

  //-
  //- Newsletter Signup
  //-
  div(uk-sticky={ offset: 60, bottom: '#dtp-content-grid' }, style="z-index: initial;").uk-margin-medium
    +renderSectionTitle('Mailing List')
    form(method="post", action="/newsletter", onsubmit="return dtp.app.submitForm(event, 'Subscribe to newsletter');").uk-form
      .uk-card.uk-card-default.uk-card-small
        .uk-card-body
          p Join the #{site.name} FREE newsletter to get news and updates in your inbox.
          .uk-margin
            label(for="email").uk-form-label.sr-only Email Address
            input(id="email", name="email", type="email", placeholder="johnsmith@example.com").uk-input

        .uk-card-footer.uk-flex.uk-flex-center
          button(type="submit").uk-button.uk-button-primary.uk-button-small.uk-border-rounded Sign Up
