import { Meta, StoryObj } from "@storybook/nextjs-vite";
import { TrialChoiceTemplate } from "./TrialChoiceTemplate";
import { fn } from "storybook/test";
import { buildTrialChoiceDefaults } from "@/lib/admin/builder/state/defaults/trialChoice";
import type { TrialChoiceScreenDefinition, FunnelDefinition } from "@/lib/funnel/types";

// Используем дефолтные значения из builder, чтобы сторибук совпадал с админкой
const defaultScreen = buildTrialChoiceDefaults(
  "trial-choice-story"
) as TrialChoiceScreenDefinition;

// Minimal funnel mock for storybook (used to derive placement id in hooks)
const mockFunnel: FunnelDefinition = {
  meta: { id: "storybook-funnel" },
  defaultTexts: { nextButton: "Next", continueButton: "Continue" },
  screens: [],
};

/** TrialChoiceTemplate — базовый экран с выбором пробного периода */
const meta: Meta<typeof TrialChoiceTemplate> = {
  title: "Funnel Templates/TrialChoiceTemplate",
  component: TrialChoiceTemplate,
  tags: ["autodocs"],
  parameters: {
    layout: "fullscreen",
  },
  args: {
    funnel: mockFunnel,
    screen: defaultScreen,
    onContinue: fn(),
    canGoBack: true,
    onBack: fn(),
    defaultTexts: {
      continueButton: "Next",
    },
    answers: {},
  },
  argTypes: {
    screen: { control: { type: "object" } },
    screenProgress: { control: { type: "object" } },
    onContinue: { action: "continue" },
    onBack: { action: "back" },
  },
};

export default meta;
type Story = StoryObj<typeof meta>;

/** Базовый Trial Choice экран */
export const Default: Story = {};
