var e=function(exports){function t(e){"@babel/helpers - typeof";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}function n(e,n){if(t(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(t(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}function r(e){var r=n(e,`string`);return t(r)==`symbol`?r:r+``}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}return exports.defineProperty=i,exports}({});import{ButtonWithLoading as t,Button_default as n,C as r,CircularProgress_default as i,ErrorModal$1 as a,Grid_default as o,L as s,MenuItem_default as c,MesfModal as l,PageTitle as u,Paper_default as d,TextField_default as f,__toESM as p,axiosInstance as m,createSlice as h,createStyles as g,format as _,getError$1 as v,init_redux_toolkit_esm as y,isEmpty_default as b,jsx as x,jsxs as S,makeStyles_default as C,n as w,require_build as T,require_react as E}from"./index-BlKb1bsp.js";y();const D={message:``,response:``,error:null,isResponseLoading:!1},O=h({name:`broker`,initialState:D,reducers:{setMessage(e,t){e.message=t.payload},setResponse(e,t){e.response=t.payload},setIsResponseLoading(e,t){e.isResponseLoading=t.payload},setError(e,t){e.error=t.payload}}}),{setMessage:k,setResponse:A,setIsResponseLoading:j,setError:M}=O.actions;var N=p(E()),P=p(T());const F=(0,N.createContext)({state:O.getInitialState(),actions:O.actions}),I=()=>(0,N.useContext)(F),L=({children:e})=>{let[t,n]=(0,P.useComplexState)({initialState:O.getInitialState(),reducers:O.caseReducers});return x(F.Provider,{value:{state:t,actions:n},children:e})};function R({onCopy:e}){let[t,r]=(0,N.useState)(_(new Date,`yyyy-MM-dd HH:mm:ss`)),[i,a]=(0,N.useState)(`CAS1`),[s,l]=(0,N.useState)(`08`),[u,d]=(0,N.useState)(`333123`),[p,m]=(0,N.useState)(`StopperRodOpen`),[h,g]=(0,N.useState)(`2023123`),[v,y]=(0,N.useState)(`4`),b=()=>{navigator.clipboard.writeText(w),e(w)},C;try{C=_(new Date(t),`yyMMddHHmmss`)}catch{C=``}let w=`<LadleTrackMessage>
    <Header>
      <Sender>Level2</Sender>
      <Receiver>REFBroker</Receiver>
      <TimeSent>${C}</TimeSent>
      <Location>${i}</Location>
      <ComponentName>${s}</ComponentName>
      <HeatNo>${u}</HeatNo>
      <Event>${p}</Event>
      <EventTime>${C}</EventTime>
    </Header>
    <Data>
      <Name>SequenceName</Name>
      <Value>${h}</Value>
      <Time>${C}</Time>
      <Comment></Comment>
      <Originator>Level2</Originator>
    </Data>
    <Data>
      <Name>TundishCarNumber</Name>
      <Value>${v}</Value>
      <Time>${C}</Time>
      <Comment></Comment>
      <Originator>Level2</Originator>
    </Data>
  </LadleTrackMessage>`;return S(o,{container:!0,spacing:2,children:[S(o,{item:!0,container:!0,xs:12,md:6,children:[x(o,{item:!0,xs:12,md:6,children:x(f,{label:`Time Sent`,type:`datetime-local`,value:t,onChange:e=>r(e.target.value),fullWidth:!0})}),x(o,{item:!0,xs:12,md:6,children:S(f,{label:`Location`,select:!0,value:i,onChange:e=>a(e.target.value),fullWidth:!0,children:[x(c,{value:`CAS1`,children:`CAS1`}),x(c,{value:`CAS2`,children:`CAS2`})]})}),x(o,{item:!0,xs:12,md:6,children:x(f,{label:`Component Name`,select:!0,value:s,onChange:e=>l(e.target.value),fullWidth:!0,children:[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`].map(e=>x(c,{value:e,children:e},e))})}),x(o,{item:!0,xs:12,md:6,children:x(f,{label:`Heat No`,value:u,onChange:e=>d(e.target.value),fullWidth:!0})}),x(o,{item:!0,xs:12,md:6,children:S(f,{label:`Event`,select:!0,value:p,onChange:e=>m(e.target.value),fullWidth:!0,children:[x(c,{value:`StopperRodOpen`,children:`StopperRodOpen`}),x(c,{value:`StopperRodClose`,children:`StopperRodClose`})]})}),x(o,{item:!0,xs:12,md:6,children:x(f,{label:`Sequence Name`,value:h,onChange:e=>g(e.target.value),fullWidth:!0})}),x(o,{item:!0,xs:12,md:6,children:x(f,{label:`Tundish Car Number`,value:v,onChange:e=>y(e.target.value),fullWidth:!0})})]}),S(o,{item:!0,container:!0,xs:12,md:6,children:[x(o,{item:!0,xs:12,children:x(f,{multiline:!0,minRows:20,value:w,fullWidth:!0,InputProps:{readOnly:!0}})}),x(o,{item:!0,xs:12,children:x(n,{variant:`contained`,color:`primary`,onClick:b,children:`Copy to Clipboard`})})]})]})}var z=R,B=class{constructor(){e.defineProperty(this,`axios`,void 0),this.axios=m,this.submitMessage=this.submitMessage.bind(this)}async submitMessage(e){try{let t=await this.axios.post(`Broker/message`,{message:e});return t.data.success?{ok:!0,data:t.data.result}:{ok:!1,message:t.data.result||v(t.data)}}catch(e){return{ok:!1,message:v(e)}}}};const{submitMessage:V}=new B,H=C(e=>g({errorTextfield:{"& .MuiOutlinedInput-root.Mui-disabled .MuiOutlinedInput-notchedOutline":{borderColor:`red`},"& .MuiInputBase-root.Mui-disabled":{color:`black`},"& .MuiFormLabel-root":{color:`red`}},successTextField:{"& .MuiOutlinedInput-root.Mui-disabled .MuiOutlinedInput-notchedOutline":{borderColor:`green`},"& .MuiInputBase-root.Mui-disabled":{color:`rgba(0, 0, 0, 0.87)`},"& .MuiFormLabel-root":{color:`green`}}})),U=e=>{let[c,p]=(0,N.useState)(``),[m,h]=(0,N.useState)(``),[g,_]=(0,N.useState)(!1),[v,y]=(0,N.useState)(!1),{state:{message:C,response:T},actions:E}=I(),D=H(),O=e=>{p(``);let t=e.target.value;E.setMessage(t)},k=async()=>{y(!0);try{let e=await V(C);e.ok?(h(D.successTextField),w(e.data.result,{icon:x(s,{})})):(h(D.errorTextfield),w(`An error was found!`,{icon:x(r,{})})),E.setResponse(e.data||e.message)}catch(e){console.log(e)}y(!1)},A=b(C);return S(d,{style:{padding:`16px`},children:[x(u,{title:`Broker`}),S(o,{container:!0,spacing:1,children:[S(o,{xs:12,item:!0,children:[x(n,{onClick:()=>_(!0),children:`Open Message Generator`}),x(l,{maxWidth:`md`,handleClose:()=>_(!1),open:g,children:x(l.Content,{children:x(d,{children:x(z,{onCopy:e=>{E.setMessage(e),_(!1)}})})})})]}),S(o,{xs:12,item:!0,container:!0,spacing:1,children:[x(o,{item:!0,xs:6,children:x(f,{multiline:!0,size:`small`,variant:`outlined`,fullWidth:!0,minRows:15,onChange:O,value:C,label:`XML Message`})}),S(o,{item:!0,xs:6,style:{position:`relative`},children:[x(f,{multiline:!0,size:`small`,variant:`outlined`,disabled:!0,className:v?``:m,fullWidth:!0,minRows:26,value:T,label:`Response text`}),v&&x(`div`,{style:{position:`absolute`,top:`50%`,right:`50%`,transform:`translate(-50%,-50%)`},children:x(i,{})})]})]}),x(o,{item:!0,xs:12,children:x(t,{isLoading:v,onClick:k,fullWidth:!0,variant:`contained`,color:`primary`,children:`Send`})})]}),x(a,{error:c,onHide:()=>p(``)})]})},W=()=>x(L,{children:x(U,{})});export{W as BrokerPage};
//# sourceMappingURL=broker-D_qXlf99.js.map