@tantainnovative/ndpr-toolkit
Version:
Nigeria Data Protection Toolkit — enterprise-grade compliance components for the Nigeria Data Protection Act (NDPA) 2023
93 lines (90 loc) • 27.6 kB
JavaScript
import {c as c$1,d,b as b$1}from'./chunk-NBQQ2GN3.mjs';import {a}from'./chunk-SFGW37LE.mjs';import {c}from'./chunk-PHA3YMFO.mjs';import {d as d$1,b,a as a$1}from'./chunk-ZJYULEER.mjs';import {useId,useState,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';var Ee=({sections:E=c$1,variables:R=d,onGenerate:S,title:F,description:A,className:N="",buttonClassName:P="",generateButtonText:Y,showPreview:q=true,allowEditing:Q=true,classNames:t,unstyled:y=false})=>{var W,de,ae;let B=c(),Z=(W=F!=null?F:B.policy.generatorTitle)!=null?W:"NDPA Privacy Policy Generator",l=(de=A!=null?A:B.policy.generatorDescription)!=null?de:"Generate an NDPA-compliant privacy policy for your organization in accordance with NDPA Section 27.",i=(ae=Y!=null?Y:B.policy.generate)!=null?ae:"Generate Policy",m=useId(),[L,ee]=useState(E),[b$2,k]=useState(R),[g,$]=useState("sections"),[X,H]=useState(""),[U,M]=useState(""),[ne,T]=useState(false),[h,G]=useState({});useEffect(()=>{ee(E);},[E]),useEffect(()=>{k(R);},[R]);let oe=p=>{ee(c=>c.map(e=>e.id===p?b(a$1({},e),{included:!e.included}):e));},I=(p,c)=>{k(e=>e.map(d=>d.id===p?b(a$1({},d),{value:c}):d)),h[p]&&G(e=>{let d=a$1({},e);return delete d[p],d});},ie=()=>{let p={},c=true;return b$2.forEach(e=>{e.required&&!e.value&&(p[e.id]=`${e.name} is required`,c=false);}),G(p),c},re=()=>{if(!ie()){$("variables");return}let p=L.filter(d=>d.included),c=Object.fromEntries(b$2.map(d=>[d.name,d.value])),e="";p.forEach(d=>{e+=`## ${d.title}
`,e+=b$1(d.template,c),e+=`
`;}),H(e),M(e),T(true),$("preview");},V=()=>{S({sections:L,variables:b$2,content:Q?U:X});},u=()=>jsxs("div",{"data-ndpr-component":"policy-generator",className:a("ndpr-form-section",t==null?void 0:t.sectionList,y),role:"group","aria-labelledby":`${m}-sections-heading`,children:[jsx("h3",{id:`${m}-sections-heading`,className:"text-lg font-medium mb-4",children:"Select Policy Sections"}),L.map(p=>{let c=`${m}-section-${p.id}`,e=p.description?`${m}-section-desc-${p.id}`:void 0;return jsx("div",{className:a("border border-gray-200 dark:border-gray-700 rounded-md p-4",t==null?void 0:t.sectionItem,y),children:jsxs("div",{className:"flex items-start",children:[jsx("div",{className:"flex items-center h-5",children:jsx("input",{id:c,type:"checkbox",checked:p.included,onChange:()=>oe(p.id),disabled:p.required,"aria-describedby":e,className:a("w-4 h-4 text-[rgb(var(--ndpr-primary))] border-gray-300 rounded focus:ring-[rgb(var(--ndpr-ring))] dark:focus:ring-[rgb(var(--ndpr-ring))] dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600",t==null?void 0:t.input,y)})}),jsxs("div",{className:"ml-3 text-sm",children:[jsxs("label",{htmlFor:c,className:"font-medium ndpr-text-foreground",children:[p.title," ",p.required&&jsx("span",{className:"text-red-500","aria-hidden":"true",children:"*"}),p.required&&jsx("span",{className:"sr-only",children:" (required)"})]}),p.description&&jsx("p",{id:e,className:"ndpr-text-muted mt-1",children:p.description})]})]})},p.id)}),jsx("div",{className:"mt-6",children:jsx("button",{onClick:()=>$("variables"),className:a(`px-4 py-2 bg-[rgb(var(--ndpr-primary))] text-white rounded hover:bg-[rgb(var(--ndpr-primary-hover))] ${P}`,(t==null?void 0:t.primaryButton)||(t==null?void 0:t.generateButton),y),children:"Next: Fill Variables"})})]}),f=()=>{let p={};return b$2.forEach(c=>{let e=c.id.split(".")[0];p[e]||(p[e]=[]),p[e].push(c);}),jsxs("div",{className:a("",t==null?void 0:t.form,y),children:[jsx("h3",{className:"text-lg font-medium mb-4",children:"Fill Policy Variables"}),jsx("div",{className:"ndpr-form-section",children:Object.entries(p).map(([c,e])=>{let d=L.find(r=>r.id===c);return d&&!d.included?null:jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md p-4",children:[jsx("h4",{className:"font-medium text-lg mb-3",children:d?d.title:"General Information"}),jsx("div",{className:"ndpr-form-section",children:e.map(r=>{let O=`${m}-var-${r.id}`,j=r.description?`${m}-var-desc-${r.id}`:void 0,le=h[r.id]?`${m}-var-err-${r.id}`:void 0,J=[j,le].filter(Boolean).join(" ")||void 0;return jsxs("div",{children:[jsxs("label",{htmlFor:O,className:"ndpr-form-field__label",children:[r.name," ",r.required&&jsx("span",{className:"text-red-500","aria-hidden":"true",children:"*"})]}),r.description&&jsx("p",{id:j,className:"text-xs ndpr-text-muted mb-2",children:r.description}),r.inputType==="textarea"?jsx("textarea",{id:O,value:r.value,onChange:_=>I(r.id,_.target.value),rows:4,className:a(`w-full px-3 py-2 border ${h[r.id]?"border-red-500 focus:ring-red-500":"border-gray-300 dark:border-gray-600 focus:ring-[rgb(var(--ndpr-ring))]"} rounded-md focus:outline-none focus:ring-2`,t==null?void 0:t.input,y),required:r.required,"aria-required":r.required||void 0,"aria-describedby":J,"aria-invalid":h[r.id]?true:void 0}):r.inputType==="select"&&r.options?jsxs("select",{id:O,value:r.value,onChange:_=>I(r.id,_.target.value),className:a(`w-full px-3 py-2 border ${h[r.id]?"border-red-500 focus:ring-red-500":"border-gray-300 dark:border-gray-600 focus:ring-[rgb(var(--ndpr-ring))]"} rounded-md focus:outline-none focus:ring-2`,t==null?void 0:t.input,y),required:r.required,"aria-required":r.required||void 0,"aria-describedby":J,"aria-invalid":h[r.id]?true:void 0,children:[jsx("option",{value:"",children:"Select an option"}),r.options.map(_=>jsx("option",{value:_,children:_},_))]}):jsx("input",{id:O,type:r.inputType,value:r.value,onChange:_=>I(r.id,_.target.value),className:a(`w-full px-3 py-2 border ${h[r.id]?"border-red-500 focus:ring-red-500":"border-gray-300 dark:border-gray-600 focus:ring-[rgb(var(--ndpr-ring))]"} rounded-md focus:outline-none focus:ring-2`,t==null?void 0:t.input,y),required:r.required,"aria-required":r.required||void 0,"aria-describedby":J,"aria-invalid":h[r.id]?true:void 0}),h[r.id]&&jsx("p",{id:le,role:"alert",className:"mt-1 text-sm ndpr-text-destructive dark:text-red-500",children:h[r.id]})]},r.id)})})]},c)})}),jsxs("div",{className:"mt-6 flex space-x-4",children:[jsx("button",{onClick:()=>$("sections"),className:`px-4 py-2 bg-gray-200 text-gray-800 dark:bg-gray-700 dark:text-white rounded hover:bg-gray-300 dark:hover:bg-gray-600 ${P}`,children:"Back to Sections"}),jsx("button",{onClick:re,className:a(`px-4 py-2 bg-[rgb(var(--ndpr-primary))] text-white rounded hover:bg-[rgb(var(--ndpr-primary-hover))] ${P}`,(t==null?void 0:t.primaryButton)||(t==null?void 0:t.generateButton),y),children:i})]})]})},x=()=>{let p=`${m}-policy-content`;return jsxs("div",{children:[jsx("h3",{className:"text-lg font-medium mb-4",children:"Preview Generated Policy"}),Q?jsxs("div",{className:"ndpr-form-field",children:[jsx("label",{htmlFor:p,className:"ndpr-form-field__label",children:"Edit Policy Content"}),jsx("textarea",{id:p,value:U,onChange:c=>M(c.target.value),rows:20,className:"ndpr-form-field__input ndpr-form-field__input--mono"})]}):jsx("div",{className:"ndpr-panel","aria-live":"polite",children:jsx("div",{className:"prose dark:prose-invert max-w-none",children:X.split(`
`).map((c,e)=>c.startsWith("## ")?jsx("h3",{className:"text-xl font-bold mt-6 mb-3",children:c.substring(3)},e):c.startsWith("### ")?jsx("h4",{className:"text-lg font-bold mt-4 mb-2",children:c.substring(4)},e):c===""?jsx("br",{},e):jsx("p",{className:"mb-2",children:c},e))})}),jsxs("div",{className:"mt-6 flex space-x-4",children:[jsx("button",{onClick:()=>$("variables"),className:`px-4 py-2 bg-gray-200 text-gray-800 dark:bg-gray-700 dark:text-white rounded hover:bg-gray-300 dark:hover:bg-gray-600 ${P}`,children:"Back to Variables"}),jsx("button",{onClick:V,className:`px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700 ${P}`,children:"Save Policy"})]})]})},C=()=>{switch(g){case "sections":return u();case "variables":return f();case "preview":return x();default:return u()}};return jsxs("div",{className:a(`bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md ${N}`,t==null?void 0:t.root,y),children:[jsxs("div",{className:a("mb-6",t==null?void 0:t.header,y),children:[jsx("h2",{className:a("ndpr-section-heading",t==null?void 0:t.title,y),children:Z}),jsx("p",{className:a("ndpr-card__subtitle",t==null?void 0:t.description,y),children:l})]}),jsx("nav",{"aria-label":"Policy generation steps",className:"mb-8",children:jsxs("ol",{className:"flex items-center w-full",children:[jsxs("li",{className:`flex w-full items-center ${g==="sections"?"ndpr-text-primary":"ndpr-card__subtitle"} after:content-[''] after:w-full after:h-1 after:border-b after:border-gray-200 after:border-1 after:hidden sm:after:inline-block after:mx-6 xl:after:mx-10`,children:[jsx("span",{className:`flex items-center justify-center w-8 h-8 ${g==="sections"?"ndpr-alert ndpr-alert--info":"ndpr-panel"} rounded-full shrink-0`,"aria-current":g==="sections"?"step":void 0,children:"1"}),jsx("span",{className:"hidden sm:inline-flex sm:ml-2",children:"Sections"}),jsx("span",{className:"sr-only",children:g==="sections"?" (current step)":""})]}),jsxs("li",{className:`flex w-full items-center ${g==="variables"?"ndpr-text-primary":"ndpr-card__subtitle"} after:content-[''] after:w-full after:h-1 after:border-b after:border-gray-200 after:border-1 after:hidden sm:after:inline-block after:mx-6 xl:after:mx-10`,children:[jsx("span",{className:`flex items-center justify-center w-8 h-8 ${g==="variables"?"ndpr-alert ndpr-alert--info":"ndpr-panel"} rounded-full shrink-0`,"aria-current":g==="variables"?"step":void 0,children:"2"}),jsx("span",{className:"hidden sm:inline-flex sm:ml-2",children:"Variables"}),jsx("span",{className:"sr-only",children:g==="variables"?" (current step)":""})]}),jsxs("li",{className:`flex items-center ${g==="preview"?"ndpr-text-primary":"ndpr-card__subtitle"}`,children:[jsx("span",{className:`flex items-center justify-center w-8 h-8 ${g==="preview"?"ndpr-alert ndpr-alert--info":"ndpr-panel"} rounded-full shrink-0`,"aria-current":g==="preview"?"step":void 0,children:"3"}),jsx("span",{className:"hidden sm:inline-flex sm:ml-2",children:"Preview"}),jsx("span",{className:"sr-only",children:g==="preview"?" (current step)":""})]})]})}),jsxs("div",{className:a("ndpr-alert ndpr-alert--info",t==null?void 0:t.complianceNotice,y),children:[jsx("h3",{className:"text-sm font-bold ndpr-text-info mb-2",children:"NDPA Compliance Notice"}),jsx("p",{className:"ndpr-text-info text-sm",children:"This tool helps you generate a privacy policy that aligns with the Nigeria Data Protection Act (NDPA) 2023. While we strive to ensure compliance, we recommend having the final policy reviewed by a legal professional familiar with NDPA requirements."})]}),C()]})};var Ie=({content:E,sections:R,variables:S,onExport:F,onEdit:A,title:N,description:P,className:Y="",buttonClassName:q="",showExportOptions:Q=true,showEditButton:t=true,showTableOfContents:y=true,showMetadata:B=true,organizationName:Z,lastUpdated:l,classNames:i,unstyled:m=false})=>{var re,V;let L=c(),ee=(re=N!=null?N:L.policy.previewTitle)!=null?re:"Privacy Policy Preview",b=(V=P!=null?P:L.policy.previewDescription)!=null?V:"Preview your NDPA-compliant privacy policy before exporting.",k=useId(),[g,$]=useState("preview"),X=`${k}-tab-preview`,H=`${k}-tab-markdown`,U=`${k}-panel-preview`,M=`${k}-panel-markdown`,T=(()=>{let u=E.split(`
`),f=[];return u.forEach(x=>{if(x.startsWith("## ")){let C=x.substring(3).trim(),W=`${k}-${C.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;f.push({id:W,title:C,level:2});}else if(x.startsWith("### ")){let C=x.substring(4).trim(),W=`${k}-${C.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;f.push({id:W,title:C,level:3});}}),f})(),h=u=>{if(F)F(u);else if(u==="markdown"){let f=document.createElement("a"),x=new Blob([E],{type:"text/markdown"});f.href=URL.createObjectURL(x),f.download=`privacy-policy-${new Date().toISOString().split("T")[0]}.md`,document.body.appendChild(f),f.click(),document.body.removeChild(f);}},G=()=>!y||T.length===0?null:jsxs("nav",{"aria-label":"Table of contents",className:"ndpr-panel",children:[jsx("h3",{className:"text-lg font-medium mb-3",children:"Table of Contents"}),jsx("ul",{className:"space-y-1",children:T.map((u,f)=>jsx("li",{style:{marginLeft:`${(u.level-2)*1.5}rem`},children:jsx("a",{href:`#${u.id}`,className:"ndpr-text-primary hover:underline",children:u.title})},f))})]}),oe=()=>B?jsxs("div",{"data-ndpr-component":"policy-preview",className:"mb-6",children:[jsx("h1",{className:"ndpr-card__title",children:Z?`${Z} Privacy Policy`:"Privacy Policy"}),jsxs("p",{className:"ndpr-form-field__hint",children:["Last Updated: ",l?l.toLocaleDateString():"N/A"]})]}):null,I=()=>jsx("div",{className:a("prose dark:prose-invert max-w-none",i==null?void 0:i.sectionContent,m),children:E.split(`
`).map((u,f)=>{if(u.startsWith("## ")){let x=u.substring(3).trim(),C=`${k}-${x.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;return jsx("h3",{id:C,className:a("text-xl font-bold mt-6 mb-3",i==null?void 0:i.sectionTitle,m),children:x},f)}else if(u.startsWith("### ")){let x=u.substring(4).trim(),C=`${k}-${x.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;return jsx("h4",{id:C,className:a("text-lg font-bold mt-4 mb-2",i==null?void 0:i.sectionTitle,m),children:x},f)}else return u===""?jsx("br",{},f):jsx("p",{className:"mb-2",children:u},f)})}),ie=()=>Q?jsxs("div",{className:"mt-6",children:[jsx("h3",{className:"text-lg font-medium mb-3",children:"Export Options"}),jsxs("div",{className:"ndpr-card__footer",children:[jsx("button",{onClick:()=>h("pdf"),className:`px-4 py-2 bg-[rgb(var(--ndpr-primary))] text-white rounded hover:bg-[rgb(var(--ndpr-primary-hover))] ${q}`,children:"Export as PDF"}),jsx("button",{onClick:()=>h("docx"),className:`px-4 py-2 bg-[rgb(var(--ndpr-primary))] text-white rounded hover:bg-[rgb(var(--ndpr-primary-hover))] ${q}`,children:"Export as DOCX"}),jsx("button",{onClick:()=>h("html"),className:`px-4 py-2 bg-[rgb(var(--ndpr-primary))] text-white rounded hover:bg-[rgb(var(--ndpr-primary-hover))] ${q}`,children:"Export as HTML"}),jsx("button",{onClick:()=>h("markdown"),className:`px-4 py-2 bg-[rgb(var(--ndpr-primary))] text-white rounded hover:bg-[rgb(var(--ndpr-primary-hover))] ${q}`,children:"Export as Markdown"})]})]}):null;return jsxs("div",{className:a(`bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md ${Y}`,i==null?void 0:i.root,m),children:[jsxs("div",{className:a("flex justify-between items-start mb-6",i==null?void 0:i.header,m),children:[jsxs("div",{children:[jsx("h2",{className:a("ndpr-section-heading",i==null?void 0:i.title,m),children:ee}),jsx("p",{className:a("ndpr-card__subtitle",i==null?void 0:i.description,m),children:b})]}),t&&A&&jsx("button",{onClick:A,className:`px-4 py-2 bg-gray-200 text-gray-800 dark:bg-gray-700 dark:text-white rounded hover:bg-gray-300 dark:hover:bg-gray-600 ${q}`,children:"Edit Policy"})]}),jsxs("div",{className:a("ndpr-alert ndpr-alert--info",i==null?void 0:i.complianceNotice,m),children:[jsx("h3",{className:"text-sm font-bold ndpr-text-info mb-2",children:"NDPA Compliance Notice"}),jsx("p",{className:"ndpr-text-info text-sm",children:"This privacy policy has been generated to align with the Nigeria Data Protection Act (NDPA) 2023. We recommend having the final policy reviewed by a legal professional familiar with NDPA requirements before publishing it on your website or sharing it with your users."})]}),jsx("div",{className:"mb-6 border-b border-gray-200 dark:border-gray-700",children:jsxs("div",{role:"tablist","aria-label":"Policy view options",className:"flex flex-wrap -mb-px",children:[jsx("div",{className:"mr-2",children:jsx("button",{role:"tab",id:X,"aria-selected":g==="preview","aria-controls":U,onClick:()=>$("preview"),className:`inline-block p-4 ${g==="preview"?"text-[rgb(var(--ndpr-primary))] border-b-2 border-[rgb(var(--ndpr-primary))] dark:text-[rgb(var(--ndpr-primary))] dark:border-[rgb(var(--ndpr-primary))]":"text-gray-600 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300"}`,children:"Preview"})}),jsx("div",{className:"mr-2",children:jsx("button",{role:"tab",id:H,"aria-selected":g==="markdown","aria-controls":M,onClick:()=>$("markdown"),className:`inline-block p-4 ${g==="markdown"?"text-[rgb(var(--ndpr-primary))] border-b-2 border-[rgb(var(--ndpr-primary))] dark:text-[rgb(var(--ndpr-primary))] dark:border-[rgb(var(--ndpr-primary))]":"text-gray-600 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300"}`,children:"Markdown"})})]})}),jsx("div",{className:a("bg-white dark:bg-gray-800 p-4 rounded-md",i==null?void 0:i.content,m),children:g==="preview"?jsxs("div",{role:"tabpanel",id:U,"aria-labelledby":X,"aria-live":"polite",children:[oe(),G(),jsx("div",{className:a("bg-gray-50 dark:bg-gray-700 p-6 rounded-md",i==null?void 0:i.section,m),children:I()})]}):jsx("div",{role:"tabpanel",id:M,"aria-labelledby":H,children:jsx("pre",{className:"bg-gray-50 dark:bg-gray-700 p-4 rounded-md overflow-auto whitespace-pre-wrap font-mono text-sm text-gray-800 dark:text-gray-200",children:E})})}),ie()]})};var Me=({content:E,title:R,organizationName:S,lastUpdated:F,onExportComplete:A,componentTitle:N="Export Privacy Policy",description:P,className:Y="",buttonClassName:q="",showExportHistory:Q=true,includeComplianceNotice:t=true,includeLogo:y=false,logoUrl:B,customStyles:Z,classNames:l,unstyled:i=false})=>{var p,c$1;let m=c(),L=(p=R!=null?R:m.policy.exporterTitle)!=null?p:"Privacy Policy",ee=(c$1=P!=null?P:m.policy.exporterDescription)!=null?c$1:"Export your NDPA-compliant privacy policy in various formats.",b=useId(),[k,g]=useState([]),[$,X]=useState("pdf"),[H,U]=useState(false),[M,ne]=useState(null),[T,h]=useState(""),[G,oe]=useState(""),[I,ie]=useState(""),[re,V]=useState(false),u=e=>{let d=new Date().toISOString().split("T")[0];return `${S?S.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"privacy-policy"}-privacy-policy-${d}.${e.toLowerCase()}`},f=e=>T?T.endsWith(`.${e.toLowerCase()}`)?T:`${T}.${e.toLowerCase()}`:u(e),x=()=>{let e=S?`${S} ${L}`:L,d=F?F.toLocaleDateString():"N/A",r=`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${e}</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
font-size: 24px;
margin-bottom: 10px;
}
h2 {
font-size: 20px;
margin-top: 30px;
margin-bottom: 10px;
border-bottom: 1px solid #eee;
padding-bottom: 5px;
}
h3 {
font-size: 18px;
margin-top: 20px;
margin-bottom: 10px;
}
p {
margin-bottom: 15px;
}
.header {
text-align: center;
margin-bottom: 30px;
}
.footer {
margin-top: 50px;
text-align: center;
font-size: 12px;
color: #666;
border-top: 1px solid #eee;
padding-top: 20px;
}
.logo {
max-width: 200px;
margin-bottom: 20px;
}
.last-updated {
font-size: 12px;
color: #666;
margin-bottom: 30px;
}
.compliance-notice {
background-color: #f8f9fa;
border: 1px solid #e9ecef;
padding: 15px;
margin-bottom: 30px;
font-size: 14px;
}
${Z||""}
</style>
</head>
<body>
<div class="header">
${y&&B?`<img src="${B}" alt="${S||"Company"} Logo" class="logo">`:""}
${G?`<div class="custom-header">${G}</div>`:""}
<h1>${e}</h1>
<div class="last-updated">Last Updated: ${d}</div>
</div>`;t&&(r+=`
<div class="compliance-notice">
<strong>NDPA Compliance Notice:</strong> This privacy policy has been created to comply with the Nigeria Data Protection Act (NDPA) 2023.
It outlines how we collect, use, disclose, and protect your personal information in accordance with NDPA requirements.
</div>`);let O=E.replace(/^## (.*?)$/gm,"<h2>$1</h2>").replace(/^### (.*?)$/gm,"<h3>$1</h3>").replace(/\n\n/g,"</p><p>").replace(/\n/g,"<br>");return r+=`
<div class="content">
<p>${O}</p>
</div>
<div class="footer">
${I?`<div class="custom-footer">${I}</div>`:""}
<p>© ${new Date().getFullYear()} ${S||"Company"}. All rights reserved.</p>
</div>
</body>
</html>`,r},C=()=>d$1(null,null,function*(){U(true),ne(null);try{let e=$.toLowerCase(),d="",r;switch(e){case "pdf":let J=x();r=new Blob([J],{type:"text/html"}),d=URL.createObjectURL(r);break;case "docx":r=new Blob([E],{type:"text/plain"}),d=URL.createObjectURL(r);break;case "html":let _=x();r=new Blob([_],{type:"text/html"}),d=URL.createObjectURL(r);break;default:r=new Blob([E],{type:"text/markdown"}),d=URL.createObjectURL(r);break}let O=f(e),j=document.createElement("a");j.href=d,j.download=O,document.body.appendChild(j),j.click(),document.body.removeChild(j);let le={id:`export_${Date.now()}`,format:e,timestamp:Date.now(),url:d,filename:O};g(J=>[le,...J]),A&&A(e,d);}catch(e){console.error("[ndpr-toolkit/policy] Export failed:",e);let d=e instanceof Error&&e.message?e.message.length>200?`${e.message.slice(0,200)}\u2026`:e.message:null;ne(d?`[ndpr-toolkit/policy] Export failed: ${d}`:"[ndpr-toolkit/policy] Export failed \u2014 see the browser console for the underlying error.");}finally{U(false);}}),W=()=>{let e=[{value:"pdf",label:"PDF Document (.pdf)"},{value:"docx",label:"Word Document (.docx)"},{value:"html",label:"Web Page (.html)"},{value:"markdown",label:"Markdown (.md)"}],d=`${b}-export-format`;return jsxs("div",{"data-ndpr-component":"policy-exporter",className:a("mb-6",l==null?void 0:l.formatSelector,i),children:[jsx("label",{htmlFor:d,className:"ndpr-form-field__label",children:"Export Format"}),jsx("select",{id:d,value:$,onChange:r=>X(r.target.value),className:a("ndpr-form-field__input",l==null?void 0:l.formatOption,i),children:e.map(r=>jsx("option",{value:r.value,children:r.label},r.value))})]})},de=()=>re?jsxs("div",{className:"mb-6 space-y-4 border border-gray-200 dark:border-gray-700 rounded-md p-4",children:[jsxs("div",{className:"flex justify-between items-center",children:[jsx("h3",{className:"text-md font-medium",children:"Advanced Export Options"}),jsx("button",{type:"button",onClick:()=>V(false),className:"ndpr-text-primary text-sm",children:"Hide Advanced Options"})]}),jsxs("div",{children:[jsx("label",{htmlFor:`${b}-custom-filename`,className:"ndpr-form-field__label",children:"Custom Filename"}),jsx("input",{type:"text",id:`${b}-custom-filename`,value:T,onChange:e=>h(e.target.value),placeholder:u($),"aria-describedby":`${b}-custom-filename-desc`,className:"ndpr-form-field__input"}),jsx("p",{id:`${b}-custom-filename-desc`,className:"ndpr-form-field__hint",children:"Leave blank to use the default filename format."})]}),jsxs("div",{children:[jsx("label",{htmlFor:`${b}-custom-header`,className:"ndpr-form-field__label",children:"Custom Header HTML (for HTML/PDF exports)"}),jsx("textarea",{id:`${b}-custom-header`,value:G,onChange:e=>oe(e.target.value),rows:3,placeholder:"<div>Custom header content</div>",className:"ndpr-form-field__input"})]}),jsxs("div",{children:[jsx("label",{htmlFor:`${b}-custom-footer`,className:"ndpr-form-field__label",children:"Custom Footer HTML (for HTML/PDF exports)"}),jsx("textarea",{id:`${b}-custom-footer`,value:I,onChange:e=>ie(e.target.value),rows:3,placeholder:"<div>Custom footer content</div>",className:"ndpr-form-field__input"})]}),jsxs("div",{className:"flex items-start",children:[jsx("div",{className:"flex items-center h-5",children:jsx("input",{id:`${b}-include-compliance-notice`,type:"checkbox",checked:t,onChange:e=>V(e.target.checked),"aria-describedby":`${b}-compliance-notice-desc`,className:"w-4 h-4 text-[rgb(var(--ndpr-primary))] border-gray-300 rounded focus:ring-[rgb(var(--ndpr-ring))] dark:focus:ring-[rgb(var(--ndpr-ring))] dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"})}),jsxs("div",{className:"ml-3 text-sm",children:[jsx("label",{htmlFor:`${b}-include-compliance-notice`,className:"font-medium ndpr-text-foreground",children:"Include NDPA Compliance Notice"}),jsx("p",{id:`${b}-compliance-notice-desc`,className:"ndpr-card__subtitle",children:"Adds a notice explaining that this policy complies with NDPA requirements."})]})]})]}):jsx("button",{type:"button",onClick:()=>V(true),className:"ndpr-text-primary text-sm mb-6",children:"Show Advanced Options"}),ae=()=>!Q||k.length===0?null:jsxs("div",{className:a("mt-6",l==null?void 0:l.preview,i),children:[jsx("h3",{className:"text-lg font-medium mb-3",children:"Export History"}),jsx("div",{className:"bg-gray-50 dark:bg-gray-700 rounded-md overflow-hidden",children:jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-600",children:[jsx("thead",{className:"bg-gray-100 dark:bg-gray-800",children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"px-6 py-3 text-left text-xs font-medium ndpr-text-muted uppercase tracking-wider",children:"Date"}),jsx("th",{scope:"col",className:"px-6 py-3 text-left text-xs font-medium ndpr-text-muted uppercase tracking-wider",children:"Format"}),jsx("th",{scope:"col",className:"px-6 py-3 text-left text-xs font-medium ndpr-text-muted uppercase tracking-wider",children:"Filename"}),jsx("th",{scope:"col",className:"px-6 py-3 text-left text-xs font-medium ndpr-text-muted uppercase tracking-wider",children:"Actions"})]})}),jsx("tbody",{className:"bg-white dark:bg-gray-700 divide-y divide-gray-200 dark:divide-gray-600",children:k.map(e=>jsxs("tr",{children:[jsx("td",{className:"ndpr-table__cell",children:new Date(e.timestamp).toLocaleString()}),jsx("td",{className:"ndpr-table__cell",children:e.format.toUpperCase()}),jsx("td",{className:"ndpr-table__cell",children:e.filename}),jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:jsx("a",{href:e.url,download:e.filename,className:"ndpr-text-primary hover:text-[rgb(var(--ndpr-primary-hover))] dark:hover:text-[rgb(var(--ndpr-primary-hover))] mr-4",children:"Download"})})]},e.id))})]})})]});return jsxs("div",{className:a(`bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md ${Y}`,l==null?void 0:l.root,i),children:[jsxs("div",{className:a("mb-6",l==null?void 0:l.header,i),children:[jsx("h2",{className:a("ndpr-section-heading",l==null?void 0:l.title,i),children:N}),jsx("p",{className:a("ndpr-card__subtitle",l==null?void 0:l.description,i),children:ee})]}),W(),de(),jsxs("div",{className:"mb-6",children:[jsx("button",{onClick:C,disabled:H,className:a(`px-6 py-3 bg-[rgb(var(--ndpr-primary))] text-white rounded-md hover:bg-[rgb(var(--ndpr-primary-hover))] focus:outline-none focus:ring-2 focus:ring-[rgb(var(--ndpr-ring))] focus:ring-offset-2 ${q} ${H?"opacity-70 cursor-not-allowed":""}`,(l==null?void 0:l.primaryButton)||(l==null?void 0:l.exportButton),i),children:H?"Exporting...":`Export as ${$.toUpperCase()}`}),M&&jsx("p",{className:"mt-2 text-sm ndpr-text-destructive dark:text-red-500",children:M})]}),jsxs("div",{className:a("ndpr-alert ndpr-alert--info",l==null?void 0:l.complianceNotice,i),children:[jsx("h3",{className:"text-sm font-bold ndpr-text-info mb-2",children:"Export Tips"}),jsxs("ul",{className:"ndpr-text-info text-sm list-disc list-inside space-y-1",children:[jsx("li",{children:"PDF format is recommended for printing or sharing with stakeholders."}),jsx("li",{children:"HTML format is ideal for publishing on your website."}),jsx("li",{children:"DOCX format allows for further editing in Microsoft Word or similar applications."}),jsx("li",{children:"Markdown format is useful for version control systems or technical documentation."})]})]}),ae()]})};export{Ee as a,Ie as b,Me as c};