<% if (importCoreJs) { -%>import 'core-js';<% } %>
import { createElement, Fragment } from 'react';
import { runClientApp, getAppConfig } from '<%- iceRuntimePath %>';
import { commons, statics } from './runtimeModules';
import * as app from '@/app';
<% if (enableRoutes) { -%>
import routes from './routes';
<% } -%>
<%- runtimeOptions.imports %>
<% if(dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
const getRouterBasename = () => {
  const appConfig = getAppConfig(app);
  return appConfig?.router?.basename ?? <%- basename %> ?? '';
}
// Add react fragment for split chunks of app.
// Otherwise chunk of route component will pack @ice/jsx-runtime and depend on framework bundle.
const App = <></>;

const render = (customOptions = {}) => {
  const appProps = {
    app,
    runtimeModules: {
      commons,
      statics,
    },
    <% if (enableRoutes) { %>routes,<% } %>
    basename: getRouterBasename(),
    hydrate: <%- hydrate %>,
    memoryRouter: <%- memoryRouter || false %>,
    <% if(dataLoaderImport.imports) {-%>dataLoaderFetcher,<% } -%>
    ...customOptions,
    <% if (runtimeOptions.exports) { -%>
    runtimeOptions: {
      <%- runtimeOptions.exports %>
      ...(customOptions.runtimeOptions || {}),
    },
    <% } -%>
  };
  return runClientApp(appProps);
};

<%- entryCode %>
