<commit_before><template>
  <uw-card
    v-if="show"
    :loaded="isReadyTextbook(term) && isReadySchedule(term)"
    :errored="isErroredTextbook(term) || isErroredSchedule(term)"
  >
    <template #card-heading>
      <h3>Textbooks</h3>
    </template>
    <template #card-body>
      <ul>
        <li v-for="(section, i) in bookData.sections" :key="i">
          <font-awesome-icon
            :icon="['fas', 'square-full']"
            :class="`text-c${section.colorId}`"
            class="mr-1"
          />
          <span>
            {{section.courseId}}:
          </span>
          <span v-if="section.noCourseBooks">
            No books
          </span>
          <span v-else>
            {{section.totalBooks}} {{section.totalBooks > 1 ? 'books' : 'book'}}
            <span>
              ({{section.requiredBooks ? section.requiredBooks : 'not'}} required)
            </span>
          </span>
        </li>
      </ul>
      <div v-if="!bookData.noBookAssigned">
        <a :href="`/textbooks/${bookData.year},${bookData.quarter}${bookData.summerTerm ? ',' + bookData.summerTerm : ''}`">
          <font-awesome-icon
            :icon="['fa', 'chevron-right']"
            class="mr-1"
          />
        </a>
      </div>
    </template>
  </uw-card>
</template>

<script>
import {mapGetters, mapState, mapActions} from 'vuex';
import Card from '../../containers/card.vue';

export default {
  components: {
    'uw-card': Card,
  },
  props: {
    term: {
      type: String,
      required: true,
    }
  },
  computed: {
    ...mapState({
      student: (state) => state.user.affiliations.student,
      isBeforeEndOfFirstWeek: (state) => 
        state.cardDisplayDates.is_before_eof_7days_of_term,
    }),
    ...mapState('schedule', {
      courseData: function (state) { return state.value[this.term]; },
    }),
    ...mapGetters('visual_schedule', {
      isReadySchedule: 'isReadyTagged',
      isErroredSchedule: 'isErroredTagged',
    }),
    ...mapGetters('textbooks', {
      isReadyTextbook: 'isReadyTagged',
      isErroredTextbook: 'isErroredTagged',
      getProcessedData: 'getProcessedData',
    }),
    show() {
      return (
        this.student &&
        (this.term !== 'current' || this.isBeforeEndOfFirstWeek)
      );
    },
    bookData() {
      if (this.isReadyTextbook(this.term) && this.isReadySchedule(this.term)) {
        let data = this.getProcessedData(this.courseData);
        let noBookAssigned = true;
        let sectionBookData = [];

        data.enrolledSections.forEach((section) => {
          let required = 0;
          let optional = 0;
          if (section.books) {
            section.books.forEach((book) => {
              if (book.is_required) {
                required += 1;
              } else {
                optional += 1;
              }
              if (noBookAssigned) {
                noBookAssigned = false;
              }
            });
          }
          let courseId = `${section.curriculum} ${section.courseNumber} ${section.sectionId}`;

          let sectionData = {
            courseId: courseId,
            colorId: section.colorId,
            requiredBooks: required,
            totalBooks: required + optional,<commit_msg>Fixed when error not shown on textbook when 404<commit_after><template>
  <uw-card
    v-if="show"
    :loaded="isReadyTextbook(term) && isReadySchedule(term)"
    :errored="isErroredTextbook(term) || isErroredSchedule(term)"
    :errored-show="showError"
  >
    <template #card-heading>
      <h3>Textbooks</h3>
    </template>
    <template #card-body>
      <ul>
        <li v-for="(section, i) in bookData.sections" :key="i">
          <font-awesome-icon
            :icon="['fas', 'square-full']"
            :class="`text-c${section.colorId}`"
            class="mr-1"
          />
          <span>
            {{section.courseId}}:
          </span>
          <span v-if="section.noCourseBooks">
            No books
          </span>
          <span v-else>
            {{section.totalBooks}} {{section.totalBooks > 1 ? 'books' : 'book'}}
            <span>
              ({{section.requiredBooks ? section.requiredBooks : 'not'}} required)
            </span>
          </span>
        </li>
      </ul>
      <div v-if="!bookData.noBookAssigned">
        <a :href="`/textbooks/${bookData.year},${bookData.quarter}${bookData.summerTerm ? ',' + bookData.summerTerm : ''}`">
          <font-awesome-icon
            :icon="['fa', 'chevron-right']"
            class="mr-1"
          />
        </a>
      </div>
    </template>
  </uw-card>
</template>

<script>
import {mapGetters, mapState, mapActions} from 'vuex';
import Card from '../../containers/card.vue';

export default {
  components: {
    'uw-card': Card,
  },
  props: {
    term: {
      type: String,
      required: true,
    }
  },
  computed: {
    ...mapState({
      student: (state) => state.user.affiliations.student,
      isBeforeEndOfFirstWeek: (state) => 
        state.cardDisplayDates.is_before_eof_7days_of_term,
    }),
    ...mapState('schedule', {
      courseData: function (state) { return state.value[this.term]; },
    }),
    ...mapGetters('schedule', {
      isReadySchedule: 'isReadyTagged',
      isErroredSchedule: 'isErroredTagged',
      statusCodeSchedule: 'statusCodeTagged'
    }),
    ...mapGetters('textbooks', {
      isReadyTextbook: 'isReadyTagged',
      isErroredTextbook: 'isErroredTagged',
      statusCodeTextbooks: 'statusCodeTagged',
      getProcessedData: 'getProcessedData',
    }),
    show() {
      return (
        this.student &&
        (this.term !== 'current' || this.isBeforeEndOfFirstWeek)
      );
    },
    showError() {
      return (
        this.statusCodeSchedule(this.term) != 404 &&
        this.statusCodeTextbooks(this.term) != 404
      );
    },
    bookData() {
      if (this.isReadyTextbook(this.term) && this.isReadySchedule(this.term)) {
        let data = this.getProcessedData(this.courseData);
        let noBookAssigned = true;
        let sectionBookData = [];

        data.enrolledSections.forEach((section) => {
          let required = 0;
          let optional = 0;
          if (section.books) {
            section.books.forEach((book) => {
              if (book.is_required) {
                required += 1;
              } else {
                optional += 1;
              }
              if (noBookAssigned) {
                noBookAssigned = false;
              }
            });
          }
          let courseId = `${section.curriculum} ${section.courseNumber} ${section.sectionId}`;

          let sectionData = {
            courseId: courseId,
            colorId: section.colorId,
            requiredBooks: required,
            totalBooks: required + optional,
{'fraction_non_alphanumeric': 0.151801535735381, 'fraction_numerical': 0.004282339043118724, 'mean_word_length': 1.9269662921348314, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 71, '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': '6029876', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2078, 'n_words': 350}