import { ReactNode } from "react";
import { AbstractWidgetSettings } from "../../components/ConfigurationPage/widgetsettings/AbstractWidgetSettings";
import { TextProperty } from "../../components/ConfigurationPage/widgetproperties/TextProperty";
import { BooleanProperty } from "../../components/ConfigurationPage/widgetproperties/BooleanProperty";
import { NumberProperty } from "../../components/ConfigurationPage/widgetproperties/NumberProperty";
import { ColorProperty, ColorPropertyTarget } from "../../components/ConfigurationPage/widgetproperties/ColorProperty";
import { BorderProperty } from "../../components/ConfigurationPage/widgetproperties/BorderProperty";
import { PaddingProperty } from "../../components/ConfigurationPage/widgetproperties/PaddingProperty";
import { RoundingProperty } from "../../components/ConfigurationPage/widgetproperties/RoundingProperty";
import { BoxShadowProperty } from "../../components/ConfigurationPage/widgetproperties/BoxShadowProperty";
import { BackgroundImageProperty } from "../../components/ConfigurationPage/widgetproperties/BackgroundImageProperty";
import { AnimatedFontProperty } from "../../components/ConfigurationPage/widgetproperties/AnimatedFontProperty";
// Import your widget for the live preview (demo):
import { MyWidget } from "./MyWidget";
import { Flex } from "antd";
import { CloseOverlayButton } from "../../components/Overlay/Overlay";
import classes from "../../components/ConfigurationPage/widgetsettings/AbstractWidgetSettings.module.css";
export class MyWidgetSettings extends AbstractWidgetSettings {
constructor() {
super({ sections: [] });
// ── General settings tab ──────────────────────────────────
this.addSection({
key: "general",
title: "Общие", // shown as tab title (can be i18n key)
properties: [
new TextProperty({
name: "title",
value: "Привет, мир!", // default value
displayName: "Заголовок",
help: "Текст, который будет отображаться",
}),
new BooleanProperty({
name: "showIcon",
value: true,
displayName: "Показывать иконку",
}),
new NumberProperty({
name: "count",
value: 42,
displayName: "Количество",
addon: "шт", // unit suffix shown next to input
}),
new AnimatedFontProperty({
name: "titleFont",
// value is optional — its own defaults will be used
}),
],
});
// ── Style settings tab ────────────────────────────────────
this.addSection({
key: "style",
title: "Стиль",
properties: [
new ColorProperty({
name: "backgroundColor",
displayName: "Цвет фона",
target: ColorPropertyTarget.BACKGROUND,
value: {
angle: 0,
colors: [{ color: "rgba(0, 0, 0, 0)" }],
gradient: false,
repeating: false,
gradientType: 0,
},
}),
new BackgroundImageProperty({ name: "backgroundImage" }),
new BorderProperty({ name: "border" }),
new PaddingProperty({ name: "padding" }),
new RoundingProperty({ name: "rounding" }),
new BoxShadowProperty({ name: "shadow" }),
],
});
}
// ── Typed property getters ──────────────────────────────────
// These expose settings to the widget component with proper types.
public get title(): string {
return this.get("title")?.value ?? "Привет, мир!";
}
public get showIcon(): boolean {
return (this.get("showIcon") as BooleanProperty)?.value ?? true;
}
public get count(): number {
return (this.get("count") as NumberProperty)?.value ?? 42;
}
public get titleFontProperty(): AnimatedFontProperty {
return (this.get("titleFont") as AnimatedFontProperty)
?? new AnimatedFontProperty({ name: "titleFont" });
}
public get backgroundColorProperty(): ColorProperty {
return (this.get("backgroundColor") as ColorProperty)
?? new ColorProperty({ name: "backgroundColor", displayName: "Цвет фона", target: ColorPropertyTarget.BACKGROUND });
}
public get borderProperty(): BorderProperty {
return (this.get("border") as BorderProperty)
?? new BorderProperty({ name: "border" });
}
public get paddingProperty(): PaddingProperty {
return (this.get("padding") as PaddingProperty)
?? new PaddingProperty({ name: "padding" });
}
public get roundingProperty(): RoundingProperty {
return (this.get("rounding") as RoundingProperty)
?? new RoundingProperty({ name: "rounding" });
}
public get shadowProperty(): BoxShadowProperty {
return (this.get("shadow") as BoxShadowProperty)
?? new BoxShadowProperty({ name: "shadow" });
}
public get backgroundImageProperty(): BackgroundImageProperty {
return (this.get("backgroundImage") as BackgroundImageProperty)
?? new BackgroundImageProperty({ name: "backgroundImage" });
}
// ── Help panel (shown when user clicks ?) ───────────────────
public help(): ReactNode {
return (
<>
<Flex align="center" justify="space-between">
<h3 className={`${classes.helptitle}`}>Мой виджет</h3>
<CloseOverlayButton />
</Flex>
<div className={`${classes.helpdescription}`}>
Описание вашего виджета — что он делает, для чего нужен.
</div>
<h3 className={`${classes.helptitle}`}>Как подключить</h3>
<div className={`${classes.helpdescription}`}>
<ul>
<li>В меню виджета скопировать ссылку.</li>
<li>Вставить как Browser Source в OBS.</li>
</ul>
</div>
</>
);
}
// ── Live preview (shown in settings panel) ──────────────────
public hasDemo(): boolean {
return true;
}
public demo(): ReactNode {
return <MyWidget settings={this} />;
}
}