import { getWindow } from "ssr-window"; import type { IFormCfg } from "../../../components/form/config/types"; import { getCfg } from "../../../utils/getCfg"; import { defaultCfg, selectors } from "../constants/defaultCfg"; type TFormElement = HTMLFormElement & Partial<{ handler: IFormCfg["handler"]; }>; interface IFormExtendedCfg extends IFormCfg { form: TFormElement; id: string; delay: number; } /** * Получает конфигурацию формы * @private * @returns {IFormExtendedCfg} */ const _getFormExtendedCfg = (form: TFormElement): IFormExtendedCfg => { const { id, handler } = form; const cfg = getCfg(form, selectors.form, defaultCfg); if (form.hasAttribute("method")) { const nativeMethod = form.getAttribute("method"); if (nativeMethod !== cfg.method) { cfg.method = nativeMethod as IFormCfg["method"]; } } if (!cfg.url) { cfg.url = (form.hasAttribute("action")) ? form.getAttribute("action") : getWindow().location.origin + getWindow().location.pathname; } return { delay: 0, ...cfg, form, id, handler, }; }; export type { IFormExtendedCfg, }; export { _getFormExtendedCfg, };