1import{j as e}from"./vendor-ui-g3F7e1tK.js";import{r as c}from"./vendor-react-CRnAI_PO.js";import{s as u,aw as o,B as d,a5 as D,C,c as O,d as R,f as j,bT as k,a$ as w,aT as B,aN as z,k as J,a7 as K,bd as Q,ao as P,a8 as Z,a9 as ee,aa as te,L as p,m as se,n as ae,o as ne,p as ie,q as re,I as E,v as oe,an as le,aH as ce,b9 as de,aE as me}from"./index-CGUZ83YD.js";import{d as he}from"./contractDownload-gnziYyHc.js";import{F as L}from"./file-pen-line-CJauE3oU.js";import"./vendor-pdf-TDXswbIA.js";import"./vendor-charts-6iPoxtwk.js";import"./vendor-supabase-DTnJzh1l.js";const $=[{id:"freelance",name:"Freelance Agreement",description:"Standard freelance service contract"},{id:"service",name:"Service Contract",description:"General service provider agreement"},{id:"nda",name:"Non-Disclosure Agreement",description:"Confidentiality agreement"},{id:"consulting",name:"Consulting Agreement",description:"Professional consulting engagement"},{id:"custom",name:"Custom Contract",description:"Start from scratch"}],F=(i,l,m)=>{const h=w(new Date,"MMMM d, yyyy"),x={freelance:`FREELANCE SERVICE AGREEMENT 2 3This Freelance Service Agreement ("Agreement") is entered into as of ${h}, by and between: 4 5Service Provider: ${l} 6Client: ${m} 7 81. SCOPE OF WORK 9The Service Provider agrees to perform the following services: 10[Describe services here] 11 122. COMPENSATION 13The Client agrees to pay the Service Provider: 14Amount: [Amount] 15Payment Terms: [Terms] 16 173. TIMELINE 18Start Date: [Date] 19End Date: [Date] 20 214. INTELLECTUAL PROPERTY 22All work product created shall be owned by the Client upon full payment. 23 245. CONFIDENTIALITY 25Both parties agree to maintain confidentiality of proprietary information. 26 276. TERMINATION 28Either party may terminate with [X] days written notice. 29 30By signing below, both parties agree to the terms outlined above.`,service:`SERVICE CONTRACT 31 32Date: ${h} 33 34Between: 35Provider: ${l} 36Client: ${m} 37 381. SERVICES 39[Describe the services to be provided] 40 412. FEES AND PAYMENT 42Total Fee: [Amount] 43Payment Schedule: [Details] 44 453. DURATION 46This contract is effective from [Start Date] to [End Date]. 47 484. RESPONSIBILITIES 49Provider will: [List responsibilities] 50Client will: [List responsibilities] 51 525. WARRANTY 53Provider warrants that services will be performed in a professional manner. 54 556. LIABILITY 56[Liability terms] 57 587. GOVERNING LAW 59This contract shall be governed by the laws of [Jurisdiction]. 60 61Signed and agreed:`,nda:`NON-DISCLOSURE AGREEMENT 62 63Date: ${h} 64 65Between: 66Disclosing Party: ${l} 67Receiving Party: ${m} 68 691. DEFINITION OF CONFIDENTIAL INFORMATION 70All non-public information disclosed by the Disclosing Party, whether oral, written, or electronic. 71 722. OBLIGATIONS 73The Receiving Party agrees to: 74- Hold all Confidential Information in strict confidence 75- Not disclose to any third party 76- Use only for the agreed purpose 77 783. DURATION 79This agreement remains in effect for [X] years from the date of signing. 80 814. EXCEPTIONS 82Information that is: 83- Publicly available 84- Already known by the Receiving Party 85- Independently developed 86 875. RETURN OF INFORMATION 88Upon request, the Receiving Party shall return or destroy all confidential materials. 89 90Agreed and signed:`,consulting:`CONSULTING AGREEMENT 91 92Date: ${h} 93 94Between: 95Consultant: ${l} 96Client: ${m} 97 981. ENGAGEMENT 99The Client engages the Consultant to provide professional consulting services. 100 1012. SERVICES 102[Describe consulting services] 103 1043. COMPENSATION 105Rate: [Rate] 106Billing: [Monthly/Project-based] 107Expenses: [Policy] 108 1094. INDEPENDENT CONTRACTOR 110The Consultant is an independent contractor, not an employee. 111 1125. DELIVERABLES 113[List expected deliverables] 114 1156. CONFIDENTIALITY 116Both parties agree to maintain confidentiality. 117 1187. TERM AND TERMINATION 119This agreement begins [Date] and continues until [Date/completion]. 120 121Signed:`,custom:`CONTRACT 122 123Date: ${h} 124 125Between: 126${l} 127and 128${m} 129 130[Write your contract terms here] 131 132 133Signed and agreed:`};return x[i]||x.custom},M={draft:{color:"secondary",icon:ce},sent:{color:"default",icon:B},viewed:{color:"outline",icon:de},signed:{color:"default",icon:k},expired:{color:"destructive",icon:me}},je=({member:i})=>{var I,b;const[l,m]=c.useState([]),[h,x]=c.useState(!0),[G,v]=c.useState(!1),[a,_]=c.useState(null),[f,q]=c.useState([]),[T,S]=c.useState(!1),[n,g]=c.useState({title:"",template_type:"custom",client_name:"",client_email:"",content:""}),U=i.is_one_host_user?{one_host_user_id:i.id}:{member_id:i.id};c.useEffect(()=>{y()},[]);const y=async()=>{x(!0);try{let t=u.from("one_host_contracts").select("*").order("created_at",{ascending:!1});i.is_one_host_user?t=t.eq("one_host_user_id",i.id):t=t.eq("member_id",i.id);const{data:s,error:r}=await t;if(r)throw r;m(s||[])}catch{o.error("Failed to load contracts")}finally{x(!1)}},V=async()=>
133{if(!n.title||!n.client_name||!n.client_email){o.error("Please fill in title, client name and email");return}S(!0);try{const t=n.content||F(n.template_type,i.full_name,n.client_name),{error:s}=await u.from("one_host_contracts").insert({...U,title:n.title,template_type:n.template_type,client_name:n.client_name,client_email:n.client_email,content:{text:t},status:"draft"});if(s)throw s;o.success("Contract created!"),v(!1),g({title:"",template_type:"custom",client_name:"",client_email:"",content:""}),y()}catch(t){o.error(t.message)}finally{S(!1)}},Y=async t=>{_(t);const{data:s}=await u.from("one_host_contract_signatures").select("*").eq("contract_id",t.id);q(s||[])},H=async t=>{try{const{error:s}=await u.from("one_host_contracts").update({status:"sent"}).eq("id",t.id);if(s)throw s;const r=`${window.location.origin}/sign/${t.contract_code}`,N=(i.business_name||i.full_name||"One Host HQ").replace(/[<>"]/g,""),{error:A}=await u.functions.invoke("send-email",{body:{to:t.client_email,subject:`Contract: ${t.title}`,html:`<div style="font-family:sans-serif;max-width:600px;margin:0 auto;"> 134 <h2>You have a contract to review</h2> 135 <p>Hi ${t.client_name},</p> 136 <p><strong>${N}</strong> has sent you a contract titled <strong>"${t.title}"</strong> for your review and signature.</p> 137 <p style="margin:24px 0;"><a href="${r}" style="background:#7c3aed;color:#fff;padding:12px 24px;border-radius:8px;text-decoration:none;font-weight:bold;">Review & Sign Contract</a></p> 138 <p style="color:#666;font-size:13px;">Or copy this link: ${r}</p> 139 </div>`,from:`${N} <[email protected]>`,reply_to:i.email||void 0,sender_one_host_user_id:i.id}});A?(console.error("Email send error:",A),o.success("Contract status updated. Email delivery may have failed â link copied to clipboard.")):o.success(`Contract sent to ${t.client_email}!`),navigator.clipboard.writeText(r),y()}catch{o.error("Failed to send contract")}},W=async t=>{try{const{error:s}=await u.from("one_host_contracts").delete().eq("id",t);if(s)throw s;o.success("Contract deleted"),(a==null?void 0:a.id)===t&&_(null),y()}catch{o.error("Failed to delete")}},X=t=>{g(s=>{var r;return{...s,template_type:t,content:F(t,i.full_name,s.client_name||"[Client Name]"),title:s.title||((r=$.find(N=>N.id===t))==null?void 0:r.name)||""}})};if(a){const t=typeof a.content=="object"?((I=a.content)==null?void 0:I.text)||JSON.stringify(a.content):String(a.content);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>_(null),children:"â Back"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold",children:a.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["For: ",a.client_name," (",a.client_email,")"]})]})]}),e.jsx(D,{variant:((b=M[a.status])==null?void 0:b.color)||"secondary",children:a.status})]}),e.jsxs(C,{children:[e.jsx(O,{children:e.jsx(R,{className:"text-base",children:"Contract Content"})}),e.jsx(j,{children:e.jsx("pre",{className:"whitespace-pre-wrap text-sm font-sans bg-muted/50 p-4 rounded-lg border",children:t})})]}),f.length>0&&e.jsxs(C,{children:[e.jsx(O,{children:e.jsx(R,{className:"text-base",children:"Signatures"})}),e.jsx(j,{className:"space-y-4",children:f.map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 border rounded-lg",children:[e.jsx(k,{className:"h-5 w-5 text-green-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.signer_name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.signer_email," ⢠Signed ",w(new Date(s.signed_at),"MMM d, yyyy h:mm a")]})]}),s.signature_data&&s.signature_data.startsWith("data:image")&&e.jsx("img",{src:s.signature_data,alt:"Signature",className:"h-12 ml-auto border rounded"})]},s.id))})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[a.status==="draft"&&e.jsxs(d,{className:"gap-2",onClick:()=>H(a),children:[e.jsx(B,{className:"h-4 w-4"})," Send & Copy Link"]}),["sent","viewed"].includes(a.status)&&e.jsxs(d,{variant:"outline",className:"gap-2",onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/sign/${a.contract_code}`),o.success("Signing link copied!")},children:[e.jsx(z,{className:"h-4 w-4"})," Copy Signing Link"]}),a.status==="signed"&&f.length>0&&e.jsxs(d,{variant:"outline",className:"gap-2",onClick:()=>he(a,f,t),children:[e.jsx(J,{className:"h-4 w-4"})," Download Signed Copy (PDF)"]})]})]})}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold",children:"Contracts & E-Signatures"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create, send, and track contracts with digital signatures"})]}),e.jsxs(K,{open:G,onOpenChange:v,children:[e.jsx(Q,{asChild:!0,children:e.jsxs(d,{className:"gap-2",children:[e.jsx(P,{className:"h-4 w-4"})," New Contract"]})}),e.jsxs(Z,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(ee,{children:e.jsx(te,{children:"Create New Contract"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Template"}),e.jsxs(se,{value:n.template_type,onValueChange:X,children:[e.jsx(ae,{children:e.jsx(ne,{})}),e.jsx(ie,{children:$.map(t=>e.jsxs(re,{value:t.id,children:[e.jsx("span",{className:"font-medium",children:t.name}),e.jsxs("span",{className:"text-muted-foreground ml-2 text-xs",children:["â ",t.description]})]},t.id))})]})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Contract Title"}),e.jsx(E,{placeholder:"Project Agreement",value:n.title,onChange:t=>g(s=>({...s,title:t.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Client Name"}),e.jsx(E,{placeholder:"John Doe",value:n.client_name,onChange:t=>g(s=>({...s,client_name:t.target.value}))})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Client Email"}),e.jsx(E,{type:"email",placeholder:"[email protected]",value:n.client_email,onChange:t=>g(s=>({...s,client_email:t.target.value}))})]})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Contract Content"}),e.jsx(oe,{className:"min-h-[300px] font-mono text-sm",value:n.content,onChange:t=>g(s=>({...s,content:t.target.value})),placeholder:"Edit your contract text here..."})]}),e.jsx(d,{onClick:V,disabled:T,className:"w-full",children:T?"Creating...":"Create Contract"})]})]})]})]}),h?e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"Loading..."}):l.length===0?e.jsx(C,{children:e.jsxs(j,{className:"py-12 text-center",children:[e.jsx(L,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"font-semibold mb-2",children:"No contracts yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Create professional contracts and get them signed digitally."}),e.jsxs(d,{onClick:()=>v(!0),className:"gap-2",children:[e.jsx(P,{className:"h-4 w-4"})," Create Your First Contract"]})]})}):e.jsx("div",{className:"space-y-3",children:l.map(t=>{var s;return e.jsx(C,{className:"cursor-pointer hover:border-primary/50 transition-colors",onClick:()=>Y(t),children:e.jsx(j,{className:"py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(L,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.client_name," ⢠",w(new Date(t.created_at),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:((s=M[t.status])==null?void 0:s.color)||"secondary",children:t.status}),t.status==="draft"&&e.jsx(d,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:r=>{r.stopPropagation(),W(t.id)},children:e.jsx(le,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})]})})},t.id)})})]})};export{je as ContractManager};
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.