import{r as e,h as t}from"./p-083180bf.js";import"./p-f8a09b0f.js";import{k as r,f as i,n as o}from"./p-a7fc1e02.js";import{d as s,J as a,w as l,$ as n,i as u}from"./p-d0993bb9.js";import{c as d}from"./p-c1086930.js";import{g as m}from"./p-9ec99ced.js";import"./p-cef45012.js";import"./p-c813ec64.js";import{P as c}from"./p-8962e023.js";import{i as f}from"./p-0d83907e.js";const v=s.gql`
  query {
    viewer {
      ... on User {
        id
        accountId
        firstName
        lastName
        email
        countryCode
      }
    }
  }
`,h=s.gql`
  mutation (
    $id: String!
    $accountId: String!
    $firstName: String!
    $lastName: String!
  ) {
    upsertUser(
      userInput: {
        id: $id
        accountId: $accountId
        firstName: $firstName
        lastName: $lastName
      }
    ) {
      firstName
      lastName
    }
  }
`,p={country:"",email:"",firstName:"",lastName:"",errors:{},error:""},b=class{constructor(t){e(this,t),this.ignored=!0,this.firstnametext="First Name",this.lastnametext="Last Name",this.emailtext="Email",this.countrytext="Country",this.editProfileHeader="Edit your profile",this.editProfileSubHeader="Personal Information",this.submitChangeButtonText="Submit Changes",this.hideCountry=!1,this.networkRequestMessage="An error occurred while loading this page. Please refresh the page.",this.fieldEmptyText="Field is required",this.formErrorText="Please correct the errors below to update your profile.",this.submissionSuccessText="Your profile has been successfully updated.",o(this)}disconnectedCallback(){}render(){const e=u()?function(e){return d({states:{success:!1,loading:!1,submitDisabled:!1,showCountry:!e.hideCountry,user:{id:"01",accountId:"111100000",firstName:"Joe",lastName:"Smith",email:"jsmith@gmail.com",countryCode:"CA"},text:{firstnametext:e.firstnametext,lastnametext:e.lastnametext,emailtext:e.emailtext,countrytext:e.countrytext,editProfileHeader:e.editProfileHeader,editProfileSubHeader:e.editProfileSubHeader,submitChangeButtonText:e.submitChangeButtonText,submissionSuccessText:e.submissionSuccessText,fieldEmptyText:e.fieldEmptyText},formState:{country:"Canada",firstName:"Joe",lastName:"Smith",errors:null,error:""}},callbacks:{onSubmit:e=>console.log(e),onChange:e=>console.log(e)}},e.demoData||{},{arrayMerge:(e,t)=>t})}(m(this)):function(e){const t=a(),[o,s]=r(!1),[u,d]=r(void 0),[m,c]=r(p),b=l(v,{},!(null==t?void 0:t.jwt)),[N,g]=n(h);return i((()=>{(null==g?void 0:g.loading)||((null==g?void 0:g.errors)?c((e=>{var t,r,i;return{...e,error:null===(i=null===(r=null===(t=null==g?void 0:g.errors)||void 0===t?void 0:t.response)||void 0===r?void 0:r.errors)||void 0===i?void 0:i[0].message}})):(d((e=>{var t;return{...e,...null===(t=null==g?void 0:g.data)||void 0===t?void 0:t.upsertUser}})),(null==g?void 0:g.data)&&s(!0)))}),[null==g?void 0:g.loading]),i((()=>{var e,t;d((e=>{var t;return{...e,...null===(t=null==b?void 0:b.data)||void 0===t?void 0:t.viewer}})),c({...p,...null===(e=b.data)||void 0===e?void 0:e.viewer,...null===(t=g.data)||void 0===t?void 0:t.upsertUser})}),[null==b?void 0:b.data]),i((()=>{var t,r;(null===(t=null==g?void 0:g.errors)||void 0===t?void 0:t.message)&&c({...null===(r=b.data)||void 0===r?void 0:r.viewer,error:e.networkRequestMessage})}),[null==g?void 0:g.errors]),{states:{success:o,loading:(null==b?void 0:b.loading)||g.loading,submitDisabled:!1,showCountry:!e.hideCountry,formState:m,user:u,text:{firstnametext:e.firstnametext,lastnametext:e.lastnametext,countrytext:e.countrytext,emailtext:e.emailtext,editProfileHeader:e.editProfileHeader,editProfileSubHeader:e.editProfileSubHeader,submitChangeButtonText:e.submitChangeButtonText}},callbacks:{onSubmit:()=>{if(s(!1),m.firstName&&m.lastName)return N({id:null==t?void 0:t.id,accountId:null==t?void 0:t.accountId,firstName:m.firstName,lastName:m.lastName}),void c((e=>({...e,errors:{},error:""})));const r={};m.firstName||(r.firstName={message:e.fieldEmptyText}),m.lastName||(r.lastName={message:e.fieldEmptyText}),f(r)||c((t=>({...t,error:e.formErrorText}))),c((e=>({...e,errors:r})))},onChange:e=>{const{name:t,value:r}=e.target;c((e=>({...e,[t]:r})))}}}}(m(this));return t(c,Object.assign({},e))}};export{b as sqm_portal_profile}