import { Assets, Ticker } from 'pixi.js';
import ReelsMachine from 'src/slotMachines/ReelsMachine';
import { argTypes, getDefaultArgs } from 'src/stories/utils/argTypes';
import { createScreenInputMap } from 'src/stories/utils/createScreenInputMap';
import MachineContainer from 'src/stories/utils/MachineContainer';
import { centerView } from 'src/stories/utils/resize';
import { SlotMachineConfig } from 'src/types/SlotMachineConfig';
import { Meta, PixiStory, StoryFn } from '@pixi/storybook-renderer';
import IdleSystem from '../systems/IdleSystem';
import MockSystem from "src/systems/MockSystem";

const args = {
    maxAnimatedSymbols: 5
};

const meta: Meta<typeof IdleSystem> = {
    title: 'Systems/IdleSystem', // Путь для отображения в Storybook
    tags: ['autodocs'], // Включает автоматическую генерацию документации
    parameters: {
        docs: {
            story: {
                height: 600
            },
            description: {
                component: 'Manages idle animations for random symbols in the slot machine. When the system is idle, it triggers an idle animation on a randomly chosen symbol.'
            },
        }
    },
    argTypes: argTypes(args),
    args: getDefaultArgs(args),
};

export default meta;

export const IdleSystemStory: StoryFn<typeof args> = (_params, context) => new PixiStory({
    context, init: async (view) =>
    {
        Assets.reset();
        await Assets.init({
            manifest: 'area69/manifest.json',
        });
        await Assets.loadBundle('configs');
        await Assets.loadBundle('symbols');
        const config: SlotMachineConfig = Assets.get('slot_machine_config');
        const machine = new ReelsMachine(config);
        const container = new MachineContainer(machine);

        view.addChild(container);
        context.machine = machine;
        machine.inputs.initMap = createScreenInputMap(config);
        machine.systems.idle.setSettings(_params);
        machine.systems.blockExitState = new MockSystem(machine)
        machine.inputs.blockExitState = true;
        setTimeout(() => {
            machine.inputs.blockExitState = false;
        }, 250);
        centerView(view);
    },
    resize: centerView,
    update: () =>
    {
        context.machine && context.machine.update(Ticker.shared.deltaMS);
        context.machine.systems.idle.setSettings(_params);
    }
});
