<commit_before>'use strict';

/**
 * @file
 * Shows a list of libraries from the ddbContent service
 *
 * @usage
 * <LibraryAffiliateList />
 */

import React from 'react';

export default class LibraryAffiliateListItem extends React.Component {
  getMarkup(html) {
    return {__html: html};
  }

  getOpeningHours(opening_hours_array) {
    const oneDayInMilliSeconds = 86400000;
    let today = new Date();
    today.setHours(0);
    today.setMinutes(0);
    today.setSeconds(0);
    today.setMilliseconds(0);
    const lastDay = today.getTime() + (7 * oneDayInMilliSeconds);

    let day = today.getTime();
    let counter = 0;
    let days = {};
    while (day < lastDay && counter < opening_hours_array.length) {
      const currentDay = opening_hours_array[counter];
      counter += 1;
      day = (new Date(currentDay.date)).getTime();
      if (day >= today.getTime()) {
        if (!days.hasOwnProperty(currentDay.date)) {
          days[currentDay.date] = [];
        }
        days[currentDay.date].push(currentDay);
      }
    }

    let dayArray = [];
    for (var i = 0; i <= 6; i++) {
      const currentDay = new Date(today.getTime() + (i * oneDayInMilliSeconds));
      const dateString = currentDay.getFullYear() + '-' + (currentDay.getMonth() + 1) + '-' + currentDay.getDate();

      switch (currentDay.getDay()) {
        case 0:
          day = 'Søndag:';
          break;
        case 1:
          day = 'Mandag: ';
          break;
        case 2:
          day = 'Tirsdag: ';
          break;
        case 3:
          day = 'Onsdag: ';
          break;
        case 4:
          day = 'Torsdag: ';
          break;
        case 5:
          day = 'Fredag: ';
          break;
        case 6:
          day = 'Lørdag: ';
          break;
        default:
          day = 'ukendt ';
          break;
      }

      if (days.hasOwnProperty(dateString)) {
        let openingTimeString = '';
        openingTimeString += day;
        let dateStrings = [];
        days[dateString].forEach((date) => {
          dateStrings.push(
            date.opening_time.split(':').splice(0, 2).join(':') +
            ' til ' +
            date.closing_time.split(':').splice(0, 2).join(':')
          );
        });

        openingTimeString += dateStrings.join(', ');
        dayArray.push(
          <p key={day}>{openingTimeString}</p>
        );
      }
      else {
        dayArray.push(<p key={day}>{day} lukket</p>);
      }
    }

    return dayArray;
  }

  render() {
    console.log(this.props);
    const openingHoursArray = this.getOpeningHours(this.props.opening_hours);

    /* eslint-disable react/no-danger */
    const library_lead_description = (<div className='libraries--library-list-item--library-lead-description' dangerouslySetInnerHTML={this.getMarkup(this.props.lead_description)}></div>);
    const library_description = (<div className='libraries--library-list-item--library-description' dangerouslySetInnerHTML={this.getMarkup(this.props.description)}></div>);
    /* eslint-enable react/no-danger */

    return (
      <div className='libraries--library-list-item'>
        <div className='libraries--library-list-item--library-title-image'>
          <img src={this.props.title_images[0] || ''} />
        </div>

        <div className='libraries--library-list-item--library-title'>
          <h2>{this.props.title}</h2>
        </div>

        {library_lead_description}
        <br />

        {library_description}
<commit_msg>sd-157: remove console statement<commit_after>'use strict';

/**
 * @file
 * Shows a list of libraries from the ddbContent service
 *
 * @usage
 * <LibraryAffiliateList />
 */

import React from 'react';

export default class LibraryAffiliateListItem extends React.Component {
  getMarkup(html) {
    return {__html: html};
  }

  getOpeningHours(opening_hours_array) {
    const oneDayInMilliSeconds = 86400000;
    let today = new Date();
    today.setHours(0);
    today.setMinutes(0);
    today.setSeconds(0);
    today.setMilliseconds(0);
    const lastDay = today.getTime() + (7 * oneDayInMilliSeconds);

    let day = today.getTime();
    let counter = 0;
    let days = {};
    while (day < lastDay && counter < opening_hours_array.length) {
      const currentDay = opening_hours_array[counter];
      counter += 1;
      day = (new Date(currentDay.date)).getTime();
      if (day >= today.getTime()) {
        if (!days.hasOwnProperty(currentDay.date)) {
          days[currentDay.date] = [];
        }
        days[currentDay.date].push(currentDay);
      }
    }

    let dayArray = [];
    for (var i = 0; i <= 6; i++) {
      const currentDay = new Date(today.getTime() + (i * oneDayInMilliSeconds));
      const dateString = currentDay.getFullYear() + '-' + (currentDay.getMonth() + 1) + '-' + currentDay.getDate();

      switch (currentDay.getDay()) {
        case 0:
          day = 'Søndag:';
          break;
        case 1:
          day = 'Mandag: ';
          break;
        case 2:
          day = 'Tirsdag: ';
          break;
        case 3:
          day = 'Onsdag: ';
          break;
        case 4:
          day = 'Torsdag: ';
          break;
        case 5:
          day = 'Fredag: ';
          break;
        case 6:
          day = 'Lørdag: ';
          break;
        default:
          day = 'ukendt ';
          break;
      }

      if (days.hasOwnProperty(dateString)) {
        let openingTimeString = '';
        openingTimeString += day;
        let dateStrings = [];
        days[dateString].forEach((date) => {
          dateStrings.push(
            date.opening_time.split(':').splice(0, 2).join(':') +
            ' til ' +
            date.closing_time.split(':').splice(0, 2).join(':')
          );
        });

        openingTimeString += dateStrings.join(', ');
        dayArray.push(
          <p key={day}>{openingTimeString}</p>
        );
      }
      else {
        dayArray.push(<p key={day}>{day} lukket</p>);
      }
    }

    return dayArray;
  }

  render() {
    const openingHoursArray = this.getOpeningHours(this.props.opening_hours);

    /* eslint-disable react/no-danger */
    const library_lead_description = (<div className='libraries--library-list-item--library-lead-description' dangerouslySetInnerHTML={this.getMarkup(this.props.lead_description)}></div>);
    const library_description = (<div className='libraries--library-list-item--library-description' dangerouslySetInnerHTML={this.getMarkup(this.props.description)}></div>);
    /* eslint-enable react/no-danger */

    return (
      <div className='libraries--library-list-item'>
        <div className='libraries--library-list-item--library-title-image'>
          <img src={this.props.title_images[0] || ''} />
        </div>

        <div className='libraries--library-list-item--library-title'>
          <h2>{this.props.title}</h2>
        </div>

        {library_lead_description}
        <br />

        {library_description}

{'fraction_non_alphanumeric': 0.1483453237410072, 'fraction_numerical': 0.009640287769784173, 'mean_word_length': 2.188532110091743, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2373954', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2154, 'n_words': 392}