import{ah as W,q as H,j as e,r as o,ai as w,aj as T,ak as L,a as u,S as a,H as l,_ as g,B,U as $,P as R,M as E,C as D,y as F,E as P,D as A,al as q,z as O,L as G,V}from"./index-09tpYl64.js";const j={message:"",response:"",error:null,isResponseLoading:!1},S=W({name:"broker",initialState:j,reducers:{setMessage(r,s){r.message=s.payload},setResponse(r,s){r.response=s.payload},setIsResponseLoading(r,s){r.isResponseLoading=s.payload},setError(r,s){r.error=s.payload}}}),{setMessage:Z,setResponse:ee,setIsResponseLoading:te,setError:ae}=S.actions,I=o.createContext({state:S.getInitialState(),actions:S.actions}),z=()=>o.useContext(I),U=({children:r})=>{const[s,n]=H.useComplexState({initialState:S.getInitialState(),reducers:S.caseReducers});return e(I.Provider,{value:{state:s,actions:n},children:r})};class X{axios;constructor(){this.axios=w,this.submitMessage=this.submitMessage.bind(this)}async submitMessage(s){try{const n=await this.axios.post("Broker/message",{message:s});return n.data.success?{ok:!0,data:n.data.result}:{ok:!1,message:n.data.result||T(n.data)}}catch(n){return{ok:!1,message:T(n)}}}}const{submitMessage:_}=new X;function J({onCopy:r}){const[s,n]=o.useState(L(new Date,"yyyy-MM-dd HH:mm:ss")),[C,v]=o.useState("CAS1"),[x,p]=o.useState("08"),[c,b]=o.useState("333123"),[m,f]=o.useState("StopperRodOpen"),[h,M]=o.useState("2023123"),[y,N]=o.useState("4"),i=()=>{navigator.clipboard.writeText(k),r(k)};let d;try{d=L(new Date(s),"yyMMddHHmmss")}catch{d=""}const k=`<LadleTrackMessage>
    <Header>
      <Sender>Level2</Sender>
      <Receiver>REFBroker</Receiver>
      <TimeSent>${d}</TimeSent>
      <Location>${C}</Location>
      <ComponentName>${x}</ComponentName>
      <HeatNo>${c}</HeatNo>
      <Event>${m}</Event>
      <EventTime>${d}</EventTime>
    </Header>
    <Data>
      <Name>SequenceName</Name>
      <Value>${h}</Value>
      <Time>${d}</Time>
      <Comment></Comment>
      <Originator>Level2</Originator>
    </Data>
    <Data>
      <Name>TundishCarNumber</Name>
      <Value>${y}</Value>
      <Time>${d}</Time>
      <Comment></Comment>
      <Originator>Level2</Originator>
    </Data>
  </LadleTrackMessage>`;return u(a,{container:!0,spacing:2,children:[u(a,{item:!0,container:!0,xs:12,md:6,children:[e(a,{item:!0,xs:12,md:6,children:e(l,{label:"Time Sent",type:"datetime-local",value:s,onChange:t=>n(t.target.value),fullWidth:!0})}),e(a,{item:!0,xs:12,md:6,children:u(l,{label:"Location",select:!0,value:C,onChange:t=>v(t.target.value),fullWidth:!0,children:[e(g,{value:"CAS1",children:"CAS1"}),e(g,{value:"CAS2",children:"CAS2"})]})}),e(a,{item:!0,xs:12,md:6,children:e(l,{label:"Component Name",select:!0,value:x,onChange:t=>p(t.target.value),fullWidth:!0,children:["01","02","03","04","05","06","07","08","09"].map(t=>e(g,{value:t,children:t},t))})}),e(a,{item:!0,xs:12,md:6,children:e(l,{label:"Heat No",value:c,onChange:t=>b(t.target.value),fullWidth:!0})}),e(a,{item:!0,xs:12,md:6,children:u(l,{label:"Event",select:!0,value:m,onChange:t=>f(t.target.value),fullWidth:!0,children:[e(g,{value:"StopperRodOpen",children:"StopperRodOpen"}),e(g,{value:"StopperRodClose",children:"StopperRodClose"})]})}),e(a,{item:!0,xs:12,md:6,children:e(l,{label:"Sequence Name",value:h,onChange:t=>M(t.target.value),fullWidth:!0})}),e(a,{item:!0,xs:12,md:6,children:e(l,{label:"Tundish Car Number",value:y,onChange:t=>N(t.target.value),fullWidth:!0})})]}),u(a,{item:!0,container:!0,xs:12,md:6,children:[e(a,{item:!0,xs:12,children:e(l,{multiline:!0,rows:20,value:k,fullWidth:!0,InputProps:{readOnly:!0}})}),e(a,{item:!0,xs:12,children:e(B,{variant:"contained",color:"primary",onClick:i,children:"Copy to Clipboard"})})]})]})}const K=A(r=>q({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"}}})),Q=r=>{const[s,n]=o.useState(""),[C,v]=o.useState(""),[x,p]=o.useState(!1),[c,b]=o.useState(!1),{state:{message:m,response:f},actions:h}=z(),M=K(),y=i=>{n("");const d=i.target.value;h.setMessage(d)},N=async()=>{b(!0);try{const i=await _(m);i.ok?(v(M.successTextField),O(i.data.result,{icon:e(G,{})})):(v(M.errorTextfield),O("An error was found!",{icon:e(V,{})})),h.setResponse(i.data||i.message)}catch(i){console.log(i)}b(!1)};return $(m),u(R,{style:{padding:"16px"},children:[u(a,{container:!0,spacing:1,children:[u(a,{xs:12,item:!0,children:[e(B,{onClick:()=>p(!0),children:"Open Message Generator"}),e(E,{maxWidth:"md",handleClose:()=>p(!1),open:x,children:e(E.Content,{children:e(R,{children:e(J,{onCopy:i=>{h.setMessage(i),p(!1)}})})})})]}),u(a,{xs:12,item:!0,container:!0,spacing:1,children:[e(a,{item:!0,xs:6,children:e(l,{multiline:!0,size:"small",variant:"outlined",fullWidth:!0,minRows:15,onChange:y,value:m,label:"XML Message"})}),u(a,{item:!0,xs:6,style:{position:"relative"},children:[e(l,{multiline:!0,size:"small",variant:"outlined",disabled:!0,className:c?"":C,fullWidth:!0,minRows:26,value:f,label:"Response text"}),c&&e("div",{style:{position:"absolute",top:"50%",right:"50%",transform:"translate(-50%,-50%)"},children:e(D,{})})]})]}),e(a,{item:!0,xs:12,children:e(F,{isLoading:c,onClick:N,fullWidth:!0,variant:"contained",color:"primary",children:"Send"})})]}),e(P,{error:s,onHide:()=>n("")})]})},se=()=>e(U,{children:e(Q,{})});export{se as BrokerPage};
//# sourceMappingURL=index-Cf91ZOxd.js.map
