import { request } from 'utils/fetch';
import { api } from 'constants/config';

export async function templateImport(
  { userCategoryId, templateConfig, componentsConfig, panelsConfig, screenConfig, filtersConfig },
  signal
) {
  const body = {
    userCategoryId,
    templateConfig: JSON.parse(templateConfig),
    componentsConfig: JSON.parse(componentsConfig),
    panelsConfig: JSON.parse(panelsConfig),
    screenConfig: JSON.parse(screenConfig),
    filtersConfig: JSON.parse(filtersConfig)
  };
  return request(api.importTemplate, undefined, undefined, JSON.stringify(body), { signal });
}
