<commit_before><template>
  <membership-detail
    :data="data"
    :is-expired="isExpired"
    :is-one-time="isOneTime"
  />
</template>

<script>
/* eslint-disable camelcase */

import isPast from 'date-fns/is_past';
import format from 'date-fns/format';
import parse from 'date-fns/parse';

import MembershipDetail from '../components/MembershipDetail.vue';
import addNumberCommas from '../../../utils/add-number-commas';
import userMixin from '../../home/mixins/user';

export default {
  name: 'MembershipDetailContainer',

  components: { MembershipDetail },

  mixins: [userMixin],

  computed: {
    isOneTime() {
      return !this.user.recurring_donor;
    },

    isExpired() {
      return isPast(parse(this.user.membership_expiration_date));
    },

    data() {
      const data = [
        { id: 0, heading: 'Donation', text: '' },
        { id: 1, heading: 'Payment method', text: '' },
        { id: 2 },
      ];
      const {
        recurring_donor,
        membership_expiration_date,
        next_transaction,
        last_transaction,
      } = this.user;
      const expired = isPast(parse(membership_expiration_date));

      if (!recurring_donor) {
        const {
          amount,
          date,
          credit_card: { last4, brand },
        } = last_transaction;

        data[0].text = `$${addNumberCommas(amount)}, ${format(
          parse(date),
          'MMMM D, YYYY'
        )}`;
        data[1].text = `${brand} ending in ${last4}`;
        data[2].heading = 'Status';
        data[2].text = `Your membership is good through ${format(
          parse(membership_expiration_date),
          'MMMM D, YYYY'
        )}.`;
      } else if (recurring_donor && expired) {
        const {
          amount,
          date,
          credit_card: { last4, brand },
        } = last_transaction;

        data[0].text = `$${addNumberCommas(amount)}, ${format(
          parse(date),
          'MMMM D, YYYY'
        )}`;
        data[1].text = `${brand} ending in ${last4}`;
        data[2].heading = 'Status';
        data[2].text = 'Your membership expired.';
      } else if (recurring_donor && !expired) {
        const {
          amount,
          date,
          period,
          credit_card: { last4, brand },
        } = next_transaction;

        data[0].text = `$${addNumberCommas(amount)}, ${period}`;
        data[1].text = `${brand} ending in ${last4}`;
        data[2].heading = 'Next payment';
        data[2].text = format(parse(date), 'MMMM D, YYYY');
      }

      return data;
    },
  },
};
</script><commit_msg>account for possibility of non-card payments<commit_after><template>
  <membership-detail
    :data="data"
    :is-expired="isExpired"
    :is-one-time="isOneTime"
  />
</template>

<script>
/* eslint-disable camelcase */

import isPast from 'date-fns/is_past';
import format from 'date-fns/format';
import parse from 'date-fns/parse';

import MembershipDetail from '../components/MembershipDetail.vue';
import addNumberCommas from '../../../utils/add-number-commas';
import userMixin from '../../home/mixins/user';

export default {
  name: 'MembershipDetailContainer',

  components: { MembershipDetail },

  mixins: [userMixin],

  computed: {
    isOneTime() {
      return !this.user.recurring_donor;
    },

    isExpired() {
      return isPast(parse(this.user.membership_expiration_date));
    },

    data() {
      const data = [{ id: 0 }, { id: 1 }];
      const {
        recurring_donor,
        membership_expiration_date,
        next_transaction,
        last_transaction,
      } = this.user;
      const expired = isPast(parse(membership_expiration_date));

      if (!recurring_donor) {
        const { amount, date, payment_type, credit_card } = last_transaction;

        data[0].heading = 'Last donation';
        data[0].text = `$${addNumberCommas(amount)}, ${format(
          parse(date),
          'MMMM D, YYYY'
        )}`;

        if (payment_type.toLowerCase() === 'credit card') {
          data[1].heading = 'Payment method';
          data[1].text = `${credit_card.brand} ending in ${credit_card.last4}`;
          data[2] = { id: 2 };
          data[2].heading = 'Status';
          data[2].text = 'Your membership is good for one year.';
        } else {
          data[1].heading = 'Status';
          data[1].text = 'Your membership is good for one year.';
        }
      } else if (recurring_donor && expired) {
        const { amount, date, payment_type, credit_card } = last_transaction;

        data[0].heading = 'Last donation';
        data[0].text = `$${addNumberCommas(amount)}, ${format(
          parse(date),
          'MMMM D, YYYY'
        )}`;

        if (payment_type.toLowerCase() === 'credit card') {
          data[1].heading = 'Payment method';
          data[1].text = `${credit_card.brand} ending in ${credit_card.last4}`;
          data[2] = { id: 2 };
          data[2].heading = 'Status';
          data[2].text = 'Your membership expired.';
        } else {
          data[1].heading = 'Status';
          data[1].text = 'Your membership expired.';
        }
      } else if (recurring_donor && !expired) {
        const {
          amount,
          date,
          period,
          payment_type,
          credit_card,
        } = next_transaction;

        data[0].heading = 'Donation';
        data[0].text = `$${addNumberCommas(amount)}, ${period}`;

        if (payment_type.toLowerCase() === 'credit card') {
          data[1].heading = 'Payment method';
          data[1].text = `${credit_card.brand} ending in ${credit_card.last4}`;
          data[2] = { id: 2 };
          data[2].heading = 'Next payment';
          data[2].text = format(parse(date), 'MMMM D, YYYY');
        } else {
          data[1].heading = 'Next payment';
          data[1].text = format(parse(date), 'MMMM D, YYYY');
        }
      }

      return data;
    },
  },
};
</script>
{'fraction_non_alphanumeric': 0.15511103576877436, 'fraction_numerical': 0.009493134429564332, 'mean_word_length': 2.1995661605206074, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1895185', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1867, 'n_words': 388}