import{G as e,J as t,K as n,Q as r,U as i,W as a,X as o,_t as s,bt as c,ht as l,it as u,mt as d,pt as f,q as p,tt as m,vt as h,wt as g,xt as _}from"./lz-string-CMojKG3P.js";import{_ as v}from"./dist-rbQIUfXp.js";import{t as y}from"./chunk-pbuEa-1d-DjY3kn7w.js";var b={id:`powerhouse/document-editor`,name:`Document Editor`,extension:`.phdm`,description:``,author:{name:`Powerhouse`,website:`https://powerhouse.inc`},specifications:[{version:1,changeLog:[],state:{global:{schema:`type DocumentEditorState {
  name: String!
  documentTypes: [DocumentTypeItem!]!
  status: StatusType!
}

type DocumentTypeItem {
  id: OID!
  documentType: String!
}

enum StatusType {
  DRAFT
  CONFIRMED
}`,initialValue:`{
  "name": "",
  "documentTypes": [],
  "status": "DRAFT"
}`,examples:[]},local:{schema:``,initialValue:``,examples:[]}},modules:[{id:`73f6d103-47cb-4074-a736-a3eaf5d079bf`,name:`base_operations`,description:``,operations:[{id:`50a16f00-d25a-4c97-9632-4ce3b951a402`,name:`SET_EDITOR_NAME`,description:``,schema:`input SetEditorNameInput {
  name: String!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`acee4272-f29e-4a19-aaf9-bae2cb6652ab`,name:`ADD_DOCUMENT_TYPE`,description:``,schema:`input AddDocumentTypeInput {
  id: OID!
  documentType: String!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`6c549776-0fc3-4632-a6c7-8721fa6ee41c`,name:`REMOVE_DOCUMENT_TYPE`,description:``,schema:`input RemoveDocumentTypeInput {
  id: OID!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`e9aa7f08-553b-452f-a494-126ace6b15f7`,name:`SET_EDITOR_STATUS`,description:``,schema:`input SetEditorStatusInput {
  status: StatusType!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`}]}]}]},x=e=>e!=null;d().refine(e=>x(e));var S=f([`CONFIRMED`,`DRAFT`]);function C(){return c({documentType:_(),id:_()})}function w(){return c({__typename:h(`DocumentEditorState`).optional(),documentTypes:l(s(()=>T())),name:_(),status:S})}function T(){return c({__typename:h(`DocumentTypeItem`).optional(),documentType:_(),id:_()})}function E(){return c({id:_()})}function D(){return c({name:_()})}function O(){return c({status:S})}var k=y({addDocumentType:()=>j,removeDocumentType:()=>M,setEditorName:()=>A,setEditorStatus:()=>N}),A=e=>o(`SET_EDITOR_NAME`,{...e},void 0,D,`global`),j=e=>o(`ADD_DOCUMENT_TYPE`,{...e},void 0,C,`global`),M=e=>o(`REMOVE_DOCUMENT_TYPE`,{...e},void 0,E,`global`),N=e=>o(`SET_EDITOR_STATUS`,{...e},void 0,O,`global`),P=`powerhouse/document-editor`,F=i.extend({documentType:h(P)}),I=a.extend({global:w()}),L=c({header:F,state:I,initialState:I});function R(e){return I.safeParse(e).success}function z(e){I.parse(e)}function B(e){return L.safeParse(e).success}function V(e){L.parse(e)}var H={setEditorNameOperation(e,t,n){let r=t.input.name.trim();if(r===``)throw Error(`Editor name cannot be empty`);e.name=r},addDocumentTypeOperation(e,t,n){if(e.documentTypes.find(e=>e.id===t.input.id))throw Error(`Document type with id "${t.input.id}" already exists`);e.documentTypes.push({id:t.input.id,documentType:t.input.documentType})},removeDocumentTypeOperation(e,t,n){e.documentTypes=e.documentTypes.filter(e=>e.id!==t.input.id)},setEditorStatusOperation(e,t,n){e.status=t.input.status}},U=r((e,t,n)=>{if(u(t))return e;switch(t.type){case`SET_EDITOR_NAME`:D().parse(t.input),H.setEditorNameOperation(e[t.scope],t,n);break;case`ADD_DOCUMENT_TYPE`:C().parse(t.input),H.addDocumentTypeOperation(e[t.scope],t,n);break;case`REMOVE_DOCUMENT_TYPE`:E().parse(t.input),H.removeDocumentTypeOperation(e[t.scope],t,n);break;case`SET_EDITOR_STATUS`:O().parse(t.input),H.setEditorStatusOperation(e[t.scope],t,n);break;default:return e}}),W={name:``,documentTypes:[],status:`DRAFT`},G={},K={fileExtension:`.phdm`,createState(e){return{...m(),global:{...W,...e?.global},local:{...G,...e?.local}}},createDocument(e){let t=n(K.createState,e);return t.header.documentType=P,t.header.id=g(),t},saveToFileHandle(e,n){return t(e,n)},loadFromInput(e){return p(e,U)},isStateOfType(e){return R(e)},assertIsStateOfType(e){return z(e)},isDocumentOfType(e){return B(e)},assertIsDocumentOfType(e){return V(e)}},q=y({});function J(){let[e,t]=v();return V(e),[e,t]}var Y={...e,...k},X={...K,...q};export{M as a,J as c,U as i,X as l,j as n,A as o,b as r,N as s,Y as t};
//# sourceMappingURL=document-editor-CHM7Pu4m-CAewHPNC.js.map