import{r as t,B as e,h as i}from"./p-03169580.js";import{t as d}from"./p-c5cf028c.js";import{g as n,D as o,F as a}from"./p-db7f957b.js";import{i as r}from"./p-a1c2b210.js";import{e as s,s as l}from"./p-5fc6058c.js";import{A as u}from"./p-c6693dde.js";import"./p-4cb16df5.js";import"./p-7cbdb4ea.js";import"./p-6c0cf874.js";import"./p-2d180048.js";import"./p-b466518d.js";import"./p-7716c8ae.js";import"./p-bd8b186e.js";import"./p-59c95c5f.js";const p=n`
  mutation addProject($data: ProjectInput!) {
    addProject(data: $data) {
      id
    }
  }
`;const m=n`
  mutation deleteProject($id: String!) {
    deleteProject(id: $id) {
      id
    }
  }
`;const c=n`
  mutation editProject($id: String!, $data: ProjectInput!) {
    editProject(id: $id, data: $data) {
      id
    }
  }
`;const v=n`
  query findProject($id: String!) {
    project(id: $id) {
      id
    }
  }
`;const f=n`
  query listProjects($data: ListQueryInput!) {
    projects(data: $data) {
      id
    }
  }
`;const $=n`
  mutation addTemplate($data: TemplateInput!) {
    addTemplate(data: $data) {
      id
    }
  }
`;const h=n`
  mutation deleteTemplate($id: String!) {
    deleteTemplate(id: $id) {
      id
    }
  }
`;const T=n`
  mutation editTemplate($id: String!, $data: TemplateInput!) {
    editTemplate(id: $id, data: $data) {
      id
    }
  }
`;const j=n`
  query findTemplate($id: String!) {
    template(id: $id) {
      id
      editor {
        time
        version
        blocks {
          data
          type
        }
      }
      tags
      description
      routes
      name
      subject
      type
      html
      head
      header
      footer
      text
      amp
      attachments {
        cid
        filename
        content
        path
        encoding
        raw
        href
        httpHeaders
        contentDisposition
        contentType
        headers
      }
      partial
      prerender
      sampleData
      createdAt
    }
  }
`;const g=n`
  query listTemplates($data: TemplateListInput!, $withHtml: Boolean!) {
    templates(data: $data) {
      id
      name
      routes
      description
      subject
      type
      text
      html @include(if: $withHtml)
      head @include(if: $withHtml)
      header @include(if: $withHtml)
      footer @include(if: $withHtml)
      tags
      partial
      createdAt
    }
  }
`;const y=n`
  mutation addToken($data: TokenInput!) {
    addToken(data: $data) {
      id
    }
  }
`;const P=n`
  mutation deleteToken($id: String!) {
    deleteToken(id: $id) {
      id
    }
  }
`;const k=n`
  mutation editToken($id: String!, $data: TokenInput!) {
    editToken(id: $id, data: $data) {
      id
    }
  }
`;const w=n`
  query findToken($id: String!) {
    token(id: $id) {
      id
    }
  }
`;const U=n`
  query listTokens($data: ListQueryInput!) {
    tokens(data: $data) {
      id
    }
  }
`;const q=n`
  mutation addUser($data: UserInput!) {
    addUser(data: $data) {
      id
    }
  }
`;const b=n`
  mutation deleteUser($id: String!) {
    deleteUser(id: $id) {
      id
    }
  }
`;const S=n`
  mutation editUser($id: String!, $data: UserInput!) {
    editUser(id: $id, data: $data) {
      id
    }
  }
`;const I=n`
  query findUser($id: String!) {
    user(id: $id) {
      id
    }
  }
`;const x=n`
  query listUsers($data: ListQueryInput!) {
    users(data: $data) {
      id
    }
  }
`;const H=n`
  mutation generatePdf($data: GeneratePdfInput!) {
    generatePdf(data: $data) {
      id
      url
    }
  }
`;const L=(t,e,i)=>t();function A(t,e=L){return{addProject(i,d){return e((e=>t.request(p,i,{...d,...e})),"addProject","mutation")},deleteProject(i,d){return e((e=>t.request(m,i,{...d,...e})),"deleteProject","mutation")},editProject(i,d){return e((e=>t.request(c,i,{...d,...e})),"editProject","mutation")},findProject(i,d){return e((e=>t.request(v,i,{...d,...e})),"findProject","query")},listProjects(i,d){return e((e=>t.request(f,i,{...d,...e})),"listProjects","query")},addTemplate(i,d){return e((e=>t.request($,i,{...d,...e})),"addTemplate","mutation")},deleteTemplate(i,d){return e((e=>t.request(h,i,{...d,...e})),"deleteTemplate","mutation")},editTemplate(i,d){return e((e=>t.request(T,i,{...d,...e})),"editTemplate","mutation")},findTemplate(i,d){return e((e=>t.request(j,i,{...d,...e})),"findTemplate","query")},listTemplates(i,d){return e((e=>t.request(g,i,{...d,...e})),"listTemplates","query")},addToken(i,d){return e((e=>t.request(y,i,{...d,...e})),"addToken","mutation")},deleteToken(i,d){return e((e=>t.request(P,i,{...d,...e})),"deleteToken","mutation")},editToken(i,d){return e((e=>t.request(k,i,{...d,...e})),"editToken","mutation")},findToken(i,d){return e((e=>t.request(w,i,{...d,...e})),"findToken","query")},listTokens(i,d){return e((e=>t.request(U,i,{...d,...e})),"listTokens","query")},addUser(i,d){return e((e=>t.request(q,i,{...d,...e})),"addUser","mutation")},deleteUser(i,d){return e((e=>t.request(b,i,{...d,...e})),"deleteUser","mutation")},editUser(i,d){return e((e=>t.request(S,i,{...d,...e})),"editUser","mutation")},findUser(i,d){return e((e=>t.request(I,i,{...d,...e})),"findUser","query")},listUsers(i,d){return e((e=>t.request(x,i,{...d,...e})),"listUsers","query")},generatePdf(i,d){return e((e=>t.request(H,i,{...d,...e})),"generatePdf","mutation")}}}let D=class{constructor(i){t(this,i);var d,n,p,m;this.app=r(s("firebase",{}));this.auth=new u({app:this.app,config:{tokenLocalStorageKey:"mx:token",authLocalStorageKey:"mx:session",emulate:!!((d=l===null||l===void 0?void 0:l.config)===null||d===void 0?void 0:d.emulate)}});this.db=new o({app:this.app,emulate:!!((n=l===null||l===void 0?void 0:l.config)===null||n===void 0?void 0:n.emulate)});this.fireenjin=new a({getSdk:A,debug:e===null||e===void 0?void 0:e.isDev,connections:[{name:"default",type:"graphql",url:(e===null||e===void 0?void 0:e.isDev)?"https://fireenjin.mx/graphql":(m=(p=l===null||l===void 0?void 0:l.config)===null||p===void 0?void 0:p.graphql)===null||m===void 0?void 0:m.url}]});this.componentProps={app:this.app,auth:this.auth,db:this.db,fireenjin:this.fireenjin}}async onUpdate(){const t=await navigator.serviceWorker.getRegistration();if(!t||!t.waiting){return}this.onToast({detail:{toast:{message:"New version available",buttons:[{side:"end",text:"Reload",handler:()=>{t.waiting.postMessage("skipWaiting");window.location.reload()}}]}}})}async onSuccess(t){var e;if(["addTemplate","editTemplate","deleteTemplate"].includes((e=t===null||t===void 0?void 0:t.detail)===null||e===void 0?void 0:e.endpoint)){this.getTemplates()}}async onToast(t){var e;if(!((e=t===null||t===void 0?void 0:t.detail)===null||e===void 0?void 0:e.toast))return;const i=await d.create(t.detail.toast);await i.present()}async onRouteChange(t){var e,i,d;const n=(t===null||t===void 0?void 0:t.target)||document.querySelector("ion-router");let o=true;try{if(((e=l===null||l===void 0?void 0:l.session)===null||e===void 0?void 0:e.uid)&&["/"].indexOf((i=t===null||t===void 0?void 0:t.detail)===null||i===void 0?void 0:i.to)>=0){o=false;n.push("/templates")}if(!((d=l===null||l===void 0?void 0:l.session)===null||d===void 0?void 0:d.uid)&&["/templates"].indexOf(t.detail.to)>=0){o=false;n.push("/")}}catch(t){console.log(t.message)}if(o){document.body.classList.add("is-loaded")}}onKeydown(t){if(t.key==="s"&&(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)){t.preventDefault()}}async getTemplates(){const t=await this.db.list("templates",[]);l.templates=t||[];l.partials=l.templates.filter((t=>!!(t===null||t===void 0?void 0:t.partial)));return t}componentWillLoad(){if(e===null||e===void 0?void 0:e.isBrowser){this.auth.onAuthChanged((async t=>{var e;if(t&&t.uid){l.session=t;if(["/","/login"].includes((e=window===null||window===void 0?void 0:window.location)===null||e===void 0?void 0:e.pathname)){setTimeout((()=>{const t=document.querySelector("ion-router");if(t===null||t===void 0?void 0:t.push)t.push("/templates")}),200)}this.getTemplates();if(typeof(t===null||t===void 0?void 0:t.uid)!=="string")return;this.db.watchDocument("users",t.uid,(async e=>{var i;if(!((i=e===null||e===void 0?void 0:e.data)===null||i===void 0?void 0:i.trade)){this.db.add("users",{id:t===null||t===void 0?void 0:t.uid,trade:"dev",email:(t===null||t===void 0?void 0:t.email)||null},t===null||t===void 0?void 0:t.uid)}else{l.profile=e.data}}))}}))}}render(){return[i("ion-router",{useHash:false},i("ion-route",{url:"/",component:"fireenjin-mx-page-login",componentProps:this.componentProps}),i("ion-route",{url:"/login",component:"fireenjin-mx-page-login",componentProps:this.componentProps}),i("ion-route",{url:"/templates",component:"fireenjin-mx-page-home",componentProps:this.componentProps}),i("ion-route",{component:"fireenjin-mx-page-template",componentProps:this.componentProps,url:"/templates/:templateId"}),i("ion-route",{url:"/test",component:"fireenjin-mx-page-test",componentProps:this.componentProps}))]}};export{D as fireenjin_mx_router};
//# sourceMappingURL=p-43a69426.entry.js.map