refactor: place all presentation code in a presentation folder

Some features didn't have this folder.

Bug: twpowertools:226
Change-Id: Ic9803e7ee66a15c6c9e083509e059e453a26ed0f
diff --git a/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/ecApp.handler.ts b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/ecApp.handler.ts
new file mode 100644
index 0000000..3676bcd
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/ecApp.handler.ts
@@ -0,0 +1,29 @@
+import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
+import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
+import { injectDarkThemeButton } from '../../core/logic/darkTheme';
+
+/**
+ * Injects the dark theme button.
+ */
+export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherHandler {
+  cssSelector = 'ec-app';
+
+  constructor(private optionsProvider: OptionsProviderPort) {
+    super();
+  }
+
+  async onMutatedNode(mutation: NodeMutation) {
+    if (!(mutation.node instanceof Element)) return;
+
+    const isEnabled = await this.optionsProvider.isEnabled('ccdarktheme');
+    const mode = await this.optionsProvider.getOptionValue('ccdarktheme_mode');
+
+    // TODO(avm99963): make this feature dynamic.
+    if (isEnabled && mode === 'switch') {
+      const rightControl = mutation.node.querySelector('header .right-control');
+      if (rightControl === null) return;
+      injectDarkThemeButton(rightControl);
+    }
+  }
+}
diff --git a/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/reportDialog.handler.ts b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/reportDialog.handler.ts
new file mode 100644
index 0000000..89ccdf2
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/reportDialog.handler.ts
@@ -0,0 +1,25 @@
+import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
+import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
+import ReportDialogColorThemeFix from '../../core/logic/reportDialog';
+
+/**
+ * Sets the report dialog iframe's theme to the appropriate theme.
+ */
+export default class CCDarkThemeReportDialogHandler extends CssSelectorNodeWatcherHandler {
+  cssSelector = 'iframe';
+
+  constructor(
+    private optionsProvider: OptionsProviderPort,
+    private reportDialogColorThemeFix: ReportDialogColorThemeFix,
+  ) {
+    super();
+  }
+
+  onMutatedNode(mutation: NodeMutation) {
+    this.reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(
+      mutation.node,
+      this.optionsProvider,
+    );
+  }
+}
diff --git a/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
new file mode 100644
index 0000000..13b6cc9
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
@@ -0,0 +1,27 @@
+import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
+import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
+import { isDarkThemeOn } from '../../core/logic/darkTheme';
+import { unifiedProfilesFix } from '../../core/logic/unifiedProfiles';
+
+/**
+ * Redirect unified profile iframe to dark version if applicable
+ */
+export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherHandler {
+  cssSelector = 'iframe';
+
+  constructor(private optionsProvider: OptionsProviderPort) {
+    super();
+  }
+
+  async onMutatedNode(mutation: NodeMutation) {
+    const optionsValues = await this.optionsProvider.getOptionsValues();
+
+    if (
+      isDarkThemeOn(optionsValues) &&
+      unifiedProfilesFix.checkIframe(mutation.node)
+    ) {
+      unifiedProfilesFix.fixIframe(mutation.node);
+    }
+  }
+}
diff --git a/src/features/ccDarkTheme/presentation/scripts/injectAutoDarkTheme.script.ts b/src/features/ccDarkTheme/presentation/scripts/injectAutoDarkTheme.script.ts
new file mode 100644
index 0000000..afbe161
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/scripts/injectAutoDarkTheme.script.ts
@@ -0,0 +1,17 @@
+import { ScriptPage } from '../../../../common/architecture/scripts/Script';
+import StylesheetScript from '../../../../common/architecture/scripts/stylesheet/StylesheetScript';
+
+export default class CCDarkThemeInjectAutoDarkTheme extends StylesheetScript {
+  stylesheet = 'ccDarkTheme.bundle.css';
+  attributes = { media: '(prefers-color-scheme: dark)' };
+  page = ScriptPage.CommunityConsole;
+
+  async shouldBeInjected(): Promise<boolean> {
+    const ccDarkThemeEnabled =
+      await this.optionsProvider.isEnabled('ccdarktheme');
+    const ccDarkThemeMode =
+      await this.optionsProvider.getOptionValue('ccdarktheme_mode');
+
+    return ccDarkThemeEnabled && ccDarkThemeMode === 'system';
+  }
+}
diff --git a/src/features/ccDarkTheme/presentation/scripts/injectForcedDarkTheme.script.ts b/src/features/ccDarkTheme/presentation/scripts/injectForcedDarkTheme.script.ts
new file mode 100644
index 0000000..0a16a70
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/scripts/injectForcedDarkTheme.script.ts
@@ -0,0 +1,23 @@
+import { ScriptPage } from '../../../../common/architecture/scripts/Script';
+import StylesheetScript from '../../../../common/architecture/scripts/stylesheet/StylesheetScript';
+
+export default class CCDarkThemeInjectForcedDarkTheme extends StylesheetScript {
+  stylesheet = 'ccDarkTheme.bundle.css';
+  page = ScriptPage.CommunityConsole;
+
+  async shouldBeInjected(): Promise<boolean> {
+    const ccDarkThemeEnabled =
+      await this.optionsProvider.isEnabled('ccdarktheme');
+    const ccDarkThemeMode =
+      await this.optionsProvider.getOptionValue('ccdarktheme_mode');
+    const ccDarkThemeSwitchEnabled = await this.optionsProvider.isEnabled(
+      'ccdarktheme_switch_status',
+    );
+
+    return (
+      ccDarkThemeEnabled &&
+      ccDarkThemeMode === 'switch' &&
+      ccDarkThemeSwitchEnabled
+    );
+  }
+}