<commit_before>import { applyChildNodes } from './utilities.js';
import * as calendar from './calendar.js';
import * as internal from './internal.js';
import * as template from './template.js';
import CalendarDay from './CalendarDay.js';
import CalendarElementMixin from './CalendarElementMixin.js';
import ReactiveElement from './ReactiveElement.js';


const Base =
  CalendarElementMixin(
    ReactiveElement
  );

/**
 * A 7-column grid of days for use in a month calendar or multi-week calendar.
 * 
 * [A default representation of days in the current month in browser's default locale](/demos/calendarMonth.html)
 * 
 * Given a `startDate` and `dayCount`, this component will show a calendar
 * representation of that many days starting from the indicated date.
 * [CalendarMonth](CalendarMonth) uses `CalendarDays` to render the days portion
 * of the month, to which it adds headers for the month/year and the days of the
 * week.
 * 
 * All of the Elix calendar components attempt to provide full
 * [international calendar support](CalendarMonth#international-support)
 * to the extent currently possible in the user's web browser.
 * 
 * @inherits ReactiveElement
 * @mixes CalendarElementMixin
 * @elementrole {CalendarDay} day
 */
class CalendarDays extends Base {

  /**
   * Returns the day element corresponding to the given date, or null if the
   * date falls outside this calendar week.
   *
   * @param {Date} date - the date to search for
   */
  dayElementForDate(date) {
    /** @type {Element[]} */ const days = this.days || [];
    return days.find(day => {
      /** @type {any} */ const cast = day;
      return calendar.datesEqual(cast.date, date);
    });
  }

  get dayCount() {
    return this[internal.state].dayCount;
  }
  set dayCount(dayCount) {
    this[internal.setState]({
      dayCount
    });
  }

  /**
   * The class, tag, or template used for the seven days of the week.
   * 
   * @type {Role}
   * @default CalendarDay
   */
  get dayRole() {
    return this[internal.state].dayRole;
  }
  set dayRole(dayRole) {
    this[internal.setState]({ dayRole });
  }

  /**
   * The elements for the days being displayed.
   * 
   * @type {Element[]|null}
   */
  get days() {
    return this[internal.state].days;
  }

  get [internal.defaultState]() {
    const today = calendar.today();
    const state = Object.assign(super[internal.defaultState], {
      date: calendar.today(),
      dayCount: 1,
      dayRole: CalendarDay,
      days: null,
      showCompleteWeeks: false,
      showSelectedDay: false,
      startDate: today
    });

    // If any date-related state changes, regenerate the set of days.
    state.onChange(['dayCount', 'dayRole', 'locale', 'showCompleteWeeks', 'startDate'], (state, changed) => {
      const days = updateDays(state, changed.dayRole);
      return { days };
    });

    return state;
  }

  [internal.render](/** @type {PlainObject} */ changed) {
    super[internal.render](changed);
    if (changed.days) {
      applyChildNodes(this[internal.ids].dayContainer, this[internal.state].days);
    }
    if (changed.date || changed.showSelectedDay) {
      // Ensure only current date has "selected" class.
      const showSelectedDay = this[internal.state].showSelectedDay;
      const { date } = this[internal.state];
      const selectedDate = date.getDate();
      const selectedMonth = date.getMonth();
      const selectedYear = date.getFullYear();
      /** @type {Element[]} */ const days = this.days || [];
      days.forEach(day => {
        if ('selected' in day) {
          /** @type {any} */ const cast = day;
          const dayDate = cast.date;
          const selected = showSelectedDay &&
            dayDate.getDate() === selectedDate &&
            dayDate.getMonth() === selectedMonth &&
            dayDate.getFullYear() === selectedYear;<commit_msg>If the locale changes, that can effect the column of the selected date, so we should recalculate the selected state for each day.<commit_after>import { applyChildNodes } from './utilities.js';
import * as calendar from './calendar.js';
import * as internal from './internal.js';
import * as template from './template.js';
import CalendarDay from './CalendarDay.js';
import CalendarElementMixin from './CalendarElementMixin.js';
import ReactiveElement from './ReactiveElement.js';


const Base =
  CalendarElementMixin(
    ReactiveElement
  );

/**
 * A 7-column grid of days for use in a month calendar or multi-week calendar.
 * 
 * [A default representation of days in the current month in browser's default locale](/demos/calendarMonth.html)
 * 
 * Given a `startDate` and `dayCount`, this component will show a calendar
 * representation of that many days starting from the indicated date.
 * [CalendarMonth](CalendarMonth) uses `CalendarDays` to render the days portion
 * of the month, to which it adds headers for the month/year and the days of the
 * week.
 * 
 * All of the Elix calendar components attempt to provide full
 * [international calendar support](CalendarMonth#international-support)
 * to the extent currently possible in the user's web browser.
 * 
 * @inherits ReactiveElement
 * @mixes CalendarElementMixin
 * @elementrole {CalendarDay} day
 */
class CalendarDays extends Base {

  /**
   * Returns the day element corresponding to the given date, or null if the
   * date falls outside this calendar week.
   *
   * @param {Date} date - the date to search for
   */
  dayElementForDate(date) {
    /** @type {Element[]} */ const days = this.days || [];
    return days.find(day => {
      /** @type {any} */ const cast = day;
      return calendar.datesEqual(cast.date, date);
    });
  }

  get dayCount() {
    return this[internal.state].dayCount;
  }
  set dayCount(dayCount) {
    this[internal.setState]({
      dayCount
    });
  }

  /**
   * The class, tag, or template used for the seven days of the week.
   * 
   * @type {Role}
   * @default CalendarDay
   */
  get dayRole() {
    return this[internal.state].dayRole;
  }
  set dayRole(dayRole) {
    this[internal.setState]({ dayRole });
  }

  /**
   * The elements for the days being displayed.
   * 
   * @type {Element[]|null}
   */
  get days() {
    return this[internal.state].days;
  }

  get [internal.defaultState]() {
    const today = calendar.today();
    const state = Object.assign(super[internal.defaultState], {
      date: calendar.today(),
      dayCount: 1,
      dayRole: CalendarDay,
      days: null,
      showCompleteWeeks: false,
      showSelectedDay: false,
      startDate: today
    });

    // If any date-related state changes, regenerate the set of days.
    state.onChange(['dayCount', 'dayRole', 'locale', 'showCompleteWeeks', 'startDate'], (state, changed) => {
      const days = updateDays(state, changed.dayRole);
      return { days };
    });

    return state;
  }

  [internal.render](/** @type {PlainObject} */ changed) {
    super[internal.render](changed);
    if (changed.days) {
      applyChildNodes(this[internal.ids].dayContainer, this[internal.state].days);
    }
    if (changed.date || changed.locale || changed.showSelectedDay) {
      // Ensure only current date has "selected" class.
      const showSelectedDay = this[internal.state].showSelectedDay;
      const { date } = this[internal.state];
      const selectedDate = date.getDate();
      const selectedMonth = date.getMonth();
      const selectedYear = date.getFullYear();
      /** @type {Element[]} */ const days = this.days || [];
      days.forEach(day => {
        if ('selected' in day) {
          /** @type {any} */ const cast = day;
          const dayDate = cast.date;
          const selected = showSelectedDay &&
            dayDate.getDate() === selectedDate &&
            dayDate.getMonth() === selectedMonth &&
            dayDate.getFullYear() === selectedYear;
{'fraction_non_alphanumeric': 0.12404287901990811, 'fraction_numerical': 0.0005104645227156713, 'mean_word_length': 3.041774110366168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1027680', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2192, 'n_words': 700}