{"version":3,"file":"store.ZhgpbYjw.js","sources":["../../../../../../src/lib/utils/filters/store.ts"],"sourcesContent":["import { derived, type Readable, type Writable, writable } from 'svelte/store';\nimport type { FilterType, IFilters } from './types';\n\nexport const getDefaultFilters = (): IFilters => ({\n courseType: [],\n score: undefined,\n category: [],\n lessionMode: [],\n duration: [],\n priceMin: 0,\n priceMax: 30000,\n studentType: [],\n month: [],\n credits: undefined,\n certificationReleaseEntity: [],\n});\n\nexport class FilterStore {\n private static instance: FilterStore;\n\n private _fetchingData: Writable;\n\n private _courseTypeFacets: Writable;\n private _categoryFacets: Writable;\n private _lessionModeFacets: Writable;\n private _durationFacets: Writable;\n private _studentTypeFacets: Writable;\n private _monthFacets: Writable;\n private _creditsFacets: Writable;\n private _certificationReleaseEntityFacets: Writable;\n\n public searchStore: Writable = writable('');\n public currentTyped: Writable = writable('');\n public suggestedSearch: Writable = writable([]);\n\n public filterStore: Writable = writable(getDefaultFilters());\n public clearfilterStore: Writable = writable(getDefaultFilters());\n public filtersApplied: Readable<{ [key in FilterType]: boolean }> = derived(\n this.filterStore,\n ($store) => {\n const defaultFilters = getDefaultFilters();\n return {\n courseType: !FilterStore.isEqual($store.courseType, defaultFilters.courseType),\n score: $store.score !== defaultFilters.score,\n category: !FilterStore.isEqual($store.category, defaultFilters.category),\n lessionMode: !FilterStore.isEqual($store.lessionMode, defaultFilters.lessionMode),\n duration: !FilterStore.isEqual($store.duration, defaultFilters.duration),\n priceMin: $store.priceMin != defaultFilters.priceMin,\n priceMax: $store.priceMax != defaultFilters.priceMax,\n studentType: !FilterStore.isEqual($store.studentType, defaultFilters.studentType),\n month: !FilterStore.isEqual($store.month, defaultFilters.month),\n credits: $store.credits !== defaultFilters.credits,\n certificationReleaseEntity: !FilterStore.isEqual(\n $store.certificationReleaseEntity,\n defaultFilters.certificationReleaseEntity\n ),\n };\n }\n );\n public isAnyFilterApplied: Readable = derived(this.filtersApplied, ($store) => {\n for (let filter in $store) {\n if ($store[filter]) return true;\n }\n return false;\n });\n\n public static getInstance() {\n if (!FilterStore.instance) {\n FilterStore.instance = new FilterStore();\n }\n return FilterStore.instance;\n }\n\n public setCourseTypeFacets(facets: any) {\n this._courseTypeFacets.set(facets?.course_type_full_slug || null);\n }\n\n public setCategoryFacets(facets: any) {\n this._categoryFacets.set(facets?.categories_slugs || null);\n }\n\n public setLessionModeFacets(facets: any) {\n this._lessionModeFacets.set(facets?.lession_mode_slug || null);\n }\n\n public setDurationFacets(facets: any) {\n this._durationFacets.set(facets?.duration_slug || null);\n }\n\n public setMonthFacets(facets: any) {\n this._monthFacets.set(facets?.month || null);\n }\n\n public setCreditsFacets(facets: any) {\n this._creditsFacets.set(facets?.credits || null);\n }\n\n public setStudentTypeFacets(facets: any) {\n this._studentTypeFacets.set(facets?.student_type || null);\n }\n\n public setCertificationReleaseEntityFacets(facets: any) {\n this._certificationReleaseEntityFacets.set(facets?.certification_release_entity || null);\n }\n\n public removeAllFilters() {\n this.filterStore.set(getDefaultFilters());\n }\n\n public removeSearchText() {\n this.searchStore.set('');\n }\n\n public setFilters(filters: IFilters) {\n this.filterStore.set(filters);\n }\n\n public setFetchingData(fetching: boolean) {\n this._fetchingData.set(fetching);\n }\n\n public get isFetching() {\n return derived(this._fetchingData, (value) => value);\n }\n\n public get courseTypeFacets() {\n return derived(this._courseTypeFacets, (value) => value);\n }\n\n public get categoryFacets() {\n return derived(this._categoryFacets, (value) => value);\n }\n\n public get lessionModeFacets() {\n return derived(this._lessionModeFacets, (value) => value);\n }\n\n public get durationFacets() {\n return derived(this._durationFacets, (value) => value);\n }\n\n public get studentTypeFacets() {\n return derived(this._studentTypeFacets, (value) => value);\n }\n\n public get monthFacets() {\n return derived(this._monthFacets, (value) => value);\n }\n\n public get creditsFacets() {\n return derived(this._creditsFacets, (value) => value);\n }\n\n public get certificationReleaseEntityFacets() {\n return derived(this._certificationReleaseEntityFacets, (value) => value);\n }\n\n private constructor() {\n this._courseTypeFacets = writable(null);\n this._categoryFacets = writable(null);\n this._lessionModeFacets = writable(null);\n this._durationFacets = writable(null);\n this._studentTypeFacets = writable(null);\n this._monthFacets = writable(null);\n this._creditsFacets = writable(null);\n this._certificationReleaseEntityFacets = writable(null);\n this._fetchingData = writable(false);\n }\n\n public static isEqual(array1: (number | string)[], array2: (number | string)[]) {\n return (\n array1.length === array2.length && array1.every((value, index) => value === array2[index])\n );\n }\n\n // reset all filters\n public resetFilters() {\n this.filterStore.set(getDefaultFilters());\n }\n}\n"],"names":["getDefaultFilters","_FilterStore","__publicField","writable","derived","$store","defaultFilters","filter","facets","filters","fetching","value","array1","array2","index","FilterStore"],"mappings":"mNAGO,MAAMA,EAAoB,KAAiB,CAChD,WAAY,CAAC,EACb,MAAO,OACP,SAAU,CAAC,EACX,YAAa,CAAC,EACd,SAAU,CAAC,EACX,SAAU,EACV,SAAU,IACV,YAAa,CAAC,EACd,MAAO,CAAC,EACR,QAAS,OACT,2BAA4B,CAAA,CAC9B,GAEaC,EAAN,MAAMA,CAAY,CA4If,aAAc,CAzIdC,EAAA,sBAEAA,EAAA,0BACAA,EAAA,wBACAA,EAAA,2BACAA,EAAA,wBACAA,EAAA,2BACAA,EAAA,qBACAA,EAAA,uBACAA,EAAA,0CAEDA,EAAA,mBAAgCC,EAAS,EAAE,GAC3CD,EAAA,oBAAiCC,EAAS,EAAE,GAC5CD,EAAA,uBAAsCC,EAAS,EAAE,GAEjDD,EAAA,mBAAkCC,EAASH,GAAmB,GAC9DE,EAAA,wBAAuCC,EAASH,GAAmB,GACnEE,EAAA,sBAA6DE,EAClE,KAAK,YACJC,GAAW,CACV,MAAMC,EAAiBN,EAAkB,EAClC,MAAA,CACL,WAAY,CAACC,EAAY,QAAQI,EAAO,WAAYC,EAAe,UAAU,EAC7E,MAAOD,EAAO,QAAUC,EAAe,MACvC,SAAU,CAACL,EAAY,QAAQI,EAAO,SAAUC,EAAe,QAAQ,EACvE,YAAa,CAACL,EAAY,QAAQI,EAAO,YAAaC,EAAe,WAAW,EAChF,SAAU,C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