import App from "./App";

import uviewPlus from "uview-plus";
import { createPinia } from "pinia";
import { messages } from "./locale/index";
import vEllipsis from './directives/v-ellipsis'
import { createI18n } from "vue-i18n";

export const i18n = createI18n({
  legacy: true,
  allowComposition: true,
  locale: uni.getStorageSync("lang") || "cn",
  messages,
});
const pinia = createPinia();

const originalT = i18n.global.t;
i18n.global.t = function (key, param1, param2) {
  const result = originalT.call(this, key, param1, param2);
  if (param1 === undefined && param2 === undefined) {
    return result;
  }
  let values = param1;
  if (
    typeof param1 === "object" &&
    !Array.isArray(param1) &&
    Array.isArray(param2)
  ) {
    values = param1;
  } else if (Array.isArray(param1)) {
    values = param1;
  } else if (typeof param1 === "object" && param1 !== null) {
    values = param1;
  } else if (param1 !== undefined) {
    values = [param1];
  }
  return interpolateTemplate(result, values);
};
// #ifdef VUE3
import { createSSRApp } from "vue";
export function createApp() {
  const app = createSSRApp(App);
  app.directive('ellipsis', vEllipsis)
  app.use(uviewPlus);
  app.use(pinia);
  app.use(i18n);
  return {
    app,
  };
}
// #endif
