import {
  ColorFieldDefaults,
  EmbedFieldDefaults,
  ImageFieldDefaults,
  VideoFieldDefaults,
} from '@hubspot/cms-components/fields';
// @ts-expect-error -- types not flowing through properly
import { VideoCrmObject, HubSpotVideoParams } from '@hubspot/video-player-core';

type ColorFieldValue = typeof ColorFieldDefaults;

export type ContentFieldsProps = {
  videoTypeLabel?: string;
  videoTypeName?: string;
  hsVideoLabel?: string;
  hsVideoName?: string;
  hsVideoDefault?: typeof VideoFieldDefaults;
  embedVideoLabel?: string;
  embedVideoName?: string;
  embedVideoDefault?: typeof EmbedFieldDefaults;
  oembedThumbnailLabel?: string;
  oembedThumbnailName?: string;
  oembedThumbnailDefault?: typeof ImageFieldDefaults;
};

export type StyleFieldsProps = {
  playButtonColorLabel?: string;
  playButtonColorName?: string;
  playButtonColorDefault?: ColorFieldValue;
};

export type VideoProps = {
  videoType: 'embed' | 'hubspot_video';
  video?: VideoCrmObject;
  hubspotVideoParams?: HubSpotVideoParams;
  embedVideoParams?: EmbedVideoParams;
  oembedThumbnail?: { src: string; alt?: string };
  playButtonColor?: ColorFieldValue;
};

export type HSVideoIslandProps = {
  video?: VideoCrmObject;
  hubspotVideoParams: HubSpotVideoParams;
  playButtonColor?: ColorFieldValue;
};

export type EmbedVideoIslandProps = {
  embedVideoParams: EmbedVideoParams;
  oembedThumbnail?: { src: string; alt?: string };
  playButtonColor?: ColorFieldValue;
};

export type EmbedVideoParams = {
  source_type: 'oembed' | 'html';
  supported_oembed_types: string[];
  // fields for 'oembed' source_type
  size_type?: 'auto' | 'auto_custom_max' | 'auto_full_width' | 'exact';
  width?: number;
  height?: number;
  max_width?: number;
  max_height?: number;
  oembed_url?: string;
  oembed_response?: {
    type: string;
    html: string;
    width: string;
    height: string;
    title?: string;
    provider_name?: string;
    provider_url?: string;
  };
  // fields for 'html' source_type
  embed_html?: string;
};

declare global {
  interface Window {
    hsVars?: {
      page_id?: number;
    };
    _hsq?: [string, unknown];
    __hsUserToken?: string;
  }
}

export type PrivacyConsent = {
  categories?: Record<string, boolean>;
  allowed?: boolean;
};

export type PageMeta = {
  pageUrl: string;
  pageTitle: string;
  pageId: number;
  _hsenc?: string;
};
