import {
  BannerWidgetParams,
  ButtonWidgetFixedParams,
  ButtonWidgetParams,
  ContainerWidgetParams,
  PopupWidgetParams,
  SideWidgetParams,
} from "@frontend/squzanswerer";

export function createContainerWidgetScriptText(params: ContainerWidgetParams, widgetUrl: string) {
  return `<div id="${params.selector.slice(1)}"></div>
<script type="module">
import { ContainerWidget } from "${widgetUrl}";

new ContainerWidget(${JSON.stringify(params, null, 4)});
</script>`;
}

export function createButtonWidgetScriptText(params: ButtonWidgetParams | ButtonWidgetFixedParams, widgetUrl: string) {
  const widgetClassName = "fixedSide" in params ? "ButtonWidgetFixed" : "ButtonWidget";

  return `${"selector" in params ? `<div id="${params.selector.slice(1)}"></div>\n` : ""}<script type="module">
import { ${widgetClassName} } from "${widgetUrl}";

new ${widgetClassName}(${JSON.stringify(params, null, 4)});
</script>`;
}

export function createPopupWidgetScriptText(params: PopupWidgetParams, widgetUrl: string) {
  return `<script type="module">
import { PopupWidget } from "${widgetUrl}";

new PopupWidget(${JSON.stringify(params, null, 4)});
</script>`;
}

export function createSideWidgetScriptText(params: SideWidgetParams, widgetUrl: string) {
  return `<script type="module">
import { SideWidget } from "${widgetUrl}";

new SideWidget(${JSON.stringify(params, null, 4)});
</script>`;
}

export function createBannerWidgetScriptText(params: BannerWidgetParams, widgetUrl: string) {
  return `<script type="module">
import { BannerWidget } from "${widgetUrl}";

new BannerWidget(${JSON.stringify(params, null, 4)});
</script>`;
}
