{"version":3,"file":"useQuizSession-CeoWB3QI.js","sources":["../../../app/javascript/composables/useQuizSession.js"],"sourcesContent":["import { computed } from \"vue\"\nimport timeHelpers from \"@/helpers/time_helpers\"\nimport helpers from \"@/helpers\"\nimport { useStore } from \"@/store\"\nimport i18n from \"@/plugins/i18n\"\n\n\nconst states = [\n {\n value: \"not_started\",\n color: \"blue-grey\",\n icon: \"mdi-calendar-remove-outline\",\n label: i18n.t(\"quiz.sessions.state.notStarted\"),\n allowManualStart: true,\n allowManualStop: false,\n },\n {\n value: \"scheduled\",\n color: \"blue\",\n icon: \"mdi-calendar-clock-outline\",\n label: i18n.t(\"quiz.sessions.state.scheduled\"),\n allowManualStart: true,\n allowManualStop: false,\n },\n {\n value: \"open\",\n color: \"green\",\n icon: \"mdi-play-circle-outline\",\n label: i18n.t(\"quiz.sessions.state.open\"),\n allowManualStart: false,\n allowManualStop: true,\n },\n {\n value: \"closed\",\n color: \"red\",\n icon: \"mdi-stop-circle-outline\",\n label: i18n.t(\"quiz.sessions.state.closed\"),\n allowManualStart: true,\n allowManualStop: false,\n },\n]\n\nexport function useQuizSession(session) {\n\n const store = useStore()\n\n const state = computed(() => {\n return states.find(s => s.value === session.state)\n })\n\n const pendingStateChange = computed(() => {\n return !!session.manual_open_requested_at\n })\n\n const color = computed(() => {\n return state.value.color\n })\n\n const icon = computed(() => {\n return state.value.icon\n })\n\n const dateRange = computed(() => {\n if (!session.start_at && !session.scheduled_end_at) {\n return i18n.t(\"quiz.settings.sessions.openAndCloseManually\")\n }\n return timeHelpers.formatDateRange(\n session.start_at,\n session.end_at,\n {\n showDateIfSameDay: true,\n startPlaceholder: i18n.t(\"quiz.settings.sessions.tooltip.notScheduled.start\"),\n endPlaceholder: i18n.t(\"quiz.settings.sessions.tooltip.notScheduled.end\"),\n }\n )\n })\n\n const startsAndEndsOnSameDay = computed(() => {\n return helpers.isSameDay(session.start_at, session.end_at)\n })\n\n const allowManualStart = computed(() => {\n return state.value.allowManualStart\n })\n\n const allowManualStop = computed(() => {\n return state.value.allowManualStop\n })\n\n const withDefaultValue = ({ existingSessions } = { existingSessions: [] }) => {\n return {\n name: `Session ${existingSessions.length + 1}`,\n sessionable_type: \"Quizzes::GeneralSession\",\n allow_self_enrollment: \"none\",\n sessionable_attributes: { quizzes_group_ids: [] },\n ...state.value,\n }\n }\n\n // Todo: session.quizzes_group_ids is deprecated, use session.sessionable.quizzes_group_ids instead when available\n const groups = computed(() => {\n return store.getters.quizzesGroups(session.quiz_id).filter(g => session.sessionable_attributes.quizzes_group_ids.includes(g.id))\n })\n\n return {\n color,\n icon,\n dateRange,\n state,\n pendingStateChange,\n allowManualStart,\n allowManualStop,\n startsAndEndsOnSameDay,\n withDefaultValue,\n groups,\n }\n}\n"],"names":["states","i18n","useQuizSession","session","store","useStore","state","computed","s","pendingStateChange","color","icon","dateRange","timeHelpers","startsAndEndsOnSameDay","helpers","allowManualStart","allowManualStop","withDefaultValue","existingSessions","__spreadValues","groups","g"],"mappings":"o4BAOA,MAAMA,EAAS,CACb,CACE,MAAO,cACP,MAAO,YACP,KAAM,8BACN,MAAOC,EAAK,EAAE,gCAAgC,EAC9C,iBAAkB,GAClB,gBAAiB,EAClB,EACD,CACE,MAAO,YACP,MAAO,OACP,KAAM,6BACN,MAAOA,EAAK,EAAE,+BAA+B,EAC7C,iBAAkB,GAClB,gBAAiB,EAClB,EACD,CACE,MAAO,OACP,MAAO,QACP,KAAM,0BACN,MAAOA,EAAK,EAAE,0BAA0B,EACxC,iBAAkB,GAClB,gBAAiB,EAClB,EACD,CACE,MAAO,SACP,MAAO,MACP,KAAM,0BACN,MAAOA,EAAK,EAAE,4BAA4B,EAC1C,iBAAkB,GAClB,gBAAiB,EAClB,CACH,EAEO,SAASC,EAAeC,EAAS,CAEtC,MAAMC,EAAQC,EAAQ,EAEhBC,EAAQC,EAAS,IACdP,EAAO,KAAKQ,GAAKA,EAAE,QAAUL,EAAQ,KAAK,CAClD,EAEKM,EAAqBF,EAAS,IAC3B,CA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