import { createStore } from './store';

export type ITextAskState = {
  inputText: string;
};

export type TextAskStoreValue = Record<string, ITextAskState>;

const initialTextAskStoreValue: TextAskStoreValue = {};

export const textAskWidgetStore = createStore(initialTextAskStoreValue);

export type IUpdateTextAskInputTextAction = {
  widgetId: string;
  inputText: string;
};

export const textAskWidgetStoreActions = {
  updateTextAskInputTextAction({
    widgetId,
    inputText,
  }: IUpdateTextAskInputTextAction) {
    textAskWidgetStore.set({
      ...textAskWidgetStore.get(),
      [widgetId]: {
        inputText,
      },
    });
  },
};
