PageSourceSearch

https://every-demo.vercel.app/_next/static/chunks/pages/v2/documen…/templates/[templateId]-6613da5498879a97.js

js every-demo.vercel.app collected 2026-10-03 06:59:20 UTC 31,623 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5010],{36120:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/v2/documents/templates/[templateId]",function(){return n(7215)}])},7215:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return ei}});var a=n(52903),r=n(2784),i=n(24432),l=n(33379),o=n(86607),s=n(5632),c=n(56958),d=n(28879),u=n.n(d),f=n(36923),m=n(51015),p=n(368),h=n(40628),v=n(74829),g=n(46933),y=n(54735);let b={type:"p",children:[{text:""}]},x=e=>{var t;let n=e.name.toLowerCase().split(".");return n.length>1&&null!==(t=n.pop())&&void 0!==t?t:""},w=e=>{let t=x(e);return"docx"===t||"pdf"===t||"application/vnd.openxmlformats-officedocument.wordprocessingml.document"===e.type||"application/pdf"===e.type};async function N(e){if(!w(e))throw Error("Unsupported file type — please upload a .docx or .pdf file.");let{getSessionIdToken:t}=await Promise.all([n.e(4055),n.e(6865),n.e(1310)]).then(n.bind(n,71310)),a=await t();if(!a)throw Error("You need to be signed in to import a document.");let r=new FormData;r.append("file",e);let i=await fetch("/api/templates/import-document",{method:"POST",headers:{Authorization:"Bearer ".concat(a)},body:r});if(!i.ok)throw Error(await Z(i));let l=await i.json();if("docx"===l.kind)return{content:await C(l.html),warnings:l.warnings};if("pdf"===l.kind)return{content:function(e){let t=e.map(e=>e.replace(/\s+/g," ").trim()).filter(e=>e.length>0).map(e=>({type:"p",children:[{text:e}]}));return t.length>0?t:[b]}(l.paragraphs),warnings:l.warnings};throw Error("Unexpected response from the import endpoint.")}async function Z(e){try{let t=await e.json();if(null==t?void 0:t.error)return t.error}catch(e){}return e.statusText||"Import failed (".concat(e.status,")")}async function C(e){let t=await n.e(4545).then(n.bind(n,64545)),a=t.createSlateEditor({plugins:(0,y.Th)({requireSignatureBlock:!1}),value:[b]});return function(e){if(!e)return[b];if(!Array.isArray(e))return[e];let t=e.filter(e=>null!==e&&"object"==typeof e&&"type"in e);return t.length>0?t:[b]}(t.deserializeHtml(a,{element:e,collapseWhiteSpace:!0}))}var k=n(18568),A=n(10479),_=n(72835),z=n(44278),B=n(57064),X=n(58636);function S(e){let{active:t,caption:n="Analyzing your document…"}=e,[i,l]=(0,r.useState)("hidden");return((0,r.useEffect)(()=>{if(t){l("entering");return}l(e=>"entering"===e?"exiting":e);let e=setTimeout(()=>l("hidden"),400);return()=>clearTimeout(e)},[t]),"hidden"===i)?null:(0,a.BX)("div",{className:(0,X.cn)("pointer-events-none absolute inset-0 z-10 animate-glow-container-in transition-opacity duration-[350ms] ease-out","exiting"===i&&"opacity-0"),"aria-hidden":!0,children:[(0,a.tZ)("div",{className:"analysis-glow-border animate-glow-spin"}),(0,a.BX)("div",{className:(0,X.cn)("absolute left-1/2 top-16 flex items-center gap-2 whitespace-nowrap rounded-full px-5 py-2.5","bg-white dark:bg-neutral-900","ring-1 ring-[#ff8a00]/30 dark:ring-[#ffd700]/25","shadow-[0_10px_40px_-4px_rgba(199,125,255,0.55)]","animate-glow-caption-in"),children:[(0,a.tZ)(B.Z,{className:"size-4 shrink-0 animate-pulse text-[#ff8a00]"}),(0,a.tZ)("span",{className:"bg-gradient-to-r from-[#ff8a00] via-[#ff5d8f] to-[#c77dff] bg-clip-text text-sm font-semibold text-transparent",children:n})]})]})}var R=n(4639),D=n(14919),E=n(52654),T=n(5254);function P(e){let{open:t,onOpenChange:n,onRun:i}=e,[l,o]=(0,r.useState)("");(0,r.useEffect)(()=>{t||o("")},[t]);let s=l.trim();return(0,a.tZ)(D.aR,{open:t,onOpenChange:n,children:(0,a.BX)(D._T,{children:[(0,a.BX)(D.fY,{children:[(0,a.BX)(D.f$,{className:"flex items-center gap-2",children:[(0,a.tZ)(B.Z,{className:"size-4 text-primary-500"}),"AI Assist"]}),(0,a.tZ)(D.yT,{children:"Tidy up your template's structure, or describe a change in your own words. You'll get a preview of the changes to review before anything is applied."})]}),(0,a.BX)("div",{className:"space-y-2",children:[(0,a.tZ)(T._,{htmlFor:"assist-instruction",className:"text-sm font-medium text-on-surface",children:"Tell the AI what to change"}),(0,a.tZ)(E.g,{id:"assist-instruction",value:l,onChange:e=>o(e.target.value),rows:3,placeholder:"e.g. Make the tone more formal, or add a remote-work clause"}),(0,a.tZ)("p",{className:"text-xs font-normal text-on-surface-tertiary",children:"Unlike structural cleanup, this can rewrite wording — review the result before publishing."})]}),(0,a.BX)(D.xo,{children:[(0,a.tZ)(D.le,{children:"Cancel"}),(0,a.tZ)(m.z,{variant:"outline",disabled:!s,onClick:()=>i("instruction",s),children:"Apply change"}),(0,a.BX)(m.z,{onClick:()=>i("cleanup"),children:[(0,a.tZ)(R.Z,{className:"mr-1.5 size-4"}),"Clean up structure"]})]})]})})}var j=n(67404);function U(e){let{open:t,title:n,summary:r,diff:i,onAccept:l,onDiscard:o}=e;return(0,a.tZ)(j.Vq,{open:t,onOpenChange:e=>!e&&o(),children:(0,a.BX)(j.cZ,{className:"max-w-2xl",children:[(0,a.BX)(j.fK,{children:[(0,a.BX)(j.$N,{className:"flex items-center gap-2",children:[(0,a.tZ)(B.Z,{className:"size-4 text-primary-500"}),n]}),(0,a.tZ)(j.Be,{children:r})]}),(0,a.tZ)("div",{className:"max-h-[50vh] overflow-y-auto whitespace-pre-wrap rounded-md border border-default bg-surface-secondary p-3 font-content text-sm leading-relaxed",children:i.map((e,t)=>(0,a.tZ)("span",{className:(0,X.cn)(e.added&&"rounded-sm bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300",e.removed&&"rounded-sm bg-red-100 text-red-700 line-through dar
1k:bg-red-900/40 dark:text-red-300",!e.added&&!e.removed&&"text-on-surface-secondary"),children:e.value},t))}),(0,a.BX)(j.cN,{children:[(0,a.tZ)(m.z,{variant:"outline",onClick:o,children:"Discard"}),(0,a.tZ)(m.z,{onClick:l,children:"Accept changes"})]})]})})}var I=n(49429);let V={h1:"# ",h2:"## ",h3:"### "};function O(e){return(function e(t,n){let a=[],r="  ".repeat(n);for(let u of t){var i,l,o,s,c,d;if(!u||"object"!=typeof u)continue;let{type:t}=u;if("conditional_block"===t){a.push("".concat(r,"‹shown if ").concat(((d=u.condition)&&"object"==typeof d?d.var?d.var:Array.isArray(d.conditions)?d.conditions.map(e=>null==e?void 0:e.var).filter(Boolean).join(" & "):"":"")||"…","›")),a.push(...e(null!==(i=u.children)&&void 0!==i?i:[],n+1));continue}if("ul"===t||"ol"===t){let e=0;for(let n of null!==(l=u.children)&&void 0!==l?l:[]){if(!n||"li"!==n.type)continue;e+=1;let i="ol"===t?"".concat(e,"."):"•";a.push("".concat(r).concat(i," ").concat(W(null!==(o=n.children)&&void 0!==o?o:[])).trimEnd())}continue}if("li"===t){a.push("".concat(r,"• ").concat(W(null!==(s=u.children)&&void 0!==s?s:[])).trimEnd());continue}if("signature_block"===t){a.push("".concat(r,"— signature block —"));continue}if("hr"===t||"page_break"===t){a.push("".concat(r,"———"));continue}let f=t&&V[t]||("blockquote"===t?"> ":""),m=u.align&&"left"!==u.align?" [".concat(u.align,"]"):"";a.push("".concat(r).concat(f).concat(W(null!==(c=u.children)&&void 0!==c?c:[])).concat(m).trimEnd())}return a})(null!=e?e:[],0).join("\n")}function W(e){return e.map(e=>{var t,n,a;return"string"==typeof(null==e?void 0:e.text)?e.text:(null==e?void 0:e.type)==="template_field"?"[".concat(null!==(n=null!==(t=e.label)&&void 0!==t?t:e.fieldKey)&&void 0!==n?n:"field","]"):(null==e?void 0:e.type)==="suggested_field"?"[".concat(null!==(a=e.label)&&void 0!==a?a:"suggested","]"):Array.isArray(null==e?void 0:e.children)?W(e.children):""}).join("")}var Y=n(375),F=n(32819),$=n(91374),q=n(80625),J=n(94529),L=n(30366),K=n(87919);function M(e){let{editorRef:t,onSave:n,isSaving:i,hasUnsavedChanges:l,onPublish:o,isPublishing:s,onImport:c,onUseDefault:d,hasExistingContent:u,onArchive:f,isArchiving:p,onReset:h,assistInProgress:v}=e,g=(0,r.useRef)(null),y=(0,r.useRef)(null),[b,x]=(0,r.useState)({canUndo:!1,canRedo:!1}),w=()=>{var e,n,a,r;return x({canUndo:null!==(a=null===(e=t.current)||void 0===e?void 0:e.canUndo())&&void 0!==a&&a,canRedo:null!==(r=null===(n=t.current)||void 0===n?void 0:n.canRedo())&&void 0!==r&&r})},N=e=>{var t;let n=null===(t=e.target.files)||void 0===t?void 0:t[0];e.target.value="",n&&c(n)},Z=e=>setTimeout(()=>{var t;return null===(t=e.current)||void 0===t?void 0:t.click()},0);return(0,a.BX)("div",{className:"flex items-center gap-2",children:[(0,a.BX)(K.h_,{onOpenChange:e=>e&&w(),children:[(0,a.tZ)(K.$F,{asChild:!0,children:(0,a.tZ)(m.z,{variant:"ghost",size:"icon","aria-label":"More actions",disabled:v,children:(0,a.tZ)(Y.Z,{className:"size-4"})})}),(0,a.BX)(K.AW,{align:"end",className:"w-56",children:[(0,a.BX)(K.Xi,{disabled:!b.canUndo,onSelect:e=>{var n;e.preventDefault(),null===(n=t.current)||void 0===n||n.undo(),w()},children:[(0,a.tZ)(F.Z,{className:"mr-2 size-4"}),"Undo",(0,a.tZ)(K.KM,{children:"⌘Z"})]}),(0,a.BX)(K.Xi,{disabled:!b.canRedo,onSelect:e=>{var n;e.preventDefault(),null===(n=t.current)||void 0===n||n.redo(),w()},children:[(0,a.tZ)($.Z,{className:"mr-2 size-4"}),"Redo",(0,a.tZ)(K.KM,{children:"⇧⌘Z"})]}),(0,a.BX)(K.Xi,{onSelect:()=>h(),disabled:!l,children:[(0,a.tZ)(q.Z,{className:"mr-2 size-4"}),"Reset"]}),(0,a.tZ)(K.VD,{}),(0,a.BX)(K.Xi,{onSelect:()=>Z(g),children:[(0,a.tZ)(J.Z,{className:"mr-2 size-4"}),"Import from Word"]}),(0,a.BX)(K.Xi,{onSelect:()=>Z(y),children:[(0,a.tZ)(J.Z,{className:"mr-2 size-4"}),"Import from PDF"]}),d&&(0,a.BX)(K.Xi,{onSelect:()=>d(),children:[(0,a.tZ)(B.Z,{className:"mr-2 size-4"}),"Use Every's default"]}),u&&(0,a.tZ)(K.Ju,{className:"pt-1 text-[11px] font-normal font-content leading-snug text-on-surface-tertiary",children:"Importing replaces your current draft."}),(0,a.tZ)(K.VD,{}),(0,a.BX)(K.Xi,{onSelect:()=>f(),disabled:p,children:[(0,a.tZ)(L.Z,{className:"mr-2 size-4"}),p?"Archiving…":"Archive"]})]})]}),(0,a.tZ)(m.z,{variant:"outline",onClick:n,disabled:i||!l||v,children:i?"Saving…":"Save draft"}),(0,a.tZ)(m.z,{onClick:o,disabled:s||i||v,children:s?"Publishing…":"Publish"}),(0,a.tZ)("input",{ref:g,type:"file",accept:".docx",className:"hidden",onChange:N}),(0,a.tZ)("input",{ref:y,type:"file",accept:".pdf,application/pdf",className:"hidden",onChange:N})]})}let Q="Analyzing your document…";function G(e){return e.status?e.isDraft?(0,a.BX)("div",{className:"flex items-center gap-2",children:[(0,a.tZ)(m.z,{variant:"outline",onClick:e.onSave,disabled:e.isSaving||e.assistInProgress||!e.hasUnsavedChanges,children:e.isSaving?"Saving…":"Save Draft"}),(0,a.tZ)(m.z,{onClick:e.onPublish,disabled:e.isPublishing||e.isSaving||e.assistInProgress,children:e.isPublishing?"Publishing…":"Publish"})]}):e.isPublished?(0,a.BX)("div",{className:"flex items-center gap-2",children:[(0,a.tZ)(m.z,{variant:"outline",onClick:e.onArchive,disabled:e.isArchiving,children:e.isArchiving?"Archiv
1ing…":"Archive"}),(0,a.tZ)(m.z,{onClick:e.onCreateDraft,disabled:e.isCreatingDraft,children:e.isCreatingDraft?"Creating draft…":"Edit"})]}):e.isArchived?(0,a.tZ)("div",{className:"flex items-center gap-2",children:(0,a.tZ)(m.z,{onClick:e.onCreateDraft,disabled:e.isCreatingDraft,children:e.isCreatingDraft?"Restoring…":"Unarchive"})}):null:null}function H(e){let{status:t,currentVersion:n,hasUnsavedChanges:r,isSaving:i,lastSaved:l}=e;return(0,a.BX)("div",{className:"flex flex-wrap items-center gap-3 text-xs",children:[t&&(0,a.tZ)(p.C,{variant:(0,z.q)(t),className:"pointer-events-none",children:t}),(null==n?void 0:n.version)!=null&&(0,a.BX)("span",{className:"font-normal font-content text-on-surface-tertiary",children:["Version ",n.version]}),"Draft"===t&&(0,a.tZ)(ee,{hasUnsavedChanges:r,isSaving:i,lastSaved:l}),"Published"===t&&(0,a.tZ)("span",{className:"font-normal font-content text-on-surface-tertiary",children:"Read-only — click Edit to create a new draft version"}),"Archived"===t&&(0,a.tZ)("span",{className:"font-normal font-content text-on-surface-tertiary",children:"Archived — click Unarchive to restore as a new draft"})]})}function ee(e){let{hasUnsavedChanges:t,isSaving:n,lastSaved:r}=e;return n?(0,a.tZ)("span",{className:"font-normal font-content text-on-surface-tertiary",children:"Saving…"}):t?(0,a.tZ)("span",{className:"font-normal font-content text-warning",children:"Unsaved changes"}):r?(0,a.BX)("span",{className:"font-normal font-content text-on-surface-tertiary",children:["Saved at ",u()(r).format("h:mm A")]}):null}function et(e){if(!e)return"Cleaned up your template";let t=[],{headingsPromoted:n,conditionalsWrapped:a,listsRecovered:r,whitespaceFixed:i}=e;return(n>0&&t.push("promoted ".concat(n," ").concat(1===n?"heading":"headings")),a>0&&t.push("wrapped ".concat(a," ").concat(1===a?"section":"sections")),r>0&&t.push("recovered ".concat(r," ").concat(1===r?"list":"lists")),i>0&&t.push("tidied ".concat(i," ").concat(1===i?"spot":"spots")),0===t.length)?"Cleaned up your template":"Cleaned up \xb7 ".concat(t.join(", "))}function en(e){return"instruction"===e?"Couldn't apply that — your template is unchanged":"Couldn't clean up — your template is unchanged"}var ea=()=>{var e,t,n,d,u,m,p,y,b;let x=(0,s.useRouter)(),{templateId:w}=x.query,[Z,C]=(0,r.useState)(null),[z,B]=(0,r.useState)(!1),[X,R]=(0,r.useState)(null),[D,E]=(0,r.useState)(0),[T,j]=(0,r.useState)("hidden"),[V,W]=(0,r.useState)(Q),[Y,F]=(0,r.useState)(!1),[$,q]=(0,r.useState)(null),J=(0,r.useRef)(0),L=(0,r.useRef)(!1),K=(0,r.useRef)(null),ee=(0,r.useRef)(null),ea=(0,r.useRef)(null),er=(0,r.useRef)(!1),ei=(0,r.useRef)(null),{data:el,loading:eo,error:es}=(0,i.aM)(g.ED,{variables:{input:{templateId:w}},skip:!w,fetchPolicy:"cache-and-network"}),ec=null==el?void 0:null===(e=el.V2_GetTemplate)||void 0===e?void 0:e.template,ed=null==ec?void 0:ec.current_version,eu=(0,A.Nk)(null==ec?void 0:ec.seed_variant),ef=null==ec?void 0:ec.status,em="Draft"===ef,ep="Published"===ef,eh="Archived"===ef;(0,r.useEffect)(()=>{var e;if(!(null==ed?void 0:ed.id)||K.current===ed.id)return;K.current=ed.id;let t=null!==(e=ed.content)&&void 0!==e?e:null;C(t),ee.current=null!=t?JSON.stringify(t):null,B(!1),R(null)},[null==ed?void 0:ed.id,null==ed?void 0:ed.content]);let ev=[(0,o.rY)(g.ED)].filter(Boolean),[eg,{loading:ey}]=(0,l.D)(g.Gc,{onCompleted:()=>{null!==ea.current?(ee.current=ea.current,ea.current=null):ee.current=null!=Z?JSON.stringify(Z):null,B(!1),R(new Date),er.current?er.current=!1:c.Am.success("Draft saved")},onError:e=>{er.current=!1,ea.current=null,c.Am.error("Failed to save draft",{description:e.message})},refetchQueries:ev}),eb=(0,r.useCallback)((e,t)=>(er.current=!0,ea.current=JSON.stringify(t),eg({variables:{input:{templateVersionId:e,content:t}}})),[eg]),[ex,{loading:ew}]=(0,l.D)(g.Y$,{refetchQueries:ev,onCompleted:()=>{c.Am.success("Template published")},onError:e=>{c.Am.error("Failed to publish",{description:e.message})}}),[eN,{loading:eZ}]=(0,l.D)(g.E5,{refetchQueries:ev,onCompleted:()=>{c.Am.success("Template archived")},onError:e=>{c.Am.error("Failed to archive",{description:e.message})}}),[eC,{loading:ek}]=(0,l.D)(g.Kh,{refetchQueries:ev,onCompleted:()=>{c.Am.success("New draft created — you can now edit")},onError:e=>{c.Am.error("Failed to create draft",{description:e.message})}}),[eA]=(0,l.D)(g.sR),[e_]=(0,l.D)(g.bx),ez=(0,r.useCallback)(()=>{(null==ed?void 0:ed.id)&&Z&&eg({variables:{input:{templateVersionId:ed.id,c
1ontent:Z}}})},[null==ed?void 0:ed.id,Z,eg]),eB=(0,r.useCallback)(async()=>{w&&(z&&(null==ed?void 0:ed.id)&&Z&&await eg({variables:{input:{templateVersionId:ed.id,content:Z}}}),ex({variables:{input:{templateId:w}}}))},[w,z,null==ed?void 0:ed.id,Z,eg,ex]),eX=(0,r.useCallback)(()=>{w&&eN({variables:{input:{templateId:w}}})},[w,eN]),eS=(0,r.useCallback)(()=>{w&&eC({variables:{input:{templateId:w}}})},[w,eC]),eR=(0,r.useCallback)(e=>{q(null),C(e),E(e=>e+1)},[]),eD=(0,r.useCallback)((e,t)=>{let n=++J.current;W(Q),j("analyzing"),eA({variables:{input:{templateId:w,content:t}}}).then(async t=>{var a,r;let{data:i}=t;if(n!==J.current)return;let l=null==i?void 0:i.V2_AnalyzeImportedDocument,o=null==l?void 0:l.content,s=null!==(a=null==l?void 0:l.matchCount)&&void 0!==a?a:0,d=null!==(r=null==l?void 0:l.suggestionCount)&&void 0!==r?r:0,u=s+d;if(Array.isArray(o)&&u>0){eR(o);try{await eb(e,o)}catch(e){j("hidden");return}j("success"),c.Am.success(function(e,t){let n=1===e?"1 variable":"".concat(e," variables");return 0===t?"Detected ".concat(n):"Detected ".concat(n," \xb7 ").concat(1===t?"1 suggested":"".concat(t," suggested"))}(s,d))}else j("hidden"),c.Am.info("No variables auto-detected — feel free to add them from the + menu")}).catch(()=>{n===J.current&&(j("fallback"),c.Am.warning("Couldn’t analyze for variables — your document is still ready to edit"))})},[w,eb,eA,eR]),eE=(0,r.useCallback)(async()=>{var e;let t=null==ed?void 0:ed.id;if(!t)return;let n=null==ec?void 0:null===(e=ec.payroll_document_type)||void 0===e?void 0:e.name,a=(0,A.Yu)(n,eu);if(0===a.length){c.Am.info("There's no default template for this document type yet");return}eR(a);try{await eb(t,a),c.Am.success("Loaded Every's default template")}catch(e){}},[null==ed?void 0:ed.id,null==ec?void 0:null===(t=ec.payroll_document_type)||void 0===t?void 0:t.name,eu,eb,eR]),eT=(0,r.useCallback)(()=>{var e;let t=ee.current?JSON.parse(ee.current):null!==(e=null==ed?void 0:ed.content)&&void 0!==e?e:null;if(!t)return;let n=ei.current;if(n){let e=n.replaceContent(t);C(e),ee.current=JSON.stringify(e)}else C(t),E(e=>e+1);B(!1),c.Am.success("Reverted to last saved version")},[null==ed?void 0:ed.content]),eP=(0,r.useCallback)(async e=>{if(!L.current){L.current=!0;try{let t;let n=null==ed?void 0:ed.id;if(!n){c.Am.error("Couldn't import — the draft isn't ready yet. Try again in a moment.");return}W(Q),j("analyzing");try{t=await N(e)}catch(e){j("hidden"),c.Am.error("Couldn't parse this document",{description:e instanceof Error?e.message:"Please try a different file."});return}eR(t.content);try{await eb(n,t.content)}catch(e){j("hidden");return}for(let e of t.warnings)c.Am.info(e);eD(n,t.content)}finally{L.current=!1}}},[null==ed?void 0:ed.id,eb,eD,eR]),ej=(0,r.useCallback)(async(e,t)=>{F(!1);let n=null==ed?void 0:ed.id,a=null!=Z?Z:null==ed?void 0:ed.content;if(!n||!a)return;let r=++J.current;W("instruction"===e?"Applying your changes…":"Cleaning up your template…"),j("analyzing");try{let{data:l}=await e_({variables:{input:{templateId:w,content:a,mode:e,instruction:t}}});if(r!==J.current)return;let o=null==l?void 0:l.V2_AssistTemplate,s=null==o?void 0:o.content,d=null==o?void 0:o.changeCount;if((null==o?void 0:o.status)==="cleaned"&&Array.isArray(s)){var i;j("hidden");let t=(0,I.NV)(O(a),O(s)).map(e=>({value:e.value,added:e.added,removed:e.removed}));if(!t.some(e=>e.added||e.removed)){c.Am.info("instruction"===e?"No changes were needed for that request":"Your template is already tidy — no cleanup needed");return}q({mode:e,versionId:n,proposed:s,diff:t,changeCount:d,summary:(null==o?void 0:null===(i=o.summary)||void 0===i?void 0:i.trim())||void 0});return}if((null==o?void 0:o.status)==="unchanged"){j("hidden"),c.Am.info("instruction"===e?"No changes were needed for that request":"Your template is already tidy — no cleanup needed");return}j("fallback"),c.Am.warning(en(e))}catch(n){if(r!==J.current)return;j("fallback");let t=n instanceof Error?n.message:"";c.Am.warning(/too large/i.test(t)?t:en(e))}},[null==ed?void 0:ed.id,null==ed?void 0:ed.content,Z,w,e_]),eU=(0,r.useCallback)(async()=>
1{if(!$)return;if($.versionId!==(null==ed?void 0:ed.id)){q(null),c.Am.error("This draft changed while you were reviewing — please run AI Assist again.");return}if(!em){q(null),c.Am.error("This template is no longer an editable draft — changes were not applied.");return}let e=ei.current;if(!e){c.Am.error("Couldn't apply changes — please try again");return}q(null);let t=e.replaceContent($.proposed);C(t);try{await eb($.versionId,t)}catch(e){B(!0);return}c.Am.success("instruction"===$.mode?$.summary||"Applied your changes":et($.changeCount))},[$,null==ed?void 0:ed.id,em,eb]),eI=(0,r.useCallback)(()=>{q(null),c.Am.info("Discarded — your template is unchanged")},[]);(0,r.useEffect)(()=>{if("success"!==T&&"fallback"!==T)return;let e=setTimeout(()=>j("hidden"),100);return()=>clearTimeout(e)},[T]);let eV=(0,r.useCallback)(e=>{C(e),K.current&&B(JSON.stringify(e)!==ee.current)},[]);if(eo&&!ec)return(0,a.BX)(v.W,{children:[(0,a.tZ)(v.W.Top,{children:(0,a.tZ)(v.W.Header,{title:"Loading…"})}),(0,a.tZ)(v.W.Content,{children:(0,a.BX)("div",{className:"flex flex-col gap-4",children:[(0,a.tZ)(h.O,{className:"h-8 w-64"}),(0,a.tZ)(h.O,{className:"h-[600px] w-full"})]})})]});if(es||!ec)return(0,a.BX)(v.W,{children:[(0,a.tZ)(v.W.Top,{children:(0,a.tZ)(v.W.Header,{title:"Template Not Found"})}),(0,a.tZ)(v.W.Content,{children:(0,a.tZ)("p",{className:"font-normal text-on-surface-secondary",children:null!==(m=null==es?void 0:es.message)&&void 0!==m?m:"Template could not be loaded."})})]});let eO=ey||ew||eZ||ek,eW="analyzing"===T||null!==$,eY=function(e){if(!e||0===e.length)return!1;for(let t of e){if("object"!=typeof t||null===t)continue;let{type:e,children:n}=t;if("signature_block"!==e){if("p"===e){let e=(null==n?void 0:n.length)===1?n[0]:null;if(!e||!e.text)continue}return!0}}return!1}(null!==(p=null!=Z?Z:null==ed?void 0:ed.content)&&void 0!==p?p:null);return(0,a.BX)("div",{"data-fill-page":!0,className:"relative flex h-full min-h-0 flex-col",children:[(0,a.BX)("header",{className:"flex items-center justify-between gap-4 border-b border-default px-4 py-3",children:[(0,a.BX)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.tZ)("button",{type:"button",onClick:()=>x.push("/v2/documents/templates"),"aria-label":"Back to templates",className:"flex size-7 shrink-0 items-center justify-center rounded text-on-surface-secondary transition-colors hover:bg-container-tertiary hover:text-on-surface",children:(0,a.tZ)(f.Z,{className:"size-4"})}),(0,a.tZ)("h1",{className:"truncate text-base font-semibold text-on-surface",children:ec.name})]}),(0,a.BX)("div",{className:"flex shrink-0 items-center gap-3",children:[(null===(n=ec.payroll_document_type)||void 0===n?void 0:n.name)&&(0,a.tZ)("span",{className:"text-sm font-normal font-content text-on-surface-secondary",children:ec.payroll_document_type.name}),(0,a.tZ)(H,{status:ef,currentVersion:ed,hasUnsavedChanges:z,isSaving:ey,lastSaved:X}),(0,a.tZ)("div",{className:"h-5 shrink-0 self-center border-l border-default"}),em?(0,a.tZ)(M,{editorRef:ei,onSave:ez,isSaving:ey,hasUnsavedChanges:z,onPublish:eB,isPublishing:ew,onImport:eP,onUseDefault:(0,A.jx)(null===(d=ec.payroll_document_type)||void 0===d?void 0:d.name,eu)?eE:void 0,hasExistingContent:eY,onArchive:eX,isArchiving:eZ,onReset:eT,assistInProgress:eW}):(0,a.tZ)(G,{status:ef,isDraft:em,isPublished:ep,isArchived:eh,hasUnsavedChanges:z,isSaving:ey,isPublishing:ew,isArchiving:eZ,isCreatingDraft:ek,assistInProgress:eW,onSave:ez,onPublish:eB,onArchive:eX,onCreateDraft:eS})]})]}),(0,a.tZ)("div",{className:"min-h-0 flex-1",children:(0,a.tZ)(k.u,{ref:ei,initialValue:null!==(y=null!=Z?Z:null==ed?void 0:ed.content)&&void 0!==y?y:void 0,onChange:eV,readOnly:!em||eO||eW,variableCategories:(0,_.u1)(null===(u=ec.payroll_document_type)||void 0===u?void 0:u.name,eu),requireSignatureBlock:!1,authoringTools:!0,fullBleed:!0,onAssist:em&&eY?()=>F(!0):void 0},"".concat(null!==(b=null==ed?void 0:ed.id)&&void 0!==b?b:"empty","-").concat(D))}),(0,a.tZ)(S,{active:"analyzing"===T,caption:V}),(0,a.tZ)(P,{open:Y,onOpenChange:F,onRun:ej}),$&&(0,a.tZ)(U,{open:!0,title:"instruction"===$.mode?"Review changes":"Review cleanup",summary:"instruction"===$.mode?$.summary||"Review the proposed changes below, then accept or discard.":et($.changeCount),diff:$.diff,onAccept:eU,onDiscard:eI})]})},er=n(82475),ei=()=>(0,a.tZ)(er.z,{children:(0,a.tZ)(ea,{})})},14919:function(e,t,n){"use strict";n.d(t,{OL:function(){return y},_T:function(){return m},aR:function(){return c},f$:function(){return v},fY:function(){return p},le:function(){return b},vW:function(){return d},xo:function(){return h},yT:function(){return g}});var a=n(52903),r=n(2784),i=n(21397),l=n(58636),o=n(51015),s=n(2121);let c=i.fC,d=i.xz,u=i.h_,f=r.forwardRef((e,t)=>
1{let{className:n,...r}=e;return(0,a.tZ)(i.aV,{className:(0,l.cn)("fixed inset-0 z-[53] bg-container-opacity-dark data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...r,ref:t})});f.displayName=i.aV.displayName;let m=r.forwardRef((e,t)=>{let{className:n,handleClose:r,...o}=e;return(0,a.BX)(u,{children:[(0,a.tZ)(f,{onClick:e=>{r&&(e.stopPropagation(),r())}}),(0,a.tZ)(i.VY,{ref:t,className:(0,l.cn)("font-content fixed left-[50%] top-[50%] z-[53] grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border-0.5 border-default bg-container p-6 shadow-md duration-200 rounded-lg\n        data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",n),...o})]})});m.displayName=i.VY.displayName;let p=e=>{let{className:t,...n}=e;return(0,a.tZ)("div",{className:(0,l.cn)("flex flex-col space-y-2 text-center sm:text-left",t),...n})};p.displayName="AlertDialogHeader";let h=e=>{let{className:t,...n}=e;return(0,a.tZ)("div",{className:(0,l.cn)("flex flex-col-reverse sm:flex-row sm:justify-start sm:space-x-2",t),...n})};h.displayName="AlertDialogFooter";let v=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.Dx,{ref:t,className:(0,l.cn)("font-content text-base text-on-surface font-semibold",n),...r})});v.displayName=i.Dx.displayName;let g=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.dk,{ref:t,className:(0,l.cn)("text-sm font-normal text-on-surface-secondary",n),...r})});g.displayName=i.dk.displayName;let y=r.forwardRef((e,t)=>{let{className:n,loading:r,disabled:c,children:d,variant:u="default",size:f="default",...m}=e;return(0,a.BX)(i.aU,{...m,disabled:r||c,ref:t,className:(0,l.cn)((0,o.d)({variant:u,size:f}),n),children:[r&&(0,a.tZ)(s.Z,{className:"animate-spin"}),d]})});y.displayName=i.aU.displayName;let b=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.$j,{ref:t,className:(0,l.cn)((0,o.d)({variant:"secondary"}),"mt-2 sm:mt-0",n),...r})});b.displayName=i.$j.displayName},49089:function(e,t,n){"use strict";n.d(t,{Bw:function(){return g},DI:function(){return f},Ph:function(){return u},Ql:function(){return b},i4:function(){return p},ki:function(){return m},n5:function(){return y}});var a=n(52903),r=n(2784),i=n(73676),l=n(58636),o=n(36890),s=n(24577),c=n(71644);let d=(0,n(10929).j)("font-content text-on-surface flex w-full min-w-0 items-center justify-between rounded-lg py-2 font-normal ring-offset-background\n    hover:border-default\n    focus:outline-none focus:ring-2 focus:ring-ring focus:border-ring\n    disabled:cursor-not-allowed disabled:opacity-50\n    [&>span]:line-clamp-1 [&>span]:min-w-0 [&>span]:text-start\n    [&_[data-select-badge]]:hidden",{variants:{variant:{default:"bg-container border border-default shadow data-[placeholder]:text-on-surface-secondary",secondary:"bg-container-tertiary border-none data-[placeholder]:text-on-surface hover:bg-hover-tertiary"},size:{default:"h-9 px-3 text-sm",sm:"h-8",xs:"h-7 px-2 text-xs",lg:"h-9 px-4 py-2 text-sm"}},defaultVariants:{variant:"default",size:"default"}}),u=i.fC,f=i.ZA,m=i.B4,p=r.forwardRef((e,t)=>{let{className:n,children:r,variant:o,size:c,...u}=e;return(0,a.BX)(i.xz,{ref:t,className:(0,l.cn)(d({variant:o,size:c,className:n})),...u,children:[r,(0,a.tZ)(i.JO,{asChild:!0,children:(0,a.tZ)(s.Z,{className:"h-4 w-4 opacity-50 stroke-surface-secondary"})})]})});p.displayName=i.xz.displayName;let h=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.u_,{ref:t,className:(0,l.cn)("flex cursor-default items-center justify-center py-1",n),...r,children:(0,a.tZ)(c.Z,{className:"h-4 w-4"})})});h.displayName=i.u_.displayName;let v=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.$G,{ref:t,className:(0,l.cn)("flex cursor-default items-center justify-center py-1",n),...r,children:(0,a.tZ)(s.Z,{className:"h-4 w-4"})})});v.displayName=i.$G.displayName;let g=r.forwardRef((e,t)=>
1{let{className:n,children:r,position:o="popper",constrainWidth:s=!1,...c}=e;return(0,a.tZ)(i.h_,{children:(0,a.BX)(i.VY,{ref:t,className:(0,l.cn)("font-content relative z-[60] max-h-[--radix-select-content-available-height] min-w-[8rem] max-w-[calc(100vw-2rem)] overflow-y-auto overflow-x-hidden rounded-md border-0.5 border-default bg-container text-on-surface shadow-md\n        data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95\n        data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]","popper"===o&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",n),position:o,...c,children:[(0,a.tZ)(h,{}),(0,a.tZ)(i.l_,{className:(0,l.cn)("p-1","popper"===o&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] ".concat(s?"max-w-[var(--radix-select-trigger-width)]":"max-w-[calc(100vw-2rem)]")),children:r}),(0,a.tZ)(v,{})]})})});g.displayName=i.VY.displayName;let y=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.__,{ref:t,className:(0,l.cn)("px-2 py-1.5 text-sm font-semibold",n),...r})});y.displayName=i.__.displayName;let b=r.forwardRef((e,t)=>{let{className:n,children:r,...s}=e;return(0,a.BX)(i.ck,{ref:t,className:(0,l.cn)("relative flex w-full min-w-0 cursor-default select-none items-center rounded-md py-1.5 pl-2 pr-8 text-sm font-normal outline-none\n      transition duration-fast ease-default\n      focus:bg-hover-secondary\n      data-[disabled]:pointer-events-none data-[disabled]:opacity-50\n      [&>span:last-child]:min-w-0 [&>span:last-child]:break-words",n),...s,children:[(0,a.tZ)("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center shrink-0",children:(0,a.tZ)(i.wU,{children:(0,a.tZ)(o.Z,{className:"h-4 w-4"})})}),(0,a.tZ)(i.eT,{children:r})]})});b.displayName=i.ck.displayName,r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)(i.Z0,{ref:t,className:(0,l.cn)("-mx-1 my-1 h-px bg-muted",n),...r})}).displayName=i.Z0.displayName},52654:function(e,t,n){"use strict";n.d(t,{g:function(){return l}});var a=n(52903),r=n(2784),i=n(58636);let l=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.tZ)("textarea",{className:(0,i.cn)("!font-content flex min-h-[60px] w-full rounded-lg border border-default bg-container px-3 py-2 text-[16px] sm:text-sm shadow font-normal text-on-surface\n          placeholder:text-on-surface-secondary dark:text-white\n          focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:border-ring focus-visible:caret-secondary\n          transition-shadow duration-fast ease-default\n          disabled:cursor-not-allowed disabled:opacity-50",n),ref:t,...r})});l.displayName="Textarea"},71644:function(e,t,n){"use strict";var a=n(52903);n(2784);let r=e=>(0,a.tZ)("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,fill:"none",viewBox:"0 0 24 24",...e,children:(0,a.tZ)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"m18 15-6-6-6 6"})});r.displayName="line/Arrows/chevron-up",t.Z=r}},function(e){e.O(0,[480,6425,6253,3676,2756,1669,8111,8568,456,2888,9774,179],function(){return e(e.s=36120)}),_N_E=e.O()}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.