import { initPageEditor } from '../components/app-page-editor.js';
import { readPageConfig } from '../core/app-page-config.js';

const pageConfig = readPageConfig('page-editor') || {};
const selector = String(pageConfig.selector || '[data-page-editor]').trim() || '[data-page-editor]';
const forms = Array.from(document.querySelectorAll(selector)).filter(
  (item) => item instanceof HTMLFormElement
);

const apis = forms.map((form) => initPageEditor(form, pageConfig)).filter(
  (api) => api && typeof api.destroy === 'function'
);

export const destroyPageEditorEntry = () => {
  apis.forEach((api) => {
    api.destroy();
  });
};
