All files / src/components/Appointment/ServiceFinder SubserviceListItem.vue

100% Statements 35/35
100% Branches 5/5
0% Functions 0/1
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82  1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x     1x 1x         1x           1x   1x   1x 2x 1x             1x 16x     16x     16x   16x 16x 16x 16x 16x 16x 1x   1x 16x 1x                                    
<template>
  <li class="m-listing__list-item">
    <div class="list-item">
      <muc-counter
        v-model="count"
        :label="subService.name"
        :link="getServiceBaseURL() + subService.id"
        :max="maxValue"
        :disabled="disabled"
      />
    </div>
  </li>
</template>
 
<script setup lang="ts">
import { MucCounter } from "@muenchen/muc-patternlab-vue";
import { computed, ref, watch } from "vue";
 
import { SubService } from "@/types/SubService";
import { getServiceBaseURL } from "@/utils/Constants";
import {
  calculateMaxCountBySlots,
  getMaxSlotOfProvider,
} from "@/utils/slotCalculations";
 
const props = defineProps<{
  subService: SubService;
  currentSlots: number;
  minSlotsPerAppointment: number;
}>();
 
const emit = defineEmits<(e: "change", id: string, count: number) => void>();
 
const count = ref<number>(props.subService.count);
 
watch(count, (newCount) => {
  emit("change", props.subService.id, newCount);
});
 
/**
 * Calculates the maximum count for this subservice, considering both:
 * - maxQuantity: the subservice's own limit
 * - minSlotsPerAppointment: remaining slots after accounting for main service and other subservices
 */
const maxValue = computed(() => {
  const subServiceSlots = getMaxSlotOfProvider(props.subService.providers);
 
  // Calculate slots currently used by this subservice
  const thisSlotsUsed = subServiceSlots * count.value;
 
  // Slots used by others = currentSlots - this subservice's contribution
  const slotsUsedByOthers = props.currentSlots - thisSlotsUsed;
 
  return calculateMaxCountBySlots(
    subServiceSlots,
    props.subService.maxQuantity,
    props.minSlotsPerAppointment,
    slotsUsedByOthers
  );
});
 
const disabled = computed(() => {
  return maxValue.value === 0 && count.value === 0;
});
</script>
 
<style lang="scss" scoped>
@use "@/styles/breakpoints.scss" as *;
.list-item {
  margin-bottom: 1.75rem;
}
.grid {
  grid-template-columns: minmax(150px, auto) 1fr !important;
}
 
@include sm-down {
  .grid {
    grid-template-columns: 1fr !important;
  }
}
</style>