1import { computed } from "@common/signal.js";
2import { OutputTransformer } from "../../base.js";
3
4/**
5 * @import { OutputManagerDeputy } from "../../../../output/types.d.ts"
6 */
7
8/**
9 * @extends {OutputTransformer}
10 */
11class DefaultOutputRefinerTransformer extends OutputTransformer {
12 constructor() {
13 super();
14
15 const base = this.base();
16
17 /** @type {OutputManagerDeputy} */
18 const manager = {
19 facets: {
20 ...base.facets,
21 collection: computed(() => {
22 return base.facets.collection() ?? [];
23 }),
24 },
25 playlists: {
26 ...base.playlists,
27 collection: computed(() => {
28 return base.playlists.collection() ?? [];
29 }),
30 },
31 themes: {
32 ...base.themes,
33 collection: computed(() => {
34 return base.themes.collection() ?? [];
35 }),
36 },
37 tracks: {
38 ...base.tracks,
39 collection: computed(() => {
40 return base.tracks.collection() ?? [];
41 }),
42 save: async (newTracks) => {
43 const filtered = newTracks.filter((t) => !t.ephemeral);
44 await base.tracks.save(filtered);
45 },
46 },
47 };
48
49 // Assign manager properties to class
50 this.facets = manager.facets;
51 this.playlists = manager.playlists;
52 this.themes = manager.themes;
53 this.tracks = manager.tracks;
54 }
55}
56
57export default DefaultOutputRefinerTransformer;
58
59////////////////////////////////////////////
60// REGISTER
61////////////////////////////////////////////
62
63export const CLASS = DefaultOutputRefinerTransformer;
64export const NAME = "dtor-default";
65
66customElements.define(NAME, CLASS);