import type { SettingDefinition } from '@nuclearplayer/plugin-sdk';

import { registerCoreSettings } from '../stores/settingsStore';

const LANGUAGE_OPTIONS = [
  { value: 'en_US', label: 'English' },
  { value: 'de_DE', label: 'Deutsch' },
  { value: 'es_ES', label: 'Español' },
  { value: 'fr_FR', label: 'Français' },
  { value: 'it_IT', label: 'Italiano' },
  { value: 'pt_BR', label: 'Português (Brasil)' },
  { value: 'ru_RU', label: 'Русский' },
];

export const CORE_SETTINGS: SettingDefinition[] = [
  {
    id: 'appearance.framelessWindow',
    title: 'preferences.appearance.framelessWindow.title',
    description: 'preferences.appearance.framelessWindow.description',
    category: 'appearance',
    kind: 'boolean',
    default: false,
    widget: { type: 'toggle' },
  },
  {
    id: 'theme.active.type',
    title: 'preferences.theme.active.type.title',
    description: 'preferences.theme.active.type.description',
    category: 'appearance',
    kind: 'string',
    default: 'basic',
    hidden: true,
    widget: { type: 'text' },
  },
  {
    id: 'theme.active.id',
    title: 'preferences.theme.active.id.title',
    description: 'preferences.theme.active.id.description',
    category: 'appearance',
    kind: 'string',
    default: '',
    hidden: true,
    widget: { type: 'text' },
  },
  {
    id: 'theme.dark',
    title: 'preferences.theme.dark.title',
    description: 'preferences.theme.dark.description',
    category: 'appearance',
    kind: 'boolean',
    default: false,
    hidden: true,
    widget: { type: 'toggle' },
  },
  {
    id: 'playback.volume',
    title: 'preferences.playback.volume.title',
    description: 'preferences.playback.volume.description',
    category: 'playback',
    kind: 'number',
    default: 1,
    hidden: true,
    widget: { type: 'slider', min: 0, max: 1, step: 0.01 },
  },
  {
    id: 'playback.muted',
    title: 'preferences.playback.muted.title',
    description: 'preferences.playback.muted.description',
    category: 'playback',
    kind: 'boolean',
    default: false,
    hidden: true,
    widget: { type: 'toggle' },
  },
  {
    id: 'playback.shuffle',
    title: 'preferences.playback.shuffle.title',
    description: 'preferences.playback.shuffle.description',
    category: 'playback',
    kind: 'boolean',
    default: false,
    hidden: true,
    widget: { type: 'toggle' },
  },
  {
    id: 'playback.repeat',
    title: 'preferences.playback.repeat.title',
    description: 'preferences.playback.repeat.description',
    category: 'playback',
    kind: 'string',
    default: 'off',
    hidden: true,
    widget: { type: 'text' },
  },
  {
    id: 'playback.discovery',
    title: 'preferences.playback.discovery.title',
    description: 'preferences.playback.discovery.description',
    category: 'playback',
    kind: 'boolean',
    default: false,
    hidden: true,
    widget: { type: 'toggle' },
  },
  {
    id: 'playback.discoveryVariety',
    title: 'preferences.playback.discoveryVariety.title',
    description: 'preferences.playback.discoveryVariety.description',
    category: 'playback',
    kind: 'number',
    default: 0.5,
    widget: {
      type: 'slider',
      min: 0,
      max: 1,
      step: 0.05,
      startLabel: 'preferences.playback.discoveryVariety.startLabel',
      endLabel: 'preferences.playback.discoveryVariety.endLabel',
    },
  },
  {
    id: 'playback.skipSeconds',
    title: 'preferences.playback.skipSeconds.title',
    description: 'preferences.playback.skipSeconds.description',
    category: 'playback',
    kind: 'number',
    default: 5,
    widget: { type: 'number-input', min: 1, max: 60, step: 1, unit: 's' },
  },
  {
    id: 'playback.crossfadeMs',
    title: 'preferences.playback.crossfadeMs.title',
    description: 'preferences.playback.crossfadeMs.description',
    category: 'playback',
    kind: 'number',
    default: 0,
    widget: { type: 'number-input', min: 0, max: 5000, step: 50, unit: 'ms' },
  },
  {
    id: 'playback.streamExpiryMs',
    title: 'preferences.playback.streamExpiryMs.title',
    description: 'preferences.playback.streamExpiryMs.description',
    category: 'playback',
    kind: 'number',
    default: 3600000,
    widget: {
      type: 'number-input',
      min: 300000,
      max: 86400000,
      step: 300000,
      unit: 'ms',
    },
  },
  {
    id: 'playback.streamResolutionRetries',
    title: 'preferences.playback.streamResolutionRetries.title',
    description: 'preferences.playback.streamResolutionRetries.description',
    category: 'playback',
    kind: 'number',
    default: 3,
    widget: { type: 'number-input', min: 1, max: 10, step: 1 },
  },
  {
    id: 'layout.leftSidebarWidth',
    title: 'preferences.layout.leftSidebarWidth.title',
    description: 'preferences.layout.leftSidebarWidth.description',
    category: 'layout',
    kind: 'number',
    default: 200,
    hidden: true,
    widget: { type: 'slider', min: 120, max: 480, step: 4, unit: 'px' },
  },
  {
    id: 'layout.rightSidebarWidth',
    title: 'preferences.layout.rightSidebarWidth.title',
    description: 'preferences.layout.rightSidebarWidth.description',
    category: 'layout',
    kind: 'number',
    default: 200,
    hidden: true,
    widget: { type: 'slider', min: 120, max: 480, step: 4, unit: 'px' },
  },
  {
    id: 'general.language',
    title: 'preferences.general.language.title',
    description: 'preferences.general.language.description',
    category: 'general',
    kind: 'enum',
    options: LANGUAGE_OPTIONS,
    default: 'en_US',
    widget: { type: 'select' },
  },
  {
    id: 'updates.checkForUpdates',
    title: 'preferences.updates.checkForUpdates.title',
    description: 'preferences.updates.checkForUpdates.description',
    category: 'updates',
    kind: 'boolean',
    default: true,
    widget: { type: 'toggle' },
  },
  {
    id: 'updates.autoInstall',
    title: 'preferences.updates.autoInstall.title',
    description: 'preferences.updates.autoInstall.description',
    category: 'updates',
    kind: 'boolean',
    default: false,
    widget: { type: 'toggle' },
  },
  {
    id: 'plugins.autoUpdate',
    title: 'preferences.plugins.auto-update.title',
    description: 'preferences.plugins.auto-update.description',
    category: 'plugins',
    kind: 'boolean',
    default: true,
    widget: { type: 'toggle' },
  },
  {
    id: 'integrations.mcp.enabled',
    title: 'preferences.integrations.mcp.enabled.title',
    description: 'preferences.integrations.mcp.enabled.description',
    category: 'integrations',
    kind: 'boolean',
    default: false,
    widget: { type: 'toggle' },
  },
  {
    id: 'integrations.mcp.serverUrl',
    title: 'preferences.integrations.mcp.serverUrl.title',
    description: 'preferences.integrations.mcp.serverUrl.description',
    category: 'integrations',
    kind: 'string',
    default: 'http://127.0.0.1:8800/mcp',
    widget: { type: 'info' },
  },
  {
    id: 'integrations.mpd.enabled',
    title: 'preferences.integrations.mpd.enabled.title',
    description: 'preferences.integrations.mpd.enabled.description',
    category: 'integrations',
    kind: 'boolean',
    default: false,
    widget: { type: 'toggle' },
  },
  {
    id: 'integrations.mpd.serverUrl',
    title: 'preferences.integrations.mpd.serverUrl.title',
    description: 'preferences.integrations.mpd.serverUrl.description',
    category: 'integrations',
    kind: 'string',
    default: 'mpd://127.0.0.1:6600',
    widget: { type: 'info' },
  },
  {
    id: 'integrations.discord.enabled',
    title: 'preferences.integrations.discord.enabled.title',
    description: 'preferences.integrations.discord.enabled.description',
    category: 'integrations',
    kind: 'boolean',
    default: false,
    widget: { type: 'toggle' },
  },
];

export const registerBuiltInCoreSettings = () => {
  registerCoreSettings(CORE_SETTINGS);
};
