import{r as t,B as e,h as i}from"./p-f8363b1b.js";import{t as d}from"./p-07a452ee.js";import{D as a,K as n}from"./p-b930c1c5.js";import{i as o}from"./p-98d7792a.js";import{e as r,s}from"./p-30821067.js";import{g as l}from"./p-bb4f18d8.js";import{A as u}from"./p-93fd19f5.js";import"./p-f13bd533.js";import"./p-bf71b10e.js";import"./p-af2a8ecd.js";import"./p-baa91ba7.js";import"./p-de14d315.js";import"./p-80de33dc.js";const m=l`
  mutation addProject($data: ProjectInput!) {
    addProject(data: $data) {
      id
    }
  }
`,p=l`
  mutation deleteProject($id: String!) {
    deleteProject(id: $id) {
      id
    }
  }
`,c=l`
  mutation editProject($id: String!, $data: ProjectInput!) {
    editProject(id: $id, data: $data) {
      id
    }
  }
`,h=l`
  query findProject($id: String!) {
    project(id: $id) {
      id
    }
  }
`,f=l`
  query listProjects($data: ListQueryInput!) {
    projects(data: $data) {
      id
    }
  }
`,$=l`
  mutation addTemplate($data: TemplateInput!) {
    addTemplate(data: $data) {
      id
    }
  }
`,v=l`
  mutation deleteTemplate($id: String!) {
    deleteTemplate(id: $id) {
      id
    }
  }
`,j=l`
  mutation editTemplate($id: String!, $data: TemplateInput!) {
    editTemplate(id: $id, data: $data) {
      id
    }
  }
`,T=l`
  query findTemplate($id: String!) {
    template(id: $id) {
      id
      editor {
        time
        version
        blocks {
          data
          type
        }
      }
      tags
      description
      routes
      name
      subject
      type
      html
      head
      text
      amp
      header {
        id
        subject
        description
        html
      }
      footer {
        id
        subject
        description
        html
      }
      frame {
        id
        subject
        description
        html
        head
        header {
          id
          subject
          description
          html
        }
        footer {
          id
          subject
          description
          html
        }
      }
      attachments {
        cid
        filename
        content
        path
        encoding
        raw
        href
        httpHeaders
        contentDisposition
        contentType
        headers
      }
      partial
      sampleData
      createdAt
    }
  }
`,g=l`
  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) {
        id
        subject
        description
        html
      }
      footer @include(if: $withHtml) {
        id
        subject
        description
        html
      }
      frame @include(if: $withHtml) {
        id
        subject
        description
        html
      }
      tags
      partial
      createdAt
    }
  }
`,y=l`
  mutation addToken($data: TokenInput!) {
    addToken(data: $data) {
      id
    }
  }
`,P=l`
  mutation deleteToken($id: String!) {
    deleteToken(id: $id) {
      id
    }
  }
`,k=l`
  mutation editToken($id: String!, $data: TokenInput!) {
    editToken(id: $id, data: $data) {
      id
    }
  }
`,b=l`
  query findToken($id: String!) {
    token(id: $id) {
      id
    }
  }
`,w=l`
  query listTokens($data: ListQueryInput!) {
    tokens(data: $data) {
      id
    }
  }
`,U=l`
  mutation addUser($data: UserInput!) {
    addUser(data: $data) {
      id
    }
  }
`,q=l`
  mutation deleteUser($id: String!) {
    deleteUser(id: $id) {
      id
    }
  }
`,S=l`
  mutation editUser($id: String!, $data: UserInput!) {
    editUser(id: $id, data: $data) {
      id
    }
  }
`,I=l`
  query findUser($id: String!) {
    user(id: $id) {
      id
    }
  }
`,x=l`
  query listUsers($data: ListQueryInput!) {
    users(data: $data) {
      id
    }
  }
`,H=l`
  mutation generatePdf($data: GeneratePdfInput!) {
    generatePdf(data: $data) {
      id
      url
    }
  }
`,L=l`
  mutation sendTemplateEmail($data: SendTemplateEmailInput!) {
    sendTemplateEmail(data: $data) {
      id
    }
  }
`,E=t=>t();function K(t,e=E){return{addProject:(i,d)=>e((e=>t.request(m,i,{...d,...e})),"addProject","mutation"),deleteProject:(i,d)=>e((e=>t.request(p,i,{...d,...e})),"deleteProject","mutation"),editProject:(i,d)=>e((e=>t.request(c,i,{...d,...e})),"editProject","mutation"),findProject:(i,d)=>e((e=>t.request(h,i,{...d,...e})),"findProject","query"),listProjects:(i,d)=>e((e=>t.request(f,i,{...d,...e})),"listProjects","query"),addTemplate:(i,d)=>e((e=>t.request($,i,{...d,...e})),"addTemplate","mutation"),deleteTemplate:(i,d)=>e((e=>t.request(v,i,{...d,...e})),"deleteTemplate","mutation"),editTemplate:(i,d)=>e((e=>t.request(j,i,{...d,...e})),"editTemplate","mutation"),findTemplate:(i,d)=>e((e=>t.request(T,i,{...d,...e})),"findTemplate","query"),listTemplates:(i,d)=>e((e=>t.request(g,i,{...d,...e})),"listTemplates","query"),addToken:(i,d)=>e((e=>t.request(y,i,{...d,...e})),"addToken","mutation"),deleteToken:(i,d)=>e((e=>t.request(P,i,{...d,...e})),"deleteToken","mutation"),editToken:(i,d)=>e((e=>t.request(k,i,{...d,...e})),"editToken","mutation"),findToken:(i,d)=>e((e=>t.request(b,i,{...d,...e})),"findToken","query"),listTokens:(i,d)=>e((e=>t.request(w,i,{...d,...e})),"listTokens","query"),addUser:(i,d)=>e((e=>t.request(U,i,{...d,...e})),"addUser","mutation"),deleteUser:(i,d)=>e((e=>t.request(q,i,{...d,...e})),"deleteUser","mutation"),editUser:(i,d)=>e((e=>t.request(S,i,{...d,...e})),"editUser","mutation"),findUser:(i,d)=>e((e=>t.request(I,i,{...d,...e})),"findUser","query"),listUsers:(i,d)=>e((e=>t.request(x,i,{...d,...e})),"listUsers","query"),generatePdf:(i,d)=>e((e=>t.request(H,i,{...d,...e})),"generatePdf","mutation"),sendTemplateEmail:(i,d)=>e((e=>t.request(L,i,{...d,...e})),"sendTemplateEmail","mutation")}}const A=class{constructor(i){var d,l,m,p;t(this,i),this.app=o(r("firebase",{})),this.auth=new u({app:this.app,config:{tokenLocalStorageKey:"mx:token",authLocalStorageKey:"mx:session",emulate:!!(null===(d=null==s?void 0:s.config)||void 0===d?void 0:d.emulate)}}),this.db=new a({app:this.app,emulate:!!(null===(l=null==s?void 0:s.config)||void 0===l?void 0:l.emulate)}),this.fireenjin=new n({getSdk:K,debug:null==e?void 0:e.isDev,connections:[{name:"default",type:"graphql",url:(null===(p=null===(m=null==s?void 0:s.config)||void 0===m?void 0:m.graphql)||void 0===p?void 0:p.url)||"https://fireenjin.com/graphql"}]}),this.componentProps={app:this.app,auth:this.auth,db:this.db,fireenjin:this.fireenjin}}async onUpdate(){const t=await navigator.serviceWorker.getRegistration();t&&t.waiting&&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;["addTemplate","editTemplate","deleteTemplate"].includes(null===(e=null==t?void 0:t.detail)||void 0===e?void 0:e.endpoint)&&this.getTemplates()}async onToast(t){var e;if(!(null===(e=null==t?void 0:t.detail)||void 0===e?void 0:e.toast))return;const i=await d.create(t.detail.toast);await i.present()}async onRouteChange(t){var e,i,d;const a=(null==t?void 0:t.target)||document.querySelector("ion-router");let n=!0;try{(null===(e=null==s?void 0:s.session)||void 0===e?void 0:e.uid)&&["/"].indexOf(null===(i=null==t?void 0:t.detail)||void 0===i?void 0:i.to)>=0&&(n=!1,a.push("/templates")),!(null===(d=null==s?void 0:s.session)||void 0===d?void 0:d.uid)&&["/templates"].indexOf(t.detail.to)>=0&&(n=!1,a.push("/"))}catch(t){console.log(t.message)}n&&document.body.classList.add("is-loaded")}onKeydown(t){"s"===t.key&&(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)&&t.preventDefault()}async getTemplates(){const t=await this.db.list("templates",[]);return s.templates=t||[],s.partials=s.templates.filter((t=>!!(null==t?void 0:t.partial))),t}componentWillLoad(){(null==e?void 0:e.isBrowser)&&this.auth.onAuthChanged((async t=>{var e;if(t&&t.uid){if(s.session=t,["/","/login"].includes(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.pathname)&&setTimeout((()=>{const t=document.querySelector("ion-router");(null==t?void 0:t.push)&&t.push("/templates")}),200),this.getTemplates(),"string"!=typeof(null==t?void 0:t.uid))return;this.db.watchDocument("users",t.uid,(async e=>{var i;(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.trade)?s.profile=e.data:this.db.add("users",{id:null==t?void 0:t.uid,trade:"dev",email:(null==t?void 0:t.email)||null},null==t?void 0:t.uid)}))}}))}render(){return[i("ion-router",{useHash:!1},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{A as fireenjin_mx_router}