import { ThemeLayoutContainerDefinition, ThemeRegistryEntry } from '../models/theme.model';

export const THEME_LAYOUT_CONTAINERS: readonly ThemeLayoutContainerDefinition[] = [
  {
    key: 'appShell',
    label: 'App Shell',
    description: 'Controls how the global rail and workspace split the application frame.',
    columns: 20,
    rows: 1,
    templateColumns: '4rem repeat(19, minmax(0, 1fr))'
  },
  {
    key: 'roomLayout',
    label: 'Room Workspace',
    description: 'Controls the channel list, main chat panel, and member list inside a room.',
    columns: 20,
    rows: 12,
    templateColumns: 'repeat(4, 4.25rem) repeat(12, minmax(0, 1fr)) repeat(4, 4.25rem)'
  },
  {
    key: 'dmLayout',
    label: 'DM Workspace',
    description: 'Controls the conversations list and private chat panel inside direct messages.',
    columns: 20,
    rows: 12,
    templateColumns: 'repeat(4, 4.25rem) repeat(16, minmax(0, 1fr))'
  }
];

export const THEME_REGISTRY: readonly ThemeRegistryEntry[] = [
  {
    key: 'appRoot',
    label: 'App Root',
    description: 'Global workspace wrapper that owns theme tokens and high-level app background styling.',
    category: 'shell',
    layoutEditable: false,
    pickerVisible: false,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'serversRail',
    label: 'Servers Rail',
    description: 'The persistent left navigation rail that holds saved servers and the create button.',
    category: 'shell',
    container: 'appShell',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'appWorkspace',
    label: 'App Workspace',
    description: 'The main workspace area to the right of the server rail.',
    category: 'shell',
    container: 'appShell',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'titleBar',
    label: 'Title Bar',
    description: 'The top application bar that shows the active room context and desktop controls.',
    category: 'shell',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: true,
    supportsIcon: true
  },
  {
    key: 'serversRailCreateButton',
    label: 'Create Server Button',
    description: 'The primary action at the top of the server rail for creating or joining servers.',
    category: 'shell',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'serversRailList',
    label: 'Servers List',
    description: 'The scrollable stack of saved server shortcuts in the left rail.',
    category: 'shell',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'serversRailItem',
    label: 'Server Shortcut',
    description: 'An individual saved server icon button in the left rail.',
    category: 'shell',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatRoomChannelsPanel',
    label: 'Channels Panel',
    description: 'The room-side panel showing text and voice channels.',
    category: 'room',
    container: 'roomLayout',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'roomPanelHeader',
    label: 'Room Panel Header',
    description: 'The header at the top of the room side panel with server or member context.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'roomTextChannelsSection',
    label: 'Text Channels Section',
    description: 'The side-panel section that groups text channels.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'roomTextChannelItem',
    label: 'Text Channel Item',
    description: 'An individual text channel row in the room side panel.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'roomVoiceChannelsSection',
    label: 'Voice Channels Section',
    description: 'The side-panel section that groups voice channels.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'roomVoiceChannelItem',
    label: 'Voice Channel Item',
    description: 'An individual voice channel row in the room side panel.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'roomVoiceUserItem',
    label: 'Voice User Item',
    description: 'A user row nested under a voice channel.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatRoomMainPanel',
    label: 'Chat Panel',
    description: 'The main room panel that hosts chat messages and the voice workspace overlay.',
    category: 'room',
    container: 'roomLayout',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatSurface',
    label: 'Chat Surface',
    description: 'The message area surface shared by room chat views.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatMessageList',
    label: 'Message List',
    description: 'The scrollable list that contains message bubbles, date separators, and load-more states.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatDateSeparator',
    label: 'Date Separator',
    description: 'The horizontal date divider inserted between groups of chat messages.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatNewMessagesBar',
    label: 'New Messages Bar',
    description: 'The sticky prompt for jumping to unread messages.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatMessageBubble',
    label: 'Message Bubble',
    description: 'The main row for an individual room or direct-message chat message.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatMessageAvatar',
    label: 'Message Avatar',
    description: 'The sender avatar hit target inside each message row.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatMessageContent',
    label: 'Message Content',
    description: 'The text and rich content column inside each chat message.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatAttachmentCard',
    label: 'Attachment Card',
    description: 'Cards that display attachment transfer, preview, request, and download states.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatReactionPill',
    label: 'Reaction Pill',
    description: 'A compact emoji reaction button under a message.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatMessageActions',
    label: 'Message Actions',
    description: 'The hover toolbar for reacting, replying, editing, and deleting a message.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatComposerBar',
    label: 'Composer Bar',
    description: 'The pinned area that holds reply state, typing indicator, markdown tools, and the message input.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatComposerReplyBar',
    label: 'Composer Reply Bar',
    description: 'The reply preview shown above the message composer.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatComposerToolbar',
    label: 'Composer Toolbar',
    description: 'The inline markdown formatting toolbar above the composer input.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatComposerInput',
    label: 'Composer Input',
    description: 'The textarea region where chat messages are written.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatComposerSendButton',
    label: 'Send Button',
    description: 'The send action button inside the message composer.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'chatGifPickerSurface',
    label: 'GIF Picker Surface',
    description: 'The floating GIF picker container opened from the chat composer.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatRoomMembersPanel',
    label: 'Members Panel',
    description: 'The right-hand room panel showing online and offline members.',
    category: 'room',
    container: 'roomLayout',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'dmConversationsPanel',
    label: 'DM Conversations Panel',
    description: 'The direct-message sidebar showing private chat conversations.',
    category: 'room',
    container: 'dmLayout',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'dmConversationsHeader',
    label: 'DM Conversations Header',
    description: 'The header above the direct-message conversations list.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'dmConversationList',
    label: 'DM Conversation List',
    description: 'The scrollable list of direct-message conversations.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'dmConversationItem',
    label: 'DM Conversation Item',
    description: 'An individual direct-message conversation row.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'dmVoiceControlsArea',
    label: 'DM Voice Controls Area',
    description: 'The voice controls slot at the bottom of the direct-message sidebar.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'dmChatPanel',
    label: 'DM Chat Panel',
    description: 'The main direct-message panel that hosts private chat messages.',
    category: 'room',
    container: 'dmLayout',
    layoutEditable: true,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'dmChatSurface',
    label: 'DM Chat Surface',
    description: 'The direct-message chat surface containing the DM header, messages, and composer.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'dmChatHeader',
    label: 'DM Chat Header',
    description: 'The header above a direct-message conversation.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'dmMessageRegion',
    label: 'DM Message Region',
    description: 'The absolute region that holds direct-message history and status markers.',
    category: 'room',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'chatRoomEmptyState',
    label: 'Room Empty State',
    description: 'The empty-state panel displayed when no room or no text channels are available.',
    category: 'state',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: true,
    supportsIcon: true
  },
  {
    key: 'voiceWorkspace',
    label: 'Voice Workspace',
    description: 'The stream-focused overlay and mini-window used when voice workspace is open.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'voiceControlsPanel',
    label: 'Voice Controls Panel',
    description: 'The voice connection card embedded in sidebars and direct-message views.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'voiceControlsUserRow',
    label: 'Voice Controls User Row',
    description: 'The current-user row inside the voice controls panel.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'voiceControlsButtons',
    label: 'Voice Controls Buttons',
    description: 'The mute, deafen, camera, screen-share, and disconnect button group.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'floatingVoiceControls',
    label: 'Floating Voice Controls',
    description: 'The compact floating voice controls shown when the active voice server is off-screen.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'settingsModalSurface',
    label: 'Settings Modal Surface',
    description: 'The main settings modal frame.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'settingsModalNav',
    label: 'Settings Navigation',
    description: 'The left navigation column inside Settings.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'settingsModalHeader',
    label: 'Settings Header',
    description: 'The title and close-button row at the top of Settings content.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'settingsModalContent',
    label: 'Settings Content',
    description: 'The scrollable settings page content area.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'contextMenuSurface',
    label: 'Context Menu Surface',
    description: 'The floating context menu panel used throughout the app.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'confirmDialogSurface',
    label: 'Confirm Dialog Surface',
    description: 'The shared confirmation dialog frame.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'profileCardSurface',
    label: 'Profile Card Surface',
    description: 'The user profile popover card.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'profileCardBanner',
    label: 'Profile Card Banner',
    description: 'The decorative banner strip at the top of a profile card.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'profileCardBody',
    label: 'Profile Card Body',
    description: 'The main text and status content inside a profile card.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: false
  },
  {
    key: 'screenShareSourcePicker',
    label: 'Screen Share Source Picker',
    description: 'The dialog for choosing a screen or window to share.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: true,
    supportsLink: false,
    supportsIcon: true
  },
  {
    key: 'screenShareSourceCard',
    label: 'Screen Share Source Card',
    description: 'An individual screen or window option in the source picker.',
    category: 'overlay',
    layoutEditable: false,
    pickerVisible: true,
    supportsTextOverride: false,
    supportsLink: false,
    supportsIcon: true
  }
];

export function findThemeRegistryEntry(key: string): ThemeRegistryEntry | null {
  return THEME_REGISTRY.find((entry) => entry.key === key) ?? null;
}

export function findThemeLayoutContainer(key: string): ThemeLayoutContainerDefinition | null {
  return THEME_LAYOUT_CONTAINERS.find((container) => container.key === key) ?? null;
}

export function getLayoutEditableThemeKeys(): string[] {
  return THEME_REGISTRY.filter((entry) => entry.layoutEditable).map((entry) => entry.key);
}

export function getPickerVisibleThemeKeys(): string[] {
  return THEME_REGISTRY.filter((entry) => entry.pickerVisible).map((entry) => entry.key);
}
