import{y as nt,l as re,w as ae,m as _e,u as Ie,k as dt,n as Ee,o as Ne,r as c,j as e,v as w,B as J,I as ke,aS as lt,t as ge,b4 as He,b5 as La,az as At,F as mt,b6 as Rt,aJ as vr,aK as Qe,aL as Ge,aM as We,aN as Ye,b7 as jr,aR as sa,aF as lr,b8 as be,aP as _a,b9 as Da,ba as Ia,aU as $a,R as pe,aI as za,a as qa,d as Ba,bb as Xt,bc as Ua}from"./index-7T7TTikv.js";import{C as Ke,a as it,b as ot,c as ia,d as pt}from"./card-_ldW-koX.js";import{L as Ce}from"./label-CABYEcfW.js";import{p as oa}from"./presignedAxios-BChDCNPv.js";import{P as ct}from"./plus-CC3ol2sL.js";import{T as la,a as ca,b as Ze,c as Ve,d as da,e as Te}from"./table-D_B7hhqb.js";import{S as ft,a as ht,b as xt,c as yt,d as bt}from"./select--i8koVXg.js";import{u as ua,C as Ha}from"./index.esm-BRNlF2G3.js";import{T as Ka,u as Va}from"./useTemplate-YHjX1fxO.js";import{S as et}from"./skeleton-BCpLdfqO.js";import{A as Bt,a as Ut,b as Ht,c as Kt,d as Vt,e as Qt,f as Gt,g as Wt}from"./alert-dialog-DwppaTz4.js";import{E as Qa}from"./eye-DYwZYJcQ.js";import{S as Ga}from"./square-pen-Dh1zj83N.js";import{C as ma}from"./chevron-left-G_a9-f9o.js";import{p as Pe,u as Wa}from"./useUnitConfiguration-BYTU44Fr.js";import{P as wr}from"./pencil-cYosDPxl.js";import{u as Ya}from"./useUnit-CRt6YBLp.js";import{u as Er}from"./useSettings-CvxIOArb.js";import{M as Xa}from"./multi-select-CZLBnGmP.js";import{u as Ja}from"./usePosition-B4V039Jv.js";import{S as Za}from"./single-select-CqAjmX3L.js";import{P as en,a as tn,b as rn}from"./popover-CSKEA8hg.js";import{B as cr}from"./badge-D4t6Wb1T.js";import{C as an,a as nn,b as sn,c as on,d as ln,e as cn}from"./command-B6S1IvD4.js";import{C as dn}from"./circle-alert-HVqsZpe-.js";import{A as un}from"./AdvancedTable-vWyUWUDX.js";import{u as mn,o as gn,s as Lt}from"./zod-D-9d3Txu.js";import{F as pn,a as Jt,b as Zt,c as er,d as tr,e as rr}from"./form-lLGtsTgY.js";import{f as fn}from"./format-DvwV82px.js";import{X as hn}from"./XSSUploadValidator-BMXKraj-.js";import{L as kr}from"./loader-CLp1W4Fa.js";import{A as xn}from"./arrow-left-mae9HpSL.js";import{B as yn}from"./building-BTGMe3qn.js";import"./Utils-BP0IYDrC.js";import"./Skeleton-BOu0YqbY.js";import"./unitService-DTtkt-Pb.js";import"./organizationService-B_C-b9EH.js";import"./separator-BXi_hr72.js";import"./positionService-BwPU5sNe.js";import"./Popover-BSKEfTKH.js";import"./use-uncontrolled-tg0LIUAX.js";import"./search-y8VSu0lZ.js";import"./utils-N2wtfq7C.js";import"./refresh-cw-B7fipPS4.js";import"./en-US-Cc-9gH5A.js";/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const bn=[["path",{d:"m20 13.7-2.1-2.1a2 2 0 0 0-2.8 0L9.7 17",key:"q6ojf0"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}],["circle",{cx:"10",cy:"8",r:"2",key:"2qkj4p"}]],vn=nt("book-image",bn);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const jn=[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]],wn=nt("chevrons-up-down",jn);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const kn=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M9 12v-1h6v1",key:"iehl6m"}],["path",{d:"M11 17h2",key:"12w5me"}],["path",{d:"M12 11v6",key:"1bwqyc"}]],Nn=nt("clipboard-type",kn);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Sn=[["path",{d:"M13 7 8.7 2.7a2.41 2.41 0 0 0-3.4 0L2.7 5.3a2.41 2.41 0 0 0 0 3.4L7 13",key:"orapub"}],["path",{d:"m8 6 2-2",key:"115y1s"}],["path",{d:"m18 16 2-2",key:"ee94s4"}],["path",{d:"m17 11 4.3 4.3c.94.94.94 2.46 0 3.4l-2.6 2.6c-.94.94-2.46.94-3.4 0L11 17",key:"cfq27r"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Cn=nt("pencil-ruler",Sn);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Pn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M17 12h-2l-2 5-2-10-2 5H7",key:"15hlnc"}]],Tn=nt("square-activity",Pn);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const En=[["path",{d:"M5 22h14",key:"ehvnwv"}],["path",{d:"M19.27 13.73A2.5 2.5 0 0 0 17.5 13h-11A2.5 2.5 0 0 0 4 15.5V17a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-1.5c0-.66-.26-1.3-.73-1.77Z",key:"1sy9ra"}],["path",{d:"M14 13V8.5C14 7 15 7 15 5a3 3 0 0 0-3-3c-1.66 0-3 1-3 3s1 2 1 3.5V13",key:"cnxgux"}]],ga=nt("stamp",En);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const An=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],Rn=nt("tag",An);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Mn=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],On=nt("triangle-alert",Mn),Je={createSeal:async t=>re.post("/seals",t,{headers:ae()}),getSeals:async()=>re.get("/seals",{headers:ae()}),getSeal:async t=>re.get(`/seals/${t}`,{headers:ae()}),getSealListsByUnitId:async t=>re.get(`/seals/list/${t}`,{headers:ae()}),updateSeal:async(t,r)=>re.put(`/seals/${t}`,r,{headers:ae()}),deleteSeal:async t=>re.delete(`/seals/${t}`,{headers:ae()}),changeSealStatus:async(t,r)=>re.put(`/seals/change-status/${t}`,r,{headers:ae()}),updateSealUploadStatus:async(t,r)=>re.patch(`/seals/${t}/upload-status`,r,{headers:ae()})},Fn=()=>{const t=_e(),{t:r}=Ie(),{handleError:a}=dt(r),{data:n,isLoading:s,isError:i,refetch:o}=Ee({queryKey:["seals"],queryFn:async()=>(await Je.getSeals()).data,enabled:!1}),d=x=>Ee({queryKey:["seal",x],queryFn:async()=>{if(x)return(await Je.getSealListsByUnitId(x)).data},enabled:!!x}),m=x=>Ee({queryKey:["seal",x],queryFn:async()=>{if(x)return(await Je.getSeal(x)).data},enabled:!!x}),l=Ne({mutationFn:async x=>(await Je.createSeal(x)).data,onSuccess:()=>{t.invalidateQueries({queryKey:["seals"]})},onError:x=>{a(x)}}),f=Ne({mutationFn:async({id:x,payload:v})=>(await Je.updateSeal(x,v)).data,onSuccess:()=>{t.invalidateQueries({queryKey:["seal"]})},onError:x=>{a(x)}}),y=Ne({mutationFn:async x=>{await Je.changeSealStatus(x,{isCurrent:!1})},onSuccess:()=>{t.invalidateQueries({queryKey:["seals"]})},onError:x=>{a(x)}}),g=Ne({mutationFn:async({id:x,updateSealStatusPayload:v})=>(await Je.updateSealUploadStatus(x,v)).data,onSuccess:()=>{t.invalidateQueries({queryKey:["seals"]})},onError:x=>{a(x)}});return{seals:(n==null?void 0:n.items)||[],totalSeals:(n==null?void 0:n.count)||0,isLoadingSeals:s,isSealsError:i,refetchSeals:o,getSealsByUnitId:d,getSealsById:m,createSeal:l.mutateAsync,isCreatingSeal:l.isPending,updateSeal:f.mutate,isUpdatingSeal:f.isPending,deleteSeal:y.mutate,isDeletingSeal:y.isPending,updateSealStatus:g.mutateAsync,isUpdatingStatus:g.isPending}},Ln=({unitId:t})=>{const{createSeal:r,isCreatingSeal:a,isLoadingSeals:n,deleteSeal:s,getSealsByUnitId:i}=Fn(),[o,d]=c.useState(),[m,l]=c.useState([]),f=c.useRef(null),y=_e(),[g,x]=c.useState(0),[v,p]=c.useState(!1),[j,E]=c.useState(""),[b,k]=c.useState(""),N=1*1024*1024,{data:u}=i(t);c.useEffect(()=>{let $=!0;return(async()=>{if(!(u!=null&&u.items))return;const _=u.items.filter(W=>W.uploadedSuccessfully&&W.isCurrent),X=(await Promise.all(_.map(async W=>{try{const ie=(await Je.getSeal(W.id)).data.presigned;return ie?{type:"seal",file:new File([],W.fileInfo.fileName),url:ie,uploadedAt:new Date(W.createdAt),id:W.id}:null}catch{return null}}))).filter(W=>W!==null);$&&l(X)})(),()=>{$=!1,m.forEach(_=>{!_.id&&_.url.startsWith("blob:")&&URL.revokeObjectURL(_.url)})}},[u==null?void 0:u.items]);const C=$=>{if($.type!=="image/png"){ge.error(w("contentManagement.onlyPngAllowed"));return}if($.size>N){ge.error("Image size should be less than 1 MB");return}const F=URL.createObjectURL($),_=new Image;_.onload=()=>{if(_.width!==_.height){ge.error(w("contentManagement.onlySquareAllowed")),URL.revokeObjectURL(F);return}d($),E(""),k(""),l([{type:"seal",url:F,file:$,uploadedAt:new Date,id:null}])},_.onerror=()=>{ge.error(w("contentManagement.invalidImage")),URL.revokeObjectURL(F)},_.src=F},M=async()=>{if(!o){ge.error(w("contentManagement.noFileSelected"));return}if(!j.trim()){k(w("contentManagement.sealNameMsg"));return}try{const $={fileInfo:{fileName:o.name,contentType:o.type,size:o.size,originalname:o.name},name:{am:j,en:j},unitId:t},F=await r($);p(!0),x(0),await oa.put(F.presigned,o,{headers:{"Content-Type":o.type}}),p(!1),x(100),d(void 0),E(""),k(""),f.current&&(f.current.value=""),y.invalidateQueries({queryKey:["seal"]}),ge.success(w("contentManagement.sealSuccessMsg"))}catch{ge.error(w("contentManagement.sealErrorMsg")),p(!1),x(0),d(void 0)}},I=async $=>{if($)try{await s($),l(F=>F.filter(_=>_.id!==$)),ge.success(w("contentManagement.sealRemove"))}catch{ge.error(w("contentManagement.sealRemove"))}},se=$=>new Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"numeric",hour12:!0,month:"short",day:"numeric"}).format($),Y=a||v;return e.jsxs(Ke,{className:"dark:border-gray-700 dark:bg-gray-800",children:[e.jsxs(it,{children:[e.jsxs(ot,{className:"flex items-center dark:text-white",children:[e.jsx(ga,{className:"h-5 w-5 mr-2"}),w("contentManagement.seal")]}),e.jsxs(ia,{className:"dark:text-gray-400",children:[w("contentManagement.uploadSealMsg")," (PNG, max 1MB)"]})]}),e.jsxs(pt,{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(Ce,{htmlFor:"seal",className:"dark:text-gray-200",children:w("contentManagement.sealImage")}),e.jsxs(J,{variant:"outline",className:"bg-primary hover:bg-primary/90 text-primary-foreground",onClick:()=>{var $;return($=f.current)==null?void 0:$.click()},disabled:Y,children:[e.jsx(ct,{className:"h-4 w-4 mr-2"}),w("contentManagement.addSeal")]})]}),e.jsx(ke,{ref:f,type:"file",accept:".png,image/png",className:"hidden",onChange:$=>{var F;return((F=$.target.files)==null?void 0:F[0])&&C($.target.files[0])},disabled:Y}),m.length>0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:m.map($=>e.jsxs("div",{className:"border rounded-lg p-3 bg-gray-50 dark:bg-gray-700 dark:border-gray-600",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground dark:text-gray-400",children:se($==null?void 0:$.uploadedAt)}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>I(($==null?void 0:$.id)||null),className:"text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-900/30",disabled:n,children:e.jsx(lt,{className:"h-4 w-4 text-red-500"})})]}),e.jsx("img",{src:$.url,alt:"Seal",className:"max-h-32 mx-auto object-contain"})]},($==null?void 0:$.id)||($==null?void 0:$.url)))}):e.jsxs("div",{className:"text-center p-4 border border-dashed rounded-lg dark:border-gray-600 dark:bg-gray-700/30",children:[e.jsx("p",{className:"text-muted-foreground dark:text-gray-400",children:w("contentManagement.noSealMsg")}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-gray-500 mt-1",children:w("contentManagement.addSealInstruction")})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ce,{htmlFor:"sealName",className:"dark:text-gray-200",children:w("contentManagement.sealName")}),e.jsx(ke,{value:j,onChange:$=>{E($.target.value),k("")},placeholder:"Enter seal name",className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"}),b&&e.jsx("p",{className:"text-sm text-red-500",children:b})]}),o&&e.jsxs(J,{className:"w-full bg-primary hover:bg-primary/90",onClick:M,disabled:Y||!o,children:[a&&"Creating seal...",v&&`Uploading ${g}%`,!Y&&w("contentManagement.saveSeal")]})]})]})},_n=async(t,r)=>He.get(`/record-templates/list/${t}`,{headers:ae(),params:r}),Dn=async t=>He.get(`/record-templates/${t}`,{headers:ae()}),In=async t=>He.post("/record-templates",t,{headers:ae()}),$n=async(t,r)=>He.put(`/record-templates/${t}`,r,{headers:ae()}),zn=async t=>He.delete(`/record-templates/${t}`,{headers:ae()}),qn=(t,r={})=>{const a=_e(),{skip:n=0,take:s=20,orderBy:i="createdAt:DESC",order:o,enabled:d=!0}=r,m={skip:n,take:s,orderBy:i,...o?{order:o}:{}},{data:l,isLoading:f,isFetching:y,isError:g,refetch:x}=Ee({queryKey:["letter-templates",t,m],queryFn:async()=>{const{data:C}=await _n(t,m);return C},enabled:!!t&&d,staleTime:300*1e3,retry:!1,placeholderData:La}),{mutate:v,isPending:p}=Ne({mutationFn:async C=>{const{data:M}=await Dn(C);return M}}),{mutate:j,isPending:E}=Ne({mutationFn:async C=>{const{data:M}=await In(C);return M},onSuccess:(C,M)=>{a.invalidateQueries({queryKey:["letter-templates",M.unitId]})}}),{mutate:b,isPending:k}=Ne({mutationFn:async C=>{const{data:M}=await $n(C.id,C.data);return M},onSuccess:(C,M)=>{a.invalidateQueries({queryKey:["letter-templates",M.data.unitId]}),a.invalidateQueries({queryKey:["letter-template",M.id]})}}),{mutate:N,isPending:u}=Ne({mutationFn:async({id:C})=>{await zn(C)},onSuccess:()=>{a.invalidateQueries({queryKey:["letter-templates",t]})}});return{letterTemplatesResponse:l,items:(l==null?void 0:l.items)??[],count:(l==null?void 0:l.count)??0,isLoading:f,isFetching:y,isError:g,refetch:x,getTemplateByDetails:v,isFetchingTemplate:p,createLetterTemplate:j,isCreating:E,updateLetterTemplate:b,isUpdating:k,deleteLetterTemplate:N,isDeleting:u}},Bn={signature:{uploadKey:"/signatures/get-file-upload-key",create:"/signatures",parentField:"employeeId"},stamp:{uploadKey:"/employee-stamps/get-file-upload-key",create:"/employee-stamps",parentField:"employeePositionId"},header:{uploadKey:"/headers/get-file-upload-key",create:"/headers",parentField:"unitId"},footer:{uploadKey:"/footers/get-file-upload-key",create:"/footers",parentField:"unitId"}};async function Un(t,r,a,n,s){const i={fileName:r.name,originalname:r.name,contentType:r.type||"application/octet-stream",size:r.size,...n!=null&&n.length?{positionId:n}:{},recordTypeKey:s},{data:o}=await a.post(t,i,{headers:ae()});return o}async function Hn(t,r){if(!r)throw new Error("Presigned URL is required");const a=await oa.put(r,t,{headers:{"Content-Type":t.type}});if(a.status<200||a.status>=300)throw new Error(`Upload failed with status ${a.status}: ${a.statusText}`)}async function Ar(t,r,a,n){const{type:s,file:i,name:o,parentId:d}=t,m=Bn[s],l=await Un(m.uploadKey,i,r,a,n),f=l.presignedUrl||l.presigned;if(await Hn(i,f||""),s==="header"||s==="footer"){const x={fileInfo:l.fileInfo,name:o,[m.parentField]:d,positionIds:a,isCurrent:!0,recordTypeKey:n},{data:v}=await r.post(m.create,x,{headers:ae()});return v}const y={fileInfo:l.fileInfo,name:o,[m.parentField]:d,...s==="signature"?{isCurrent:!0}:{}},{data:g}=await r.post(m.create,y,{headers:ae()});return g}const Me={uploadAndCreateHeader:(t,r,a,n,s)=>Ar({type:"header",file:t,name:{am:r,en:r},parentId:a},re,n,s),uploadAndCreateFooter:(t,r,a,n,s)=>Ar({type:"footer",file:t,name:{am:r,en:r},parentId:a},re,n,s),createHeader:async t=>re.post("/headers",t,{headers:ae()}),getHeaders:async()=>re.get("/headers",{headers:ae()}),getHeadersByUnitId:async(t,r,a)=>re.get(`/headers/list/${t}?take=100${r?`&positionId=${r}`:""}${a?`&recordTypeKey=${a}`:""}`,{headers:ae()}),getHeaderById:async t=>re.get(`/headers/${t}`,{headers:ae()}),updateHeader:async(t,r)=>re.put(`/headers/${t}`,r,{headers:ae()}),deleteHeader:async t=>re.delete(`/headers/${t}`,{headers:ae()}),updateHeaderUploadStatus:async(t,r)=>re.patch(`/headers/${t}/upload-status`,r,{headers:ae()}),changeHeaderStatus:async(t,r)=>re.put(`/headers/change-status/${t}`,r,{headers:ae()}),createFooter:async t=>re.post("/footers",t,{headers:ae()}),getFooters:async()=>re.get("/footers",{headers:ae()}),getFootersByUnitId:async(t,r,a)=>re.get(`/footers/list/${t}?take=300${r?`&positionId=${r}`:""}${a?`&recordTypeKey=${a}`:""}`,{headers:ae()}),getFooterById:async t=>re.get(`/footers/${t}`,{headers:ae()}),updateFooter:async(t,r)=>re.put(`/footers/${t}`,r,{headers:ae()}),deleteFooter:async t=>re.delete(`/footers/${t}`,{headers:ae()}),updateFooterUploadStatus:async(t,r)=>re.patch(`/footers/${t}/upload-status`,r,{headers:ae()}),changeFooterStatus:async(t,r)=>re.put(`/footers/change-status/${t}`,r,{headers:ae()})},pa=(t,r,a)=>Ee({queryKey:["headers-footers",t,r,a],queryFn:async()=>{const[n,s]=await Promise.all([Me.getHeadersByUnitId(t,r,a),Me.getFootersByUnitId(t,r,a)]),i=n.data.items.filter(f=>f.isCurrent&&f.uploadedSuccessfully),o=s.data.items.filter(f=>f.isCurrent&&f.uploadedSuccessfully),d=async(f,y)=>Promise.all(f.map(async g=>{try{const x=y==="header"?await Me.getHeaderById(g.id):await Me.getFooterById(g.id);return{...g,presigned:x.data.presigned}}catch{return g}})),m=await d(i,"header"),l=await d(o,"footer");return{headers:m,footers:l}},enabled:!!t,staleTime:600*1e3}),Rr=({unitId:t,template:r,isSubmitting:a,onCancel:n,onSubmitCreate:s})=>{var g,x,v,p;const{register:i,handleSubmit:o,reset:d,control:m,formState:{errors:l}}=ua({defaultValues:{name:{en:((g=r==null?void 0:r.name)==null?void 0:g.en)??"",am:((x=r==null?void 0:r.name)==null?void 0:x.am)??""},key:(r==null?void 0:r.key)??"",subject:(r==null?void 0:r.subject)??"",body:(r==null?void 0:r.body)??"",sincerelyText:(r==null?void 0:r.sincerelyText)??"",unitId:t}}),{data:f}=pa(t);c.useMemo(()=>(f==null?void 0:f.headers)||[],[f==null?void 0:f.headers]),c.useMemo(()=>(f==null?void 0:f.footers)||[],[f==null?void 0:f.footers]);const y=j=>{s(j),r||d()};return e.jsxs("form",{onSubmit:o(y),className:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg p-8 shadow-sm space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Template Key"}),e.jsx(ke,{placeholder:"Template Key",...i("key",{required:"Template key is required"})}),l.key&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:l.key.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Subject"}),e.jsx(ke,{placeholder:"Subject",...i("subject",{required:"Subject is required"})}),l.subject&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:l.subject.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"English Name"}),e.jsx(ke,{placeholder:"English Name",...i("name.en",{required:"English name is required"})}),((v=l.name)==null?void 0:v.en)&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:l.name.en.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Amharic Name"}),e.jsx(ke,{placeholder:"Amharic Name",...i("name.am",{required:"Amharic name is required"})}),((p=l.name)==null?void 0:p.am)&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:l.name.am.message})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Body"}),e.jsx(Ha,{name:"body",control:m,rules:{required:!0},render:({field:j,fieldState:E})=>e.jsxs(e.Fragment,{children:[e.jsx(Ka,{value:j.value,onEditorChange:j.onChange,placeholders:[{key:"delegatorName",label:"Delegator Name"},{key:"delegatorDepartment",label:"Delegator Department"},{key:"delegateeName",label:"Delegatee Name"},{key:"delegateeDepartment",label:"Delegatee Department"},{key:"startDate",label:"Start Date"},{key:"endDate",label:"End Date"},{key:"startDateTime",label:"Start Date & Time"},{key:"endDateTime",label:"End Date & Time"}]}),E.invalid&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:"Body is required"})]})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Sincerely Text"}),e.jsx(ke,{placeholder:"Sincerely Text",...i("sincerelyText")})]}),e.jsxs("div",{className:"flex gap-2 pt-4 justify-end",children:[e.jsx(J,{type:"submit",disabled:a,children:a?"Saving...":r?"Update":"Save"}),e.jsx(J,{type:"button",variant:"outline",onClick:n,children:"Cancel"})]})]})},Kn=({unitId:t})=>{var ze,Se,H,ue;const{t:r}=Ie(),{handleError:a}=dt(r),[n,s]=c.useState(0),[i,o]=c.useState(10),{letterTemplatesResponse:d,count:m,isLoading:l,isFetching:f,isError:y,refetch:g,createLetterTemplate:x,updateLetterTemplate:v,deleteLetterTemplate:p,isCreating:j,isUpdating:E,isDeleting:b}=qn(t,{skip:n*i,take:i}),k=Math.max(1,Math.ceil(m/i)),{templates:N,isLoading:u,adoptTemplate:C,isAdoptingTemplate:M}=Va(),{data:I}=Ee({queryKey:["headers",t],queryFn:()=>Me.getHeadersByUnitId(t)}),{data:se}=Ee({queryKey:["footers",t],queryFn:()=>Me.getFootersByUnitId(t)}),Y=At(),[$,F]=c.useState(!1),[_,ne]=c.useState(!1),[X,W]=c.useState(!1),[xe,ie]=c.useState(!1),[Ae,je]=c.useState(!1),[z,O]=c.useState(null),[R,L]=c.useState(""),[T,h]=c.useState(""),U=z?Y(z.name):"",P=l||u,Z=y,ee=Array.isArray(N)?N:(N==null?void 0:N.items)||[],te=(d==null?void 0:d.items)||[],q=[...ee.map(D=>({...D,isGlobal:!0})),...te.map(D=>({...D,isGlobal:!1}))],de=D=>{const we=D.target;we!=null&&we.closest(".tox-tinymce-aux, .moxman-window, .tam-assetmanager-root")&&D.preventDefault()},fe=D=>{x(D,{onSuccess:we=>{ge.success(`${Y(we.name)} ${r("contentManagement.templateSuccessMsg")}`),g(),F(!1)},onError:we=>{a(we)}})},Q=D=>{z&&v({id:z.id,data:D},{onSuccess:()=>{ge.success(r("contentManagement.updateTemplate")),g(),ne(!1),O(null)},onError:we=>{a(we)}})},le=()=>{z&&p({id:z.id},{onSuccess:()=>{ge.success(r("contentManagement.deleteTemplate")),g(),ie(!1),O(null)},onError:D=>{a(D)}})},G=()=>{if(!z||!R||!T){ge.error(r("contentManagement.pleaseSelectHeaderAndFooter","Please select header and footer"));return}C({templateId:z.id,headerId:R,footerId:T},{onSuccess:()=>{ge.success(r("contentManagement.adoptSuccess","Successfully adopted global template")),g(),je(!1),O(null),L(""),h("")},onError:D=>{a(D)}})},oe=D=>{O(D),ne(!0)},Re=D=>{O(D),W(!0)},ye=D=>{O(D),ie(!0)},$e=D=>{O(D),je(!0)};return P?e.jsxs(Ke,{children:[e.jsx(it,{children:e.jsxs(ot,{className:"flex items-center",children:[e.jsx(mt,{className:"h-5 w-5 mr-2"}),r("contentManagement.letterTemplate")]})}),e.jsx(pt,{children:e.jsx("div",{className:"space-y-3",children:Array(3).fill(0).map((D,we)=>e.jsx(et,{className:"h-12 w-full"},we))})})]}):Z?e.jsxs(Ke,{children:[e.jsx(it,{children:e.jsxs(ot,{className:"flex items-center",children:[e.jsx(mt,{className:"h-5 w-5 mr-2"}),r("contentManagement.letterTemplate")]})}),e.jsx(pt,{children:e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:r("contentManagement.failedToLoadTemplates")})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{children:[e.jsx(it,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs(ot,{className:"flex items-center",children:[e.jsx(mt,{className:"h-5 w-5 mr-2"}),r("contentManagement.letterTemplate")]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:r("contentManagement.createMsg")})]}),e.jsxs(J,{onClick:()=>F(!0),size:"sm",className:"shrink-0",children:[e.jsx(ct,{className:"h-4 w-4 mr-1"}),r("contentManagement.addTemplate")]})]})}),e.jsx(pt,{children:q.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(mt,{className:"mx-auto mb-4 h-12 w-12 text-gray-400 dark:text-gray-500"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:r("contentManagement.noTemplates")})]}):e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs(la,{children:[e.jsx(ca,{children:e.jsxs(Ze,{children:[e.jsx(Ve,{className:"min-w-[150px]",children:r("common.name")}),e.jsx(Ve,{className:"min-w-[200px] hidden md:table-cell",children:r("contentManagement.sincerelyText")}),e.jsx(Ve,{className:"min-w-[120px] hidden sm:table-cell",children:r("common.createdDate")}),e.jsx(Ve,{className:"text-right min-w-[120px]",children:r("common.actions")})]})}),e.jsx(da,{children:q.map(D=>e.jsxs(Ze,{className:D.isGlobal?"bg-blue-50/50 hover:bg-blue-50 dark:bg-blue-950/30 dark:hover:bg-blue-900/40":"",children:[e.jsx(Te,{className:"font-medium",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[Y(D.name),D.isGlobal&&e.jsx("span",{className:"rounded bg-blue-100 px-2 py-0.5 text-[10px] font-semibold text-blue-700 dark:bg-blue-900/50 dark:text-blue-200",children:"Global"})]}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 md:hidden",children:D.sincerelyText&&D.sincerelyText.length>30?`${D.sincerelyText.substring(0,30)}...`:D.sincerelyText||r("common.notAvailable")})]})}),e.jsx(Te,{className:"max-w-xs truncate hidden md:table-cell",children:D.sincerelyText||r("common.notAvailable")}),e.jsx(Te,{className:"hidden sm:table-cell",children:D.createdAt?new Date(D.createdAt).toLocaleDateString():r("common.notAvailable")}),e.jsx(Te,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>Re(D),title:r("contentManagement.viewTemplate"),children:e.jsx(Qa,{className:"h-4 w-4"})}),D.isGlobal?e.jsx(J,{variant:"outline",size:"sm",onClick:()=>$e(D),title:r("contentManagement.adoptTemplate","Adopt Template"),className:"h-8 border-blue-200 px-3 text-blue-700 hover:bg-blue-100 hover:text-blue-800 dark:border-blue-700/60 dark:text-blue-300 dark:hover:bg-blue-900/40 dark:hover:text-blue-200",children:r("common.adopt","Adopt")}):e.jsxs(e.Fragment,{children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>oe(D),title:r("contentManagement.editTemplate"),children:e.jsx(Ga,{className:"h-4 w-4"})}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>ye(D),className:"text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300",title:r("contentManagement.deleteTemplate"),children:e.jsx(Rt,{className:"h-4 w-4"})})]})]})})]},D.id))})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:[r("common.page","Page")," ",n+1," / ",k,m>0&&e.jsxs(e.Fragment,{children:[" ","• ",m," ",r("contentManagement.letterTemplate","templates")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ft,{value:String(i),onValueChange:D=>{o(Number(D)),s(0)},children:[e.jsx(ht,{className:"h-8 w-[80px]",children:e.jsx(xt,{})}),e.jsx(yt,{children:[10,20,50,100].map(D=>e.jsx(bt,{value:String(D),children:D},D))})]}),e.jsxs(J,{variant:"outline",size:"sm",disabled:n===0||f,onClick:()=>s(D=>Math.max(0,D-1)),children:[e.jsx(ma,{className:"h-4 w-4"}),r("common.previous","Previous")]}),e.jsxs(J,{variant:"outline",size:"sm",disabled:n+1>=k||f,onClick:()=>s(D=>D+1),children:[r("common.next","Next"),e.jsx(vr,{className:"h-4 w-4"})]})]})]})]})})]}),e.jsx(Qe,{open:$,onOpenChange:F,children:e.jsxs(Ge,{className:"max-h-[90vh] w-full max-w-[95vw] overflow-y-auto lg:max-w-[1200px] dark:border-gray-700 dark:bg-gray-900",onInteractOutside:de,children:[e.jsx(We,{children:e.jsx(Ye,{children:r("contentManagement.createTemplate")})}),e.jsx(Rr,{unitId:t,isSubmitting:j,onCancel:()=>F(!1),onSubmitCreate:fe})]})}),e.jsx(Qe,{open:_,onOpenChange:ne,children:e.jsxs(Ge,{className:"max-h-[90vh] w-full max-w-[95vw] overflow-y-auto lg:max-w-[1200px] dark:border-gray-700 dark:bg-gray-900",onInteractOutside:de,children:[e.jsx(We,{children:e.jsx(Ye,{children:r("contentManagement.editTemplate")})}),e.jsx(Rr,{unitId:t,template:z,isSubmitting:E,onCancel:()=>{ne(!1),O(null)},onSubmitCreate:Q})]})}),e.jsx(Qe,{open:X,onOpenChange:W,children:e.jsxs(Ge,{className:"max-h-[90vh] w-full max-w-[95vw] overflow-y-auto lg:max-w-[1200px] dark:border-gray-700 dark:bg-gray-900",children:[e.jsx(We,{children:e.jsx(Ye,{children:r("contentManagement.viewTemplate")})}),z&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:r("common.name")}),e.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:Y(z.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:r("contentManagement.sincerelyText")}),e.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:z.sincerelyText||r("common.notAvailable")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:r("contentManagement.body")}),e.jsx("div",{className:"mt-1 max-h-60 overflow-y-auto rounded-md border bg-gray-50 p-3 text-sm text-gray-900 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100",dangerouslySetInnerHTML:{__html:z.body}})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(J,{onClick:()=>W(!1),children:r("common.close")})})]})]})}),e.jsx(Qe,{open:Ae,onOpenChange:je,children:e.jsxs(Ge,{className:"max-w-md dark:border-gray-700 dark:bg-gray-900",children:[e.jsx(We,{children:e.jsx(Ye,{children:r("contentManagement.adoptTemplate","Adopt Template")})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:r("contentManagement.selectHeader","Select Header")}),e.jsxs(ft,{value:R,onValueChange:L,children:[e.jsx(ht,{children:e.jsx(xt,{placeholder:r("contentManagement.selectHeader","Select Header")})}),e.jsx(yt,{children:(Se=(ze=I==null?void 0:I.data)==null?void 0:ze.items)==null?void 0:Se.map(D=>e.jsx(bt,{value:D.id,children:Y(D.name)},D.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:r("contentManagement.selectFooter","Select Footer")}),e.jsxs(ft,{value:T,onValueChange:h,children:[e.jsx(ht,{children:e.jsx(xt,{placeholder:r("contentManagement.selectFooter","Select Footer")})}),e.jsx(yt,{children:(ue=(H=se==null?void 0:se.data)==null?void 0:H.items)==null?void 0:ue.map(D=>e.jsx(bt,{value:D.id,children:Y(D.name)},D.id))})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{variant:"outline",onClick:()=>je(!1),children:r("common.cancel")}),e.jsx(J,{onClick:G,disabled:M||!R||!T,children:M?r("common.adopting","Adopting..."):r("common.adopt","Adopt")})]})]})}),e.jsx(Bt,{open:xe,onOpenChange:ie,children:e.jsxs(Ut,{children:[e.jsxs(Ht,{children:[e.jsx(Kt,{children:r("contentManagement.deleteTemplate")}),e.jsx(Vt,{children:r("contentManagement.deleteTemplateConfirm",{name:U}).replace("{{name}}",U).replace("{name}",U)})]}),e.jsxs(Qt,{children:[e.jsx(Gt,{children:r("common.cancel")}),e.jsx(Wt,{onClick:le,disabled:b,className:"bg-red-600 hover:bg-red-700",children:r(b?"common.deleting":"common.delete")})]})]})})]})},Vn=({activities:t})=>{const r=a=>new Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"numeric",hour12:!0,month:"short",day:"numeric"}).format(a);return e.jsxs(Ke,{className:"bg-gradient-to-br from-gray-50 to-slate-50 dark:from-gray-800 dark:to-gray-900 dark:border-gray-700",children:[e.jsxs(it,{children:[e.jsxs(ot,{className:"flex items-center dark:text-white",children:[e.jsx(mt,{className:"h-5 w-5 mr-2"}),"Recent Activities"]}),e.jsx(ia,{className:"dark:text-gray-400",children:"Recent content management activities"})]}),e.jsx(pt,{children:e.jsx("div",{className:"space-y-4",children:t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground dark:text-gray-400",children:"No recent activities."}):t.map(({id:a,type:n,description:s,timestamp:i})=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm font-medium capitalize dark:text-white",children:n}),e.jsx("span",{className:"text-sm dark:text-gray-300",children:s}),e.jsx("span",{className:"text-xs text-muted-foreground dark:text-gray-400",children:r(i)})]},a))})})]})},Qn=(t,r)=>Ee({queryKey:["remark",t,r],queryFn:async()=>(await Pe.getRemarkList(t,r)).data}),Gn=({unitId:t})=>{const[r,a]=c.useState(""),[n,s]=c.useState(""),[i,o]=c.useState(null),[d,m]=c.useState(!1),[l,f]=c.useState(!1),[y,g]=c.useState(null),[x,v]=c.useState(""),p=_e(),{data:j,isLoading:E}=Qn(t,{skip:0,take:300}),b=Ne({mutationFn:async()=>{if(!r)throw new Error(w("contentManagement.remarkRequired"));const M={unitId:t,remark:r,description:n};return i?Pe.editRemark(i,M):Pe.createRemark(M)},onSuccess:()=>{p.invalidateQueries({queryKey:["remark",t]}),N(),m(!1)},onError:M=>v(M.message||w("contentManagement.failed"))}),k=Ne({mutationFn:M=>Pe.deleteRemarks(M),onSuccess:()=>{p.invalidateQueries({queryKey:["remark",t]}),f(!1),g(null)},onError:()=>v(w("contentManagement.failedToDelete"))}),N=()=>{a(""),s(""),o(null),v("")},u=M=>{o(M.id),a(M.remark),s(M.description||""),m(!0)},C=()=>b.mutate();return e.jsxs(Ke,{className:"p-4 border shadow-sm space-y-4 dark:border-gray-700 dark:bg-gray-800",children:[e.jsxs(Qe,{open:d,onOpenChange:m,children:[e.jsx(jr,{asChild:!0,children:e.jsxs(J,{className:"w-[180px] bg-primary hover:bg-primary/90 text-primary-foreground flex items-center",children:[e.jsx(ct,{className:"h-4 w-4 mr-2"}),w("contentManagement.addRemark")]})}),e.jsxs(Ge,{className:"sm:max-w-xl w-full dark:bg-gray-800",children:[e.jsx(We,{children:e.jsx(Ye,{className:"dark:text-white",children:i?w("contentManagement.editRemark"):w("contentManagement.addRemark")})}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx(Ce,{htmlFor:"remark",className:"mb-1 dark:text-gray-200",children:w("header.Remark")}),e.jsx(ke,{id:"remark",value:r,onChange:M=>a(M.target.value),placeholder:w("header.Remark"),disabled:E,className:"w-full dark:bg-gray-700 dark:border-gray-600 dark:text-white"}),e.jsx(Ce,{htmlFor:"description",className:"mb-1 dark:text-gray-200",children:w("header.Description")}),e.jsx(ke,{id:"description",value:n,onChange:M=>s(M.target.value),placeholder:w("header.Description"),disabled:E,className:"w-full mb-2 dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]}),x&&e.jsx("p",{className:"text-sm text-red-500",children:x})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx(J,{variant:"outline",onClick:()=>{N(),m(!1)},children:w("common.Cancel")}),e.jsx(J,{onClick:C,disabled:E,className:"bg-primary hover:bg-primary/90 text-primary-foreground",children:E?w("contentManagement.saving"):i?w("delegation.update"):w("delegation.save")})]})]})]}),e.jsx("h3",{className:"font-semibold text-md dark:text-white",children:w("contentManagement.commonRemarks")}),E?e.jsx("div",{className:"text-center py-4 dark:text-gray-400",children:w("contentManagement.loading")}):e.jsx("div",{className:"overflow-x-auto max-h-[380px] overflow-y-auto border rounded dark:border-gray-600",children:e.jsxs("table",{className:"min-w-full text-sm text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-gray-100 dark:bg-gray-700",children:[e.jsx("th",{className:"px-3 py-2 dark:text-white",children:"#"}),e.jsx("th",{className:"px-3 py-2 dark:text-white",children:w("header.Remark")}),e.jsx("th",{className:"px-3 py-2 dark:text-white",children:w("header.Description")}),e.jsx("th",{className:"px-3 py-2 dark:text-white",children:w("userRecord.Actions")})]})}),e.jsx("tbody",{children:j!=null&&j.items.length?j.items.map((M,I)=>e.jsxs("tr",{className:"border-b hover:bg-gray-50 dark:hover:bg-gray-700 dark:border-gray-600",children:[e.jsx("td",{className:"px-3 py-2 dark:text-gray-300",children:I+1}),e.jsx("td",{className:"px-3 py-2 dark:text-gray-300",children:M.remark}),e.jsx("td",{className:"px-3 py-2 dark:text-gray-300",children:M.description}),e.jsxs("td",{className:"px-3 py-2 flex gap-2",children:[e.jsx(J,{variant:"outline",size:"sm",onClick:()=>u(M),children:e.jsx(wr,{className:"h-4 w-4"})}),e.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{g(M.id),f(!0)},children:e.jsx(Rt,{className:"h-4 w-4"})})]})]},M.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"text-center py-4 text-gray-500 dark:text-gray-400",children:w("contentManagement.noRec")})})})]})}),e.jsx(Bt,{open:l,onOpenChange:M=>{k.isPending||(f(M),M||g(null))},children:e.jsxs(Ut,{children:[e.jsxs(Ht,{children:[e.jsx(Kt,{children:w("common.delete")}),e.jsx(Vt,{children:w("contentManagement.deleteMsg")})]}),e.jsxs(Qt,{children:[e.jsx(Gt,{disabled:k.isPending,children:w("common.cancel")}),e.jsx(Wt,{className:"bg-red-600 hover:bg-red-700",disabled:k.isPending||!y,onClick:()=>{y&&k.mutate(y)},children:k.isPending?w("common.deleting","Deleting..."):w("common.delete")})]})]})})]})},Wn=({unitId:t})=>{var R,L;const[r,a]=c.useState([]),[n,s]=c.useState([]),[i,o]=c.useState(!0),[d,m]=c.useState(""),[l,f]=c.useState(null),[y,g]=c.useState("header"),[x,v]=c.useState(null),[p,j]=c.useState(!1),[E,b]=c.useState(null),k=c.useRef(null),N=_e(),u=sa.language,[C,M]=c.useState([]),{data:I}=Wa(t??"",{enabled:!!t}),se=(L=(R=I==null?void 0:I.data)==null?void 0:R.items)==null?void 0:L[0],Y=(se==null?void 0:se.canCreateDirectRecord)??!1,$=At(),[F,_]=c.useState(null),ne=T=>{var P,Z;const h=String(T.key||"").toLowerCase(),U=[(P=T.name)==null?void 0:P.en,(Z=T.name)==null?void 0:Z.am].filter(Boolean).join(" ").toLowerCase();return h.includes("direct")||U.includes("direct")},{recordTypes:X}=Er(),{allDepratments:W}=Er(),xe=c.useCallback(T=>T?u==="am"?T.am||T.en:T.en||T.am:"",[u]),ie=c.useCallback(async()=>{o(!0);try{const[T,h]=await Promise.all([Me.getHeadersByUnitId(t),Me.getFootersByUnitId(t)]),U=T.data.items.filter(q=>q.isCurrent&&q.uploadedSuccessfully),P=h.data.items.filter(q=>q.isCurrent&&q.uploadedSuccessfully),Z=async(q,de)=>Promise.all(q.map(async fe=>{try{const Q=de==="header"?await Me.getHeaderById(fe.id):await Me.getFooterById(fe.id);return{...fe,presigned:Q.data.presigned}}catch{return fe}})),[ee,te]=await Promise.all([Z(U,"header"),Z(P,"footer")]);a(ee),s(te)}catch{ge.error(w("contentManagement.failedToLoadHeaderFooter"))}finally{o(!1)}},[t]),Ae=async(T,h,U)=>{try{const P={isCurrent:U};h==="header"?await Me.changeHeaderStatus(T,P):await Me.changeFooterStatus(T,P),N.invalidateQueries({queryKey:["headers-footers",t]}),ge.success(w("contentManagement.statusChanged")),ie()}catch{ge.error(w("contentManagement.statusChangeFailed"))}},je=async()=>{if(!d||!l){b(w("contentManagement.provideMsg"));return}j(!0),b(null);try{const T=await(y==="header"?Me.uploadAndCreateHeader(l,d,t,C,F):Me.uploadAndCreateFooter(l,d,t,C,F));T!=null&&T.id&&(y==="header"?await Me.changeHeaderStatus(T.id,{isCurrent:!0}):await Me.changeFooterStatus(T.id,{isCurrent:!0})),ge.success(`${y} ${w("contentManagement.uploadSuccess")}`),k.current&&(k.current.value=""),f(null),m(""),v(null),b(null),M([]),_(null),ie()}catch{b(w("contentManagement.uploadFailed")),ge.error(w("contentManagement.uploadFailed"))}finally{j(!1)}};c.useEffect(()=>{ie()},[ie]);const z=(X==null?void 0:X.filter(T=>Y?!0:!ne(T)).map(T=>({label:T.key=="direct"?$({en:"Direct Letter",am:"ቀጥታ ደብዳቤ"}):$(T.name),value:T.key})))||[],O=(T,h,U)=>e.jsxs(Ke,{className:"p-6 border shadow-sm dark:border-gray-700 dark:bg-gray-800",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"font-semibold text-xl dark:text-white",children:T}),e.jsxs("span",{className:"text-sm text-muted-foreground dark:text-gray-400",children:[h.length," ",h.length===1?"item":"items"]})]}),i?e.jsx(et,{className:"h-40"}):h.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center",children:e.jsx("span",{className:"text-2xl text-gray-400 dark:text-gray-500",children:U==="header"?"📄":"📋"})}),e.jsxs("p",{className:"text-sm text-muted-foreground dark:text-gray-400 mb-2",children:["No ",T.toLowerCase()," found"]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-gray-500",children:["Upload your first ",U," using the form below"]})]}):e.jsx("div",{className:"space-y-4",children:h.map(P=>e.jsxs("div",{className:`border rounded-lg p-4 ${P.isCurrent?"bg-primary-50 dark:bg-primary-900/30 border-primary-200 dark:border-primary-800 shadow-sm":"bg-white dark:bg-gray-700"}`,children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-lg truncate dark:text-white",children:u==="en"?P.name.en:P.name.am}),P.isCurrent&&e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-primary-100 dark:bg-primary-900/50 text-primary-800 dark:text-primary-300 flex-shrink-0",children:w("contentManagement.currentlyActive")})]}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-gray-400 truncate",children:P.fileInfo.fileName})]})}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[P.presigned&&e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"w-24 h-16 border rounded-md overflow-hidden bg-gray-50 dark:bg-gray-600",children:e.jsx("img",{src:P.presigned,alt:`${U} Preview`,className:"w-full h-full object-contain"})})}),e.jsx("div",{className:"flex items-center gap-2 ml-auto",children:e.jsx(J,{size:"sm",variant:"outline",onClick:()=>Ae(P.id,U,!1),className:"text-red-600 dark:text-red-400 border-red-300 dark:border-red-700 hover:bg-red-50 dark:hover:bg-red-900/30 whitespace-nowrap",children:w("contentManagement.delete")})})]})]},P.id))})]});return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid lg:grid-cols-2 gap-8",children:[O("Headers",r,"header"),O("Footers",n,"footer")]}),e.jsxs(Ke,{className:"p-4 border shadow-sm space-y-4 dark:border-gray-700 dark:bg-gray-800",children:[e.jsxs("h2",{className:"font-semibold text-lg flex items-center gap-2 dark:text-white",children:[e.jsx(ct,{className:"h-5 w-5"})," ",w("contentManagement.addHeaderFooter")]}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(Ce,{className:"dark:text-gray-200",children:w("contentManagement.name")}),e.jsx(ke,{value:d,onChange:T=>{m(T.target.value),b(null)},placeholder:w("contentManagement.name"),disabled:p,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]}),e.jsxs("div",{children:[e.jsx(Ce,{className:"dark:text-gray-200",children:w("contentManagement.type")}),e.jsxs("select",{value:y,onChange:T=>g(T.target.value),className:"w-full rounded border px-3 py-2 text-sm dark:bg-gray-700 dark:border-gray-600 dark:text-white",disabled:p,children:[e.jsx("option",{value:"header",children:w("contentManagement.header")}),e.jsx("option",{value:"footer",children:w("contentManagement.footer")})]})]}),e.jsxs("div",{children:[e.jsx(Ce,{className:"dark:text-gray-200",children:w("contentManagement.uploadFile")}),e.jsx(ke,{type:"file",accept:"image/*",ref:k,onChange:T=>{var U;const h=((U=T.target.files)==null?void 0:U[0])||null;if(h){if(h.size>5*1024*1024){b("File size must be less than 5 MB"),k.current&&(k.current.value=""),f(null),v(null);return}f(h),v(URL.createObjectURL(h))}else f(null),v(null);b(null)},disabled:p})]}),e.jsxs("div",{children:[e.jsx(Ce,{className:"dark:text-gray-200",children:w("contentManagement.positions")}),e.jsx(Xa,{options:(W==null?void 0:W.map(T=>({label:xe(T.name),value:T.id})))??[],value:C,onValueChange:M,placeholder:w("contentManagement.selectPositions"),maxCount:5,className:"w-full max-w-full sm:max-w-md overflow-x-auto",animation:0})]}),e.jsxs("div",{children:[e.jsx(Ce,{className:"dark:text-gray-200",children:w("addRecord.Record Type")}),e.jsxs(ft,{value:F??"",onValueChange:T=>_(T||null),children:[e.jsx(ht,{children:e.jsx(xt,{placeholder:w("addRecord.Select Record Type")})}),e.jsx(yt,{children:z.map(T=>e.jsx(bt,{value:T.value,children:T.label},T.value))})]})]})]}),x&&e.jsxs("div",{className:"mt-2",children:[e.jsx(Ce,{className:"dark:text-gray-200",children:w("contentManagement.preview")}),e.jsx("div",{className:"border rounded p-2 inline-block mt-1 dark:border-gray-600",children:e.jsx("img",{src:x,alt:"Preview",className:"h-24 object-contain rounded"})})]}),E&&e.jsx("p",{className:"text-sm text-red-500",children:E}),e.jsx(J,{onClick:je,disabled:p,className:"bg-primary hover:bg-primary/90 text-primary-foreground w-full",children:p?w("PDF.uploading"):`${w("signatureUpload.upload")} ${y}`})]})]})},Yn=({items:t,isLoading:r,onEdit:a,onDelete:n,showPositionColumn:s=!1,showCountColumn:i=!1,positions:o=[]})=>{const d=_e(),m=b=>{var N,u;const k=o.find(C=>C.id===b);return((N=k==null?void 0:k.name)==null?void 0:N.en)||((u=k==null?void 0:k.name)==null?void 0:u.am)||b},[l,f]=c.useState(null),[y,g]=c.useState(""),x=b=>{var k,N;return((N=(k=b.recordSequences)==null?void 0:k[0])==null?void 0:N.count)??b.count??void 0},v=b=>{var k,N;return((N=(k=b.recordSequences)==null?void 0:k[0])==null?void 0:N.id)??b.sequenceId??void 0},p=b=>{const k=x(b)??0,N=v(b);N&&(f({itemId:N,currentCount:k}),g(String(k)))},j=()=>{f(null),g(""),d.invalidateQueries({queryKey:["prefixes-by-position"]}),d.invalidateQueries({queryKey:["unit-reference-numbers"]})},E=b=>{if(b.preventDefault(),!l)return;const k=parseInt(y,10);isNaN(k)||k<0||Pe.updateCount(l.itemId,k).then(()=>{j()})};return e.jsxs("div",{className:"overflow-x-auto border rounded-lg dark:border-gray-600",children:[e.jsxs("table",{className:"min-w-full text-sm text-left",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700 border-b dark:border-gray-600",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 dark:text-white",children:"#"}),e.jsx("th",{className:"px-4 py-3 dark:text-white",children:w("header.amharic")}),e.jsx("th",{className:"px-4 py-3 dark:text-white",children:w("header.english")}),e.jsx("th",{className:"px-4 py-3 dark:text-white",children:w("contentManagement.type")}),s&&e.jsx("th",{className:"px-4 py-3 dark:text-white",children:w("contentManagement.position")}),i&&e.jsx("th",{className:"px-4 py-3 dark:text-white",children:w("contentManagement.count")}),e.jsx("th",{className:"px-4 py-3 dark:text-white",children:w("userRecord.Actions")})]})}),e.jsx("tbody",{children:r?e.jsx("tr",{children:e.jsx("td",{colSpan:s?6:5,className:"text-center py-8 text-gray-500 dark:text-gray-400",children:w("contentManagement.loading")})}):t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:s?6:5,className:"text-center py-8 text-gray-500 dark:text-gray-400",children:w("contentManagement.noRec")})}):t.map((b,k)=>{var N,u;return e.jsxs("tr",{className:"border-b hover:bg-gray-50 dark:hover:bg-gray-700 dark:border-gray-600",children:[e.jsx("td",{className:"px-4 py-3 dark:text-gray-300",children:k+1}),e.jsx("td",{className:"px-4 py-3 dark:text-gray-300",children:((N=b.name)==null?void 0:N.am)||"-"}),e.jsx("td",{className:"px-4 py-3 dark:text-gray-300",children:((u=b.name)==null?void 0:u.en)||"-"}),e.jsxs("td",{className:"px-4 py-3 capitalize dark:text-gray-300",children:[b.type,b.isForCC&&e.jsx("span",{className:"ml-1 text-xs text-purple-600 dark:text-purple-400",children:"(CC)"})]}),s&&e.jsx("td",{className:"px-4 py-3 dark:text-gray-300",children:b.positionId?m(b.positionId):"-"}),i&&e.jsx("td",{className:"px-4 py-3 dark:text-gray-300",children:(()=>{const C=x(b);return C===void 0?"-":e.jsx("button",{onClick:()=>p(b),className:"text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 underline cursor-pointer",children:C})})()}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>a(b),children:e.jsx(wr,{className:"h-4 w-4"})}),e.jsx(J,{variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300",onClick:()=>n(b.id,b.type,b.recordTypeKey),children:e.jsx(Rt,{className:"h-4 w-4"})})]})})]},b.id)})})]}),l&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 w-80",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold dark:text-white",children:w("contentManagement.updateCount")}),e.jsx("button",{onClick:j,className:"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200",children:e.jsx(lt,{className:"h-5 w-5"})})]}),e.jsxs("form",{onSubmit:E,children:[e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs(Ce,{htmlFor:"countValue",className:"dark:text-gray-200",children:[w("contentManagement.value")," *"]}),e.jsx(ke,{id:"countValue",type:"number",min:"0",value:y,onChange:b=>g(b.target.value),placeholder:w("contentManagement.enterValue"),className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[w("contentManagement.currentCount"),":"," ",l.currentCount]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(J,{type:"button",variant:"outline",onClick:j,children:w("common.cancel")}),e.jsx(J,{type:"submit",children:w("common.submit")})]})]})]})})]})},ut=(t,r)=>{var n,s;const a=t;return((s=(n=a==null?void 0:a.response)==null?void 0:n.data)==null?void 0:s.message)||(a==null?void 0:a.message)||r},wt=t=>{var n,s,i;const r=t,a=((s=(n=r==null?void 0:r.response)==null?void 0:n.data)==null?void 0:s.message)||(r==null?void 0:r.message)||"";return((i=r==null?void 0:r.response)==null?void 0:i.status)===400&&/unit not found/i.test(a)},Mr=t=>({data:t,status:200,statusText:"OK",headers:{},config:{}}),Yt={getReferenceNumbers:async t=>{try{return await re.get(`/unit-configurations/${t}/reference-number`)}catch(r){if(wt(r))return Mr([]);throw new Error(ut(r,"Failed to fetch reference numbers"))}},getTagBasedReferences:async(t,r)=>{try{return await re.get(`/record-prefixes/list/${t}/`)}catch(a){if(wt(a))return Mr([]);throw new Error(ut(a,"Failed to fetch reference numbers"))}},getUnitConfiguration:async t=>{try{return await re.get(`/unit-configurations/${t}`)}catch(r){throw new Error(ut(r,"Failed to fetch unit configuration"))}},addReferenceNumber:async(t,r)=>{try{return await re.post(`/unit-configurations/${t}/reference-number`,r)}catch(a){if(wt(a))return await re.post("/unit-configurations",{unitId:t}),await re.post(`/unit-configurations/${t}/reference-number`,r);throw new Error(ut(a,"Failed to add reference numbers"))}},updateInternalMemoReferencePrefix:async(t,r)=>{try{return await re.patch(`/unit-configurations/add-internal-memo-reference-number-prefix/${t}`,r)}catch(a){if(wt(a))return await re.post("/unit-configurations",{unitId:t}),await re.patch(`/unit-configurations/add-internal-memo-reference-number-prefix/${t}`,r);throw new Error(ut(a,"Failed to update internal memo reference prefix"))}},updateExternalReferencePrefix:async(t,r)=>{try{return await re.patch(`/unit-configurations/add-external-reference-number-prefix/${t}`,r)}catch(a){if(wt(a))return await re.post("/unit-configurations",{unitId:t}),await re.patch(`/unit-configurations/add-external-reference-number-prefix/${t}`,r);throw new Error(ut(a,"Failed to update external reference prefix"))}}},fa=t=>Ee({queryKey:["unit-reference-numbers",t],queryFn:()=>Yt.getReferenceNumbers(t),enabled:!!t}),Xn=()=>{const t=_e();return Ne({mutationFn:({unitId:r,payload:a})=>Yt.addReferenceNumber(r,a),onSuccess:(r,a)=>{t.invalidateQueries({queryKey:["unit-reference-numbers",a.unitId]}),t.invalidateQueries({queryKey:["unit-configuration",a.unitId]})}})},Jn=()=>{const t=_e();return Ne({mutationFn:({unitId:r,payload:a})=>Yt.updateInternalMemoReferencePrefix(r,a),onSuccess:(r,a)=>{t.invalidateQueries({queryKey:["unit-reference-numbers",a.unitId]}),t.invalidateQueries({queryKey:["unit-configuration",a.unitId]})}})},Zn=()=>{const t=_e();return Ne({mutationFn:({unitId:r,payload:a})=>Yt.updateExternalReferencePrefix(r,a),onSuccess:(r,a)=>{t.invalidateQueries({queryKey:["unit-reference-numbers",a.unitId]}),t.invalidateQueries({queryKey:["unit-configuration",a.unitId]})}})},es=({open:t,onClose:r,onSuccess:a,unitId:n,cardType:s,recordType:i,editingItem:o,positions:d=[]})=>{var Ae,je;const m=_e(),l=!!o,[f,y]=c.useState(""),[g,x]=c.useState(""),[v,p]=c.useState(""),j=["reference","externalReference","internalMemoReference"].includes(s),E=i==="positionPrefix",b=s.includes("CC"),k=s==="reference",N=s==="externalReference",u=s==="internalMemoReference",C=d.filter(z=>!!(z!=null&&z.id)).map(z=>{var O,R;return{value:z.id,label:((O=z.name)==null?void 0:O.en)||((R=z.name)==null?void 0:R.am)||z.id}}),M=s==="internalPrefix"?"internal":s==="externalPrefix"?"external":s==="internalMemoPrefix"?"internal_memo":o==null?void 0:o.recordTypeKey,{data:I}=fa(j?n:""),se=Xn(),Y=Jn(),$=Zn(),{handleError:F}=dt(w),_=((je=(Ae=I==null?void 0:I.data)==null?void 0:Ae.items)==null?void 0:je[0])||(I==null?void 0:I.data)||{},ne=Array.isArray(_);ne&&(_==null||_.find(z=>z.name==="referenceNumberPrefix")),ne&&(_==null||_.find(z=>z.name==="externalReferenceNumberPrefix")),ne&&(_==null||_.find(z=>z.name==="internalMemoReferenceNumberPrefix")),c.useEffect(()=>{var z,O,R,L;o?(j?(y(((z=o.name)==null?void 0:z.am)||""),x(((O=o.name)==null?void 0:O.en)||"")):(y(((R=o.name)==null?void 0:R.am)||""),x(((L=o.name)==null?void 0:L.en)||"")),p(o.positionId||"")):(y(""),x(""),p(""))},[o,j]),c.useEffect(()=>{if(!(!j||o)){if(k){y(_.referenceNumberPrefix||""),x(_.referenceNumberPrefix||"");return}if(N){y(_.externalReferenceNumberPrefix||""),x(_.externalReferenceNumberPrefix||"");return}u&&(y(_.internalMemoReferenceNumberPrefix||""),x(_.internalMemoReferenceNumberPrefix||""))}},[o,j,k,N,u,_.referenceNumberPrefix,_.externalReferenceNumberPrefix,_.internalMemoReferenceNumberPrefix]);const{mutate:X,isPending:W}=Ne({mutationFn:async()=>{const z=i,O=j||E||s==="prefix"||s==="prefixCC"||s==="internalPrefix"||s==="externalPrefix"||s==="internalMemoPrefix";let R,L;if(j){if(k){await se.mutateAsync({unitId:n,payload:{referenceNumberPrefix:{am:f,en:g}}});return}if(N){await $.mutateAsync({unitId:n,payload:{externalReferenceNumberPrefix:{am:f,en:g}}});return}if(u){await Y.mutateAsync({unitId:n,payload:{internalMemoReferenceNumberPrefix:{am:f,en:g}}});return}}else if(E){if(M!=="internal"&&M!=="external"&&M!=="internal_memo")throw new Error("Position prefix requires internal, external, or internal_memo recordTypeKey");R={unitId:n,recordTypeKey:M,isForCC:!1,positionId:v,name:{am:f,en:g}}}else{const T={unitId:n,recordTypeKey:z,isForCC:b,name:{am:f,en:g}};s==="suffix"||s==="suffixCC"?L=T:R=T}if(l){if(O&&R)return Pe.editPrefix(o.id,R);if(L)return Pe.editSuffix(o.id,L);throw new Error("Invalid prefix/suffix payload for update")}if(O&&R)return Pe.createPrefix(R);if(L)return Pe.createSuffix(L);throw new Error("Invalid prefix/suffix payload for create")},onSuccess:()=>{m.invalidateQueries({queryKey:["prefixSuffix"]}),ge.success(w("msg.successfullyCompleted")),a()},onError:z=>{F(z)}}),xe=z=>{z.preventDefault(),X()},ie=()=>j?f.trim()!==""&&g.trim()!=="":E?f.trim()!==""&&g.trim()!==""&&v:f.trim()!==""&&g.trim()!=="";return e.jsx(Qe,{open:t,onOpenChange:r,children:e.jsxs(Ge,{className:"sm:max-w-[500px] dark:bg-gray-800",children:[e.jsx(We,{children:e.jsxs(Ye,{className:"dark:text-white",children:[l?w("contentManagement.edit"):w("contentManagement.add")," ",w(`contentManagement.${s}`)]})}),e.jsxs("form",{onSubmit:xe,className:"space-y-4",children:[j?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"nameAm",className:"dark:text-gray-200",children:[w("contentManagement.amharicName")," *"]}),e.jsx(ke,{id:"nameAm",value:f,onChange:z=>y(z.target.value),placeholder:w("contentManagement.amharicName"),disabled:W,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"nameEn",className:"dark:text-gray-200",children:[w("contentManagement.englishName")," *"]}),e.jsx(ke,{id:"nameEn",value:g,onChange:z=>x(z.target.value),placeholder:w("contentManagement.englishName"),disabled:W,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"nameAm",className:"dark:text-gray-200",children:[w("contentManagement.amharicName")," *"]}),e.jsx(ke,{id:"nameAm",value:f,onChange:z=>y(z.target.value),placeholder:w("contentManagement.amharicName"),disabled:W,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"nameEn",className:"dark:text-gray-200",children:[w("contentManagement.englishName")," *"]}),e.jsx(ke,{id:"nameEn",value:g,onChange:z=>x(z.target.value),placeholder:w("contentManagement.englishName"),disabled:W,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]})]}),E&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"position",className:"dark:text-gray-200",children:[w("contentManagement.position")," *"]}),e.jsx(Za,{options:C,value:v,onValueChange:p,placeholder:w("contentManagement.selectPosition"),className:W?"pointer-events-none opacity-60":""})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(J,{type:"button",variant:"outline",onClick:r,disabled:W,children:w("common.Cancel")}),e.jsx(J,{type:"submit",disabled:!ie()||W,className:"bg-purple-600 hover:bg-purple-700",children:W?w("contentManagement.saving"):k&&(_.referenceNumberPrefix||_.externalReferenceNumberPrefix||_.internalMemoReferenceNumberPrefix)||l?w("common.update"):w("common.save")})]})]})]})})},ts=(t,r,a=0,n=10)=>Ee({queryKey:["prefixes",t,r,{cc:!1}],queryFn:()=>Pe.getPrefix(t,r,a,n),enabled:!!t&&!!r}),rs=(t,r,a=0,n=10)=>Ee({queryKey:["prefixes",t,r,{cc:!0}],queryFn:()=>Pe.getPrefixCC(t,r,a,n),enabled:!!t&&!!r}),as=(t,r,a=0,n=10)=>Ee({queryKey:["prefixes-by-position",t,r],queryFn:()=>Pe.getPrefixByPosition(t,r,a,n),enabled:!!t&&!!r}),ns=()=>{const t=_e();return Ne({mutationFn:({id:r})=>Pe.deletePrefix(r),onSuccess:(r,a)=>{t.invalidateQueries({queryKey:["prefixes",a.unitId,a.recordTypeKey,{cc:a.isForCC}]}),t.invalidateQueries({queryKey:["prefix",a.id]})}})},ss=(t,r,a=0,n=10)=>Ee({queryKey:["suffixes",t,r,{cc:!1}],queryFn:()=>Pe.getSuffix(t,r,a,n),enabled:!!t&&!!r}),is=(t,r,a=0,n=10)=>Ee({queryKey:["suffixes",t,r,{cc:!0}],queryFn:()=>Pe.getSuffixCC(t,r,a,n),enabled:!!t&&!!r}),os=()=>{const t=_e();return Ne({mutationFn:({id:r})=>Pe.deleteSuffix(r),onSuccess:(r,a)=>{t.invalidateQueries({queryKey:["suffixes",a.unitId,a.recordTypeKey,{cc:a.isForCC}]}),t.invalidateQueries({queryKey:["suffix",a.id]})}})},ls=({unitId:t,recordTagId:r,skip:a=0,take:n=10})=>{const{t:s}=Ie(),{handleError:i}=dt(s),o=_e(),{data:d,isLoading:m,isError:l,refetch:f}=Ee({queryKey:["recordTagPrefixes",t,r,a,n],queryFn:async()=>{const{data:p}=await Pe.getPrefixByRecordTagId(t,r,a,n);return p},enabled:!!t&&!!r,staleTime:300*1e3,retry:!1}),{mutate:y,isPending:g}=Ne({mutationFn:async p=>{const{data:j}=await Pe.createPrefix(p);return j},onSuccess:()=>{ge.success(s("prefixes.createdSuccess")||"Prefix created successfully ✅"),o.invalidateQueries({queryKey:["recordTagPrefixes",t,r]})},onError:p=>{i(p)}}),{mutate:x,isPending:v}=Ne({mutationFn:async p=>{const{data:j}=await Pe.deletePrefix(p);return j},onSuccess:()=>{ge.success(s("prefixes.deletedSuccess")||"Prefix deleted successfully 🗑️"),o.invalidateQueries({queryKey:["recordTagPrefixes",t,r]})},onError:p=>{i(p)}});return{prefixes:(d==null?void 0:d.items)??[],total:(d==null?void 0:d.count)??0,isLoadingPrefixes:m,isErrorPrefixes:l,refetchPrefixes:f,createPrefix:y,isCreatingPrefix:g,deletePrefix:x,isDeletingPrefix:v}},kt={getRecordTags:t=>He.get(`/record-tags/${t}`,{headers:ae()}),getRecordTagsListWithUnitById:t=>He.get(`/record-tags/list/${t}`,{headers:ae()}),createRecordTags:t=>He.post("/record-tags",{...t,recordTypeKey:"external"},{headers:ae()}),updateEmployee:(t,r)=>He.put(`/record-tags/${t}`,r,{headers:ae()}),deleteEmployee:t=>He.delete(`/record-tags/${t}`,{headers:ae()})},Mt=({unitId:t,recordTagId:r})=>{const{t:a}=Ie(),{handleError:n}=dt(a),{data:s,isLoading:i,isError:o,refetch:d}=Ee({queryKey:["recordTagsList",t],queryFn:async()=>{const{data:b}=await kt.getRecordTagsListWithUnitById(t);return b},enabled:!!t,staleTime:300*1e3,retry:!1}),{data:m,isLoading:l,isError:f,refetch:y}=Ee({queryKey:["recordTag",r],queryFn:async()=>{const{data:b}=await kt.getRecordTags(r);return b},enabled:!!r,staleTime:300*1e3,retry:!1}),{mutate:g,isPending:x}=Ne({mutationFn:async b=>{const{data:k}=await kt.createRecordTags(b);return k},onSuccess:()=>{ge.success("Record Tag created successfully ✅"),d()},onError:b=>{n(b)}}),{mutate:v,isPending:p}=Ne({mutationFn:async({id:b,payload:k})=>{const{data:N}=await kt.updateEmployee(b,k);return N},onSuccess:()=>{ge.success("Record Tag updated successfully ✨"),d()},onError:b=>{n(b)}}),{mutate:j,isPending:E}=Ne({mutationFn:async b=>{const{data:k}=await kt.deleteEmployee(b);return k},onSuccess:()=>{ge.success("Record Tag deleted successfully 🗑️"),d()},onError:b=>{n(b)}});return{recordTagsList:s,isLoadingRecordTagsList:i,isErrorRecordTagsList:o,refetchRecordTagsList:d,recordTag:m,isLoadingRecordTag:l,isErrorRecordTag:f,refetchRecordTag:y,createRecordTag:g,isCreatingRecordTag:x,updateRecordTag:v,isUpdatingRecordTag:p,deleteRecordTag:j,isDeletingRecordTag:E}};function cs({unitId:t,selectedTagIds:r,onChange:a,placeholder:n="Select tags...",multiple:s=!0,disabled:i=!1,className:o,maxDisplayTags:d=3,error:m}){const{t:l}=Ie(),[f,y]=c.useState(!1),g=At(),{recordTagsList:x,isLoadingRecordTagsList:v,isErrorRecordTagsList:p}=Mt({unitId:t}),j=(x==null?void 0:x.items)??[],E=j.filter(u=>r.includes(u.id)),b=c.useCallback(u=>{s?a(r.includes(u)?r.filter(C=>C!==u):[...r,u]):(a(r.includes(u)?[]:[u]),y(!1))},[s,a,r]),k=c.useCallback((u,C)=>{u.stopPropagation(),a(r.filter(M=>M!==C))},[a,r]),N=c.useCallback(u=>{u.stopPropagation(),a([])},[a]);return e.jsxs("div",{className:be("flex flex-col gap-1.5",o),children:[e.jsxs(en,{open:f,onOpenChange:y,children:[e.jsx(tn,{asChild:!0,children:e.jsxs(J,{variant:"outline",role:"combobox","aria-expanded":f,disabled:i||v,className:be("w-full justify-between min-h-[40px] h-auto px-3 py-2",!s&&E.length>0&&"justify-start gap-2",m&&"border-destructive ring-destructive","hover:bg-accent"),children:[v?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(lr,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm",children:l("common.loading")})]}):E.length===0?e.jsx("span",{className:"text-muted-foreground text-sm",children:n}):s?e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 flex-1",children:[E.slice(0,d).map(u=>e.jsxs(cr,{variant:"secondary",className:"gap-1 px-2 py-0.5 text-xs font-medium cursor-default",style:{backgroundColor:u.color?`${u.color}20`:void 0,color:u.color,borderColor:u.color},children:[u.name,e.jsx(lt,{className:"h-3 w-3 cursor-pointer hover:text-destructive",onClick:C=>k(C,u.id)})]},u.id)),E.length>d&&e.jsxs(cr,{variant:"secondary",className:"text-xs",children:["+",E.length-d]})]}):e.jsx("div",{className:"flex items-center gap-2 flex-1",children:e.jsx("span",{className:"text-sm",children:g(E[0].name)})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[E.length>0&&!i&&e.jsx(lt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground cursor-pointer",onClick:N}),e.jsx(wn,{className:"h-4 w-4 text-muted-foreground shrink-0"})]})]})}),e.jsx(rn,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(an,{children:[e.jsx(nn,{placeholder:l("common.search")||"Search tags..."}),e.jsxs(sn,{children:[e.jsx(on,{children:p?e.jsx("div",{className:"py-6 text-center text-sm text-destructive",children:l("common.errorLoading")}):l("common.noResults")||"No tags found."}),e.jsx(ln,{children:j.map(u=>{const C=r.includes(u.id);return e.jsx(cn,{value:u.id,onSelect:()=>b(u.id),className:"cursor-pointer",children:e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx("div",{className:be("flex h-4 w-4 items-center justify-center rounded-sm border border-primary",C?"bg-primary text-primary-foreground":"opacity-50"),children:C&&e.jsx(_a,{className:"h-3 w-3"})}),e.jsx("span",{className:"flex-1 text-sm",children:g(u.name)})]})},u.id)})})]})]})})]}),m&&e.jsx("p",{className:"text-xs text-destructive",children:m})]})}function ds({className:t,...r}){return e.jsx("nav",{role:"navigation","aria-label":"pagination","data-slot":"pagination",className:be("mx-auto flex w-full justify-center",t),...r})}function us({className:t,...r}){return e.jsx("ul",{"data-slot":"pagination-content",className:be("flex flex-row items-center gap-1",t),...r})}function ar({...t}){return e.jsx("li",{"data-slot":"pagination-item",...t})}function Nr({className:t,isActive:r,size:a="icon",...n}){return e.jsx("a",{"aria-current":r?"page":void 0,"data-slot":"pagination-link","data-active":r,className:be(Da({variant:r?"outline":"ghost",size:a}),t),...n})}function ms({className:t,...r}){return e.jsxs(Nr,{"aria-label":"Go to previous page",size:"default",className:be("gap-1 px-2.5 sm:pl-2.5",t),...r,children:[e.jsx(ma,{}),e.jsx("span",{className:"hidden sm:block",children:"Previous"})]})}function gs({className:t,...r}){return e.jsxs(Nr,{"aria-label":"Go to next page",size:"default",className:be("gap-1 px-2.5 sm:pr-2.5",t),...r,children:[e.jsx("span",{className:"hidden sm:block",children:"Next"}),e.jsx(vr,{})]})}function ps({unitId:t,className:r}){const{t:a}=Ie(),n=At(),[s,i]=c.useState(""),[o,d]=c.useState(!1),[m,l]=c.useState(null),[f,y]=c.useState(1),g=10,x=(f-1)*g,{recordTagsList:v,isLoadingRecordTagsList:p}=Mt({unitId:t}),{prefixes:j,total:E,isLoadingPrefixes:b,isErrorPrefixes:k,createPrefix:N,isCreatingPrefix:u,deletePrefix:C,isDeletingPrefix:M}=ls({unitId:t,recordTagId:s||void 0,skip:x,take:g}),I=Math.ceil(E/g);c.useEffect(()=>{y(1)},[s]);const se=c.useMemo(()=>{var F;return(F=v==null?void 0:v.items)==null?void 0:F.find(_=>_.id===s)},[v,s]),Y=c.useCallback(F=>{var xe,ie;F.preventDefault();const _=new FormData(F.currentTarget),ne=(xe=_.get("nameAm"))==null?void 0:xe.trim(),X=(ie=_.get("nameEn"))==null?void 0:ie.trim();if(!ne||!X)return;N({name:{am:ne,en:X},unitId:t,isForCC:!1,recordTagId:s||void 0},{onSuccess:()=>{d(!1)}})},[N,s,t]),$=c.useCallback(()=>{m&&C(m,{onSuccess:()=>l(null)})},[C,m]);return e.jsxs("div",{className:be("space-y-6",r),children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-end gap-4",children:[e.jsxs("div",{className:"flex-1 w-full sm:w-auto space-y-2",children:[e.jsx(Ce,{className:"text-sm font-medium",children:a("nav.selectTag")||"Select Record Tag"}),e.jsx(cs,{unitId:t,selectedTagIds:s?[s]:[],onChange:F=>i(F[0]||""),placeholder:a("nav.selectTag")||"Choose a tag to view prefixes...",multiple:!1,disabled:p})]}),e.jsxs(Qe,{open:o,onOpenChange:d,children:[e.jsx(jr,{asChild:!0,children:e.jsxs(J,{className:"shrink-0",disabled:!s||b,children:[e.jsx(ct,{className:"h-4 w-4 mr-2"}),a("contentManagement.addPrefix")||"Add Prefix"]})}),e.jsxs(Ge,{className:"sm:max-w-[500px]",children:[e.jsx(We,{children:e.jsx(Ye,{children:a("contentManagement.addPrefix")||"Add New Prefix"})}),e.jsxs("form",{id:"add-prefix-form",onSubmit:Y,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"nameAm",className:"dark:text-gray-200",children:[a("contentManagement.amharicName")," *"]}),e.jsx(ke,{id:"nameAm",name:"nameAm",placeholder:a("contentManagement.amharicName"),required:!0,autoFocus:!0,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{htmlFor:"nameEn",className:"dark:text-gray-200",children:[a("contentManagement.englishName")," *"]}),e.jsx(ke,{id:"nameEn",name:"nameEn",placeholder:a("contentManagement.englishName"),required:!0,className:"dark:bg-gray-700 dark:border-gray-600 dark:text-white"})]})]}),e.jsxs(Ia,{children:[e.jsx(J,{type:"button",variant:"outline",onClick:()=>d(!1),children:a("common.cancel")||"Cancel"}),e.jsxs(J,{type:"submit",form:"add-prefix-form",disabled:u,children:[u&&e.jsx(lr,{className:"h-4 w-4 mr-2 animate-spin"}),a("common.save")||"Save"]})]})]})]})]}),se&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{children:"Showing prefixes for:"}),e.jsx(cr,{variant:"outline",children:n(se.name)}),e.jsxs("span",{className:"text-xs",children:["(",E," items)"]})]}),e.jsx("div",{className:"rounded-md border",children:e.jsxs(la,{children:[e.jsx(ca,{children:e.jsxs(Ze,{children:[e.jsx(Ve,{className:"w-[80px]",children:a("common.no")||"#"}),e.jsx(Ve,{children:a("contentManagement.amharicName")}),e.jsx(Ve,{children:a("contentManagement.englishName")}),e.jsx(Ve,{children:a("contentManagement.createdAt")||"Created"}),e.jsx(Ve,{className:"w-[100px] text-right",children:a("common.actions")||"Actions"})]})}),e.jsxs(da,{children:[b&&e.jsx(e.Fragment,{children:Array.from({length:5}).map((F,_)=>e.jsxs(Ze,{children:[e.jsx(Te,{children:e.jsx(et,{className:"h-4 w-8"})}),e.jsx(Te,{children:e.jsx(et,{className:"h-4 w-24"})}),e.jsx(Te,{children:e.jsx(et,{className:"h-4 w-20"})}),e.jsx(Te,{children:e.jsx(et,{className:"h-4 w-32"})}),e.jsx(Te,{children:e.jsx(et,{className:"h-4 w-24"})}),e.jsx(Te,{children:e.jsx(et,{className:"h-8 w-8 ml-auto"})})]},`skeleton-${_}`))}),k&&!b&&e.jsx(Ze,{children:e.jsx(Te,{colSpan:6,className:"h-32 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-destructive",children:[e.jsx(dn,{className:"h-8 w-8"}),e.jsx("p",{className:"text-sm",children:a("common.errorLoading")||"Failed to load prefixes"}),e.jsx(J,{variant:"outline",size:"sm",onClick:()=>window.location.reload(),children:a("common.retry")||"Retry"})]})})}),!b&&!k&&e.jsxs(e.Fragment,{children:[!s&&e.jsx(Ze,{children:e.jsx(Te,{colSpan:6,className:"h-32 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground",children:[e.jsx("span",{className:"text-2xl",children:"🏷️"}),e.jsx("p",{className:"text-sm",children:a("nav.selectTag")||"Select a tag above to view its prefixes"})]})})}),s&&j.length===0&&e.jsx(Ze,{children:e.jsx(Te,{colSpan:6,className:"h-32 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground",children:[e.jsx(ct,{className:"h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:a("nav.emptyState")||"No prefixes found for this tag"}),e.jsx(J,{variant:"outline",size:"sm",onClick:()=>d(!0),children:a("nav.addNew")||"Add your first prefix"})]})})}),j.map((F,_)=>{var ne,X;return e.jsxs(Ze,{className:"group",children:[e.jsx(Te,{className:"text-muted-foreground text-sm",children:x+_+1}),e.jsx(Te,{className:"font-medium",children:((ne=F.name)==null?void 0:ne.am)||e.jsx("span",{className:"text-muted-foreground text-sm",children:"—"})}),e.jsx(Te,{children:((X=F.name)==null?void 0:X.en)||e.jsx("span",{className:"text-muted-foreground text-sm",children:"—"})}),e.jsx(Te,{className:"text-muted-foreground text-sm",children:new Date(F.createdAt).toLocaleDateString()}),e.jsx(Te,{className:"text-right",children:e.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>l(F.id),disabled:M,children:e.jsx(Rt,{className:"h-4 w-4"})})})]},F.id)})]})]})]})}),I>1&&e.jsx(ds,{children:e.jsxs(us,{children:[e.jsx(ar,{children:e.jsx(ms,{onClick:()=>y(F=>Math.max(1,F-1)),className:be(f===1&&"pointer-events-none opacity-50")})}),Array.from({length:I},(F,_)=>_+1).map(F=>e.jsx(ar,{children:e.jsx(Nr,{isActive:f===F,onClick:()=>y(F),children:F})},F)),e.jsx(ar,{children:e.jsx(gs,{onClick:()=>y(F=>Math.min(I,F+1)),className:be(f===I&&"pointer-events-none opacity-50")})})]})}),e.jsx(Bt,{open:!!m,onOpenChange:F=>!F&&l(null),children:e.jsxs(Ut,{children:[e.jsxs(Ht,{children:[e.jsx(Kt,{children:a("prefixes.deleteConfirmTitle")||"Delete Prefix?"}),e.jsx(Vt,{children:a("prefixes.deleteConfirmDescription")||"This action cannot be undone. This will permanently delete the prefix."})]}),e.jsxs(Qt,{children:[e.jsx(Gt,{disabled:M,children:a("common.cancel")||"Cancel"}),e.jsxs(Wt,{onClick:$,disabled:M,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[M&&e.jsx(lr,{className:"h-4 w-4 mr-2 animate-spin"}),a("common.delete")||"Delete"]})]})]})})]})}const fs=[{id:"internal",label:"nav.internal"},{id:"external",label:"nav.external"},{id:"internal_memo",label:"nav.internal_memo"},{id:"branch",label:"nav.branch"},{id:"tag-based-reference",label:"nav.tagBasedReference"},{id:"referenceNumber",label:"userRecord.Reference"},{id:"positionPrefix",label:"contentManagement.positionPrefixes"}],Nt=t=>t==="positionPrefix"?"internalPrefix":t==="referenceNumber"?"reference":"prefix",hs=({unitId:t,initialTab:r="internal"})=>{var H,ue,D,we,S,B,V;const{handleError:a}=dt(w),[n,s]=c.useState(r),[i,o]=c.useState(Nt(r)),[d,m]=c.useState(!1),[l,f]=c.useState(null),y=_e(),{mutateAsync:g}=ns(),{mutateAsync:x}=os(),{usePositionListByUnitId:v}=Ja(),{data:p}=v(t,{take:1e3,skip:0}),j=(p==null?void 0:p.items)||[];c.useEffect(()=>{s(r),o(Nt(r))},[r]),c.useEffect(()=>{o(Nt(n))},[n]);const E=A=>{f({cardType:A,recordType:n}),m(!0)},b=A=>{f({cardType:A.type,recordType:n,editingItem:A}),m(!0)},k=async(A,K,he)=>{if(K==="reference"||K==="externalReference"||K==="internalMemoReference"){ge.error(w("msg.errorOccurred"));return}const Oe=K==="prefix"||K==="prefixCC"||K==="internalPrefix"||K==="externalPrefix"||K==="internalMemoPrefix",ce=K==="prefixCC"||K==="suffixCC",ve=he||(K==="internalPrefix"?"internal":K==="externalPrefix"?"external":K==="internalMemoPrefix"?"internal_memo":n);try{Oe?(await g({id:A,unitId:t,recordTypeKey:ve,isForCC:ce}),n==="positionPrefix"&&y.invalidateQueries({queryKey:["prefixes-by-position",t,ve]})):await x({id:A,unitId:t,recordTypeKey:ve,isForCC:ce}),y.invalidateQueries({queryKey:["prefixSuffix"]}),ge.success(w("contentManagement.deleted"))}catch(qe){a(qe)}},N=()=>{m(!1),f(null)},u=()=>{const A=(l==null?void 0:l.cardType)??i,K=(l==null?void 0:l.recordType)??n,he=A==="prefixCC"||A==="suffixCC",Ue=A==="prefix"||A==="prefixCC"||A==="internalPrefix"||A==="externalPrefix"||A==="internalMemoPrefix"||K==="referenceNumber",Oe=K==="referenceNumber"?A:K==="positionPrefix"?A==="internalPrefix"?"internal":A==="internalMemoPrefix"?"internal_memo":"external":K;Ue?(K==="positionPrefix"&&y.invalidateQueries({queryKey:["prefixes-by-position",t,Oe]}),y.invalidateQueries({queryKey:["prefixes",t,Oe,{cc:he}]})):y.invalidateQueries({queryKey:["suffixes",t,Oe,{cc:he}]}),y.invalidateQueries({queryKey:["prefixSuffix"]}),N()},M=n==="positionPrefix"?[{id:"internalPrefix",label:"contentManagement.internalPrefix"},{id:"externalPrefix",label:"contentManagement.externalPrefix"},{id:"internalMemoPrefix",label:"contentManagement.internalMemoPrefix"}]:n==="referenceNumber"?[{id:"reference",label:"contentManagement.reference"},{id:"externalReference",label:"contentManagement.externalReference"},{id:"internalMemoReference",label:"contentManagement.internalMemoReference"}]:[{id:"prefix",label:"contentManagement.prefix"},{id:"suffix",label:"contentManagement.suffix"},{id:"prefixCC",label:"contentManagement.prefixCC"},{id:"suffixCC",label:"contentManagement.suffixCC"}];c.useEffect(()=>{var A;M.some(K=>K.id===i)||o(((A=M[0])==null?void 0:A.id)||Nt(n))},[M,i,n]);const I=i==="prefixCC"||i==="suffixCC",se=n==="referenceNumber",Y=n==="positionPrefix",$=n==="tag-based-reference",F=i==="prefix"||i==="prefixCC"||i==="internalPrefix"||i==="externalPrefix"||i==="internalMemoPrefix"||se,_=i==="internalPrefix"?"internal":i==="externalPrefix"?"external":i==="internalMemoPrefix"?"internal_memo":"",ne=n==="positionPrefix"?_:n,{data:X,isLoading:W,error:xe}=fa(se?t:""),{data:ie,isLoading:Ae,error:je}=ts(t,F&&!I&&!se&&!Y&&!$?ne:"",0,1e3),{data:z,isLoading:O,error:R}=as(t,Y?_:"",0,1e3),{data:L,isLoading:T,error:h}=rs(t,F&&I&&!se?ne:"",0,1e3),{data:U,isLoading:P,error:Z}=ss(t,!F&&!I&&!se?ne:"",0,1e3),{data:ee,isLoading:te,error:q}=is(t,!F&&I&&!se?ne:"",0,1e3),de=c.useMemo(()=>[xe,R,je,h,Z,q].find(Boolean),[xe,R,je,h,Z,q]),fe=c.useRef(null);c.useEffect(()=>{!de||de===fe.current||(fe.current=de,a(de))},[de,a]);const Q=(X==null?void 0:X.data)||[],le=Q==null?void 0:Q.find(A=>A.name==="referenceNumberPrefix"),G=Q==null?void 0:Q.find(A=>A.name==="externalReferenceNumberPrefix"),oe=Q==null?void 0:Q.find(A=>A.name==="internalMemoReferenceNumberPrefix"),Re=A=>{if(!A)return"";if(typeof A=="string")try{const K=JSON.parse(A);return(K==null?void 0:K.am)??A}catch{return A}return typeof A=="object"?(A==null?void 0:A.am)??"":""},ye=[{id:"referenceNumberPrefix",type:"reference",recordTypeKey:"reference",isForCC:!1,name:{am:Re(le==null?void 0:le.number),en:Re((H=le==null?void 0:le.number)==null?void 0:H.en)},count:(le==null?void 0:le.count)??0,sequenceId:le==null?void 0:le.sequenceId},{id:"externalReferenceNumberPrefix",type:"externalReference",recordTypeKey:"externalReference",isForCC:!1,name:{am:Re((ue=G==null?void 0:G.number)==null?void 0:ue.am),en:Re((D=G==null?void 0:G.number)==null?void 0:D.en)},count:(G==null?void 0:G.count)??0,sequenceId:G==null?void 0:G.sequenceId},{id:"internalMemoReferenceNumberPrefix",type:"internalMemoReference",recordTypeKey:"internalMemoReference",isForCC:!1,name:{am:Re((we=oe==null?void 0:oe.number)==null?void 0:we.am),en:Re((S=oe==null?void 0:oe.number)==null?void 0:S.en)},count:(oe==null?void 0:oe.count)??0,sequenceId:oe==null?void 0:oe.sequenceId}].filter(A=>A.type===i),$e=Y?z:F?I?L:ie:I?ee:U,ze=se?ye:((V=(B=$e==null?void 0:$e.data)==null?void 0:B.items)==null?void 0:V.map(A=>({...A,type:n==="positionPrefix"?A.recordTypeKey==="internal"?"internalPrefix":A.recordTypeKey==="internal_memo"?"internalMemoPrefix":"externalPrefix":F?I?"prefixCC":"prefix":I?"suffixCC":"suffix",isForCC:I||A.isForCC})))||[],Se=W||O||Ae||T||P||te;return e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsx("div",{className:"flex border-b border-gray-200 dark:border-gray-700",children:fs.map(A=>e.jsx("button",{onClick:()=>{s(A.id),o(Nt(A.id))},className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${n===A.id?"border-purple-600 text-purple-600 dark:text-purple-400":"border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300 dark:hover:border-gray-600"}`,children:w(A.label)},A.id))}),n==="tag-based-reference"?e.jsx(ps,{unitId:t,className:"w-full"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-4",children:M.map(A=>e.jsx(Ke,{onClick:()=>o(A.id),className:`inline-flex w-fit min-w-[260px] max-w-full shadow-sm hover:shadow-md transition-shadow cursor-pointer dark:bg-gray-800 dark:border-gray-700 ${i===A.id?"ring-2 ring-purple-600 dark:ring-purple-400":""}`,children:e.jsx(it,{className:"pb-2 items-center",children:e.jsx(ot,{className:"text-sm font-medium text-gray-700 dark:text-gray-200 text-center whitespace-nowrap",children:w(A.label)})})},A.id))}),e.jsx("div",{className:"flex justify-end mb-4",children:e.jsxs(J,{onClick:()=>E(i),children:[e.jsx(ct,{className:"h-4 w-4 mr-2"}),w("contentManagement.add")]})}),e.jsx(Yn,{items:ze,isLoading:Se,onEdit:b,onDelete:k,showPositionColumn:n==="positionPrefix",showCountColumn:n==="positionPrefix"||n==="referenceNumber",positions:j}),d&&l&&e.jsx(es,{open:d,onClose:N,onSuccess:u,unitId:t,cardType:l.cardType,recordType:l.recordType,editingItem:l.editingItem,positions:j})]})]})},xs=async t=>(await re.get(`/units/${t}/requirement-satisfied`,{headers:ae()})).data;function ys({unitId:t}){const[r,a]=c.useState(t||""),[n,s]=c.useState(!0);c.useEffect(()=>{const l=f=>a(f.detail);return window.addEventListener("unitChanged",l),()=>window.removeEventListener("unitChanged",l)},[]);const{data:i,isLoading:o,refetch:d}=Ee({queryKey:["admin-setup-requirements",r],queryFn:()=>xs(r),enabled:!!r}),m=i==null?void 0:i.requirements;return c.useEffect(()=>{r&&d()},[r,d]),!m||Object.values(m).every(Boolean)||!n?null:e.jsxs("div",{className:"relative flex items-center gap-6 p-2 border rounded bg-amber-50 shadow-2xl  top-10 left-1/2 -translate-x-1/2 z-[1000] w-full",children:[e.jsx("h3",{className:"font-semibold text-amber-700 whitespace-nowrap",children:"Finish site setup"}),o?e.jsx("p",{className:"text-sm text-slate-600",children:"Loading requirements..."}):e.jsxs("div",{className:"flex flex-wrap gap-6 text-sm text-slate-600",children:[!m.hasFooter&&e.jsx("span",{children:"⚠️ Missing Footer"}),!m.hasSeal&&e.jsx("span",{children:"⚠️ Missing Seal"}),!m.hasHeader&&e.jsx("span",{children:"⚠️ Missing Header"}),!m.internalPrefix&&e.jsx("span",{children:"⚠️ Missing Internal Prefix"}),!m.externalPrefix&&e.jsx("span",{children:"⚠️ Missing External Prefix"}),!m.internalSuffix&&e.jsx("span",{children:"⚠️ Missing Internal Suffix"}),!m.externalSuffix&&e.jsx("span",{children:"⚠️ Missing External Suffix"})]}),e.jsx("button",{onClick:()=>s(!1),className:"absolute top-2 right-2 text-amber-700 hover:text-red-600",children:e.jsx(lt,{size:16})})]})}const bs=gn({nameAm:Lt().min(1,"Amharic name is required"),nameEn:Lt().min(1,"English name is required"),key:Lt().min(1,"Key is required"),unitId:Lt().min(1,"Unit is required")});function ha({defaultValues:t,unitId:r,mode:a,id:n,onSuccess:s}){const i=ua({resolver:mn(bs),defaultValues:{nameAm:(t==null?void 0:t.nameAm)??"",nameEn:(t==null?void 0:t.nameEn)??"",key:(t==null?void 0:t.key)??"",unitId:(t==null?void 0:t.unitId)??r}}),{createRecordTag:o,updateRecordTag:d,isCreatingRecordTag:m,isUpdatingRecordTag:l}=Mt({unitId:r}),f=y=>{if(a==="create"){const g={name:{am:y.nameAm,en:y.nameEn},key:y.key,unitId:y.unitId};o(g,{onSuccess:()=>{i.reset(),s==null||s()}})}else if(a==="edit"&&n){const g={name:{am:y.nameAm,en:y.nameEn},key:y.key,unitId:y.unitId};d({id:n,payload:g},{onSuccess:()=>{s==null||s()}})}};return e.jsx(pn,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(f),className:"space-y-4",children:[e.jsx(Jt,{control:i.control,name:"nameAm",render:({field:y})=>e.jsxs(Zt,{children:[e.jsx(er,{children:"Amharic Name"}),e.jsx(tr,{children:e.jsx(ke,{placeholder:"Enter Amharic name",...y})}),e.jsx(rr,{})]})}),e.jsx(Jt,{control:i.control,name:"nameEn",render:({field:y})=>e.jsxs(Zt,{children:[e.jsx(er,{children:"English Name"}),e.jsx(tr,{children:e.jsx(ke,{placeholder:"Enter English name",...y})}),e.jsx(rr,{})]})}),e.jsx(Jt,{control:i.control,name:"key",render:({field:y})=>e.jsxs(Zt,{children:[e.jsx(er,{children:"Key"}),e.jsx(tr,{children:e.jsx(ke,{placeholder:"Unique key",...y})}),e.jsx(rr,{})]})}),e.jsx(J,{type:"submit",disabled:m||l,children:a==="create"?m?"Creating...":"Create":l?"Updating...":"Update"})]})})}function vs({row:t,unitId:r}){var x,v,p;const[a,n]=c.useState(!1),[s,i]=c.useState(!1),[o,d]=c.useState(!1),{deleteRecordTag:m,refetchRecordTagsList:l}=Mt({unitId:r}),{t:f}=Ie(),{handleError:y}=dt(f),g=()=>{d(!0),m(t.id,{onSuccess:()=>{l(),i(!1)},onError:j=>{y(j)},onSettled:()=>{d(!1)}})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{variant:"outline",size:"sm",onClick:()=>n(!0),children:e.jsx(wr,{className:"h-4 w-4"})}),e.jsx(J,{variant:"destructive",size:"sm",onClick:()=>i(!0),children:e.jsx(Rt,{className:"h-4 w-4"})})]}),e.jsx(Qe,{open:a,onOpenChange:n,children:e.jsxs(Ge,{children:[e.jsx(We,{children:e.jsx(Ye,{children:"Edit Record Tag"})}),e.jsx(ha,{unitId:r,mode:"edit",id:t.id,defaultValues:{nameAm:((x=t.name)==null?void 0:x.am)??"",nameEn:((v=t.name)==null?void 0:v.en)??"",key:t.key,unitId:t.unitId},onSuccess:()=>{n(!1),l()}})]})}),e.jsx(Bt,{open:s,onOpenChange:i,children:e.jsxs(Ut,{children:[e.jsxs(Ht,{children:[e.jsx(Kt,{children:"Are you sure you want to delete this record tag?"}),e.jsxs(Vt,{children:["This action cannot be undone. The record tag ",e.jsx("b",{children:(p=t.name)==null?void 0:p.en})," ","will be permanently removed."]})]}),e.jsxs(Qt,{children:[e.jsx(Gt,{disabled:o,children:"Cancel"}),e.jsx(Wt,{onClick:g,disabled:o,className:"bg-red-600 hover:bg-red-700",children:o?"Deleting...":"Delete"})]})]})})]})}const js=t=>[{accessorKey:"name",header:()=>w("recordTag.name"),cell:({row:r})=>{var s;const a=At(),n=(s=r.original)==null?void 0:s.name;return e.jsx("span",{children:a(n)})}},{accessorKey:"key",header:()=>w("recordTag.key"),cell:({row:r})=>{var n;const a=(n=r.original)==null?void 0:n.key;return e.jsx("span",{children:a||"--"})}},{accessorKey:"createdAt",header:()=>w("recordTag.CreatedAt"),cell:({row:r})=>{var n;const a=(n=r.original)==null?void 0:n.createdAt;return e.jsx("span",{children:a?fn(new Date(a),"MMM d, yyyy HH:mm"):"--"})}},{id:"actions",header:()=>w("recordTag.Actions"),cell:({row:r})=>e.jsx(vs,{row:r.original,unitId:t})}];function ws({unitId:t}){const[r,a]=c.useState(0),[n,s]=c.useState(!1),{t:i}=Ie(),{recordTagsList:o,isLoadingRecordTagsList:d,refetchRecordTagsList:m}=Mt({unitId:t??""}),l=f=>{a(f)};return d?e.jsx("div",{children:i("loading")}):e.jsx("div",{className:"p-6 space-y-6",children:e.jsxs(Ke,{className:"col-span-2 shadow-none border-none bg-transparent px-0",children:[e.jsxs(it,{className:"flex flex-row justify-between items-center px-0",children:[e.jsx(ot,{className:"text-xl font-semibold",children:i("recordTag.title")}),e.jsxs(Qe,{open:n,onOpenChange:s,children:[e.jsx(jr,{asChild:!0,children:e.jsx(J,{children:i("recordTag.createNew")})}),e.jsxs(Ge,{children:[e.jsx(We,{children:e.jsx(Ye,{children:i("recordTag.createTitle")})}),e.jsx(ha,{unitId:t,mode:"create",onSuccess:()=>{s(!1),m()}})]})]})]}),e.jsx(pt,{className:"px-0",children:e.jsx(un,{columns:js(t),data:(o==null?void 0:o.items)||[],tableName:i("recordTag.tableName"),toolBarPosition:"right",itemCount:(o==null?void 0:o.count)||0,pageIndex:r,onPageChange:l,nextFunction:()=>l(r+1),prevFunction:()=>l(Math.max(r-1,0))})})]})})}const ks="adf98293-41ba-4bda-bdb4-70e30a70c1b7",Fe={"x-tenant-id":ks},Le=He,st=t=>({...t,name:t.name||{am:"",en:""},description:t.description||{am:"",en:""}}),St={async getResourceTypes(){return(await Le.get("/resource_types",{headers:Fe})).data},async getAllTemplates(t){try{const r=await Le.get("/templates",{params:t,headers:Fe});let a=(r.data.items||r.data||[]).map(st);if(t!=null&&t.search&&typeof t.search=="string"){const n=t.search.toLowerCase();a=a.filter(s=>{var i,o,d,m,l,f,y,g;return((o=(i=s.name)==null?void 0:i.en)==null?void 0:o.toLowerCase().includes(n))||((m=(d=s.name)==null?void 0:d.am)==null?void 0:m.toLowerCase().includes(n))||((f=(l=s.description)==null?void 0:l.en)==null?void 0:f.toLowerCase().includes(n))||((g=(y=s.description)==null?void 0:y.am)==null?void 0:g.toLowerCase().includes(n))})}return{count:a.length,items:a}}catch{return{count:0,items:[]}}},async getTemplates(t){const{resourceTypeId:r,search:a,...n}=t||{};if(!r)return{count:0,items:[]};let i=((await Le.get(`/resources/list-with-presigned/${r}`,{params:n,headers:Fe})).data.items||[]).map(st);if(a&&typeof a=="string"){const o=a.toLowerCase();i=i.filter(d=>{var m,l,f,y,g,x,v,p;return((l=(m=d.name)==null?void 0:m.en)==null?void 0:l.toLowerCase().includes(o))||((y=(f=d.name)==null?void 0:f.am)==null?void 0:y.toLowerCase().includes(o))||((x=(g=d.description)==null?void 0:g.en)==null?void 0:x.toLowerCase().includes(o))||((p=(v=d.description)==null?void 0:v.am)==null?void 0:p.toLowerCase().includes(o))})}return{count:i.length,items:i}},async getTemplate(t){const r=await Le.get(`/resources/with-presigned?id=${t}`,{headers:Fe});return st(r.data)},async getTemplateWithPresigned(t,r){var a;try{const i=((await Le.get(`/resources/list-with-presigned/${t}`,{headers:Fe})).data.items||[]).map(st).find(o=>o.id===r);if(!i)throw new Error("Template not found");return i}catch(n){if(((a=n.response)==null?void 0:a.status)===400)try{const i=await Le.get(`/resources/with-presigned?id=${r}`,{headers:Fe});return st(i.data)}catch{throw n}throw n}},async createTemplate(t){const r=await Le.post("/resources",t,{headers:Fe});return st(r.data)},async updateTemplate(t,r){const a=await Le.put(`/resources/${t}`,r,{headers:Fe});return st(a.data)},async deleteTemplate(t){await Le.delete(`/resources/${t}`,{headers:Fe})},async uploadFile(t,r){var s,i,o,d;if(!r)return null;const a=await hn.validateFileForUpload(t,{allowedMimeTypes:["image/png","image/jpeg","image/gif","image/webp","application/pdf"],allowedExtensions:[".png",".jpg",".jpeg",".gif",".webp",".pdf"],maxSizeMB:50,uploadContext:"signature"});if(!a.isValid)throw new Error(((s=a.clientValidation.fileName)==null?void 0:s.error)||((i=a.clientValidation.extension)==null?void 0:i.error)||((o=a.clientValidation.mimeType)==null?void 0:o.error)||((d=a.clientValidation.size)==null?void 0:d.error)||"File validation failed");const n=await fetch(r,{method:"PUT",headers:{"Content-Type":t.type},body:t});if(!n.ok){const m=await n.text();throw new Error(`Upload failed: ${n.status} ${n.statusText}
${m}`)}return n},async updateUploadStatus(t,r){await Le.put(`/resources/change-status/${t}`,{isCurrent:r},{headers:Fe})},async generateSampleTemplate(t,r){try{const a=await Le.post(`/templates/${t}/sample`,r,{responseType:"arraybuffer",headers:Fe}),n=new Blob([a.data],{type:"application/pdf"});return{pdf:URL.createObjectURL(n),contentType:"application/pdf"}}catch(a){throw a}},async getTemplateSettingsByUnit(t){try{const a=(await Le.get(`/template-settings/by-unit/${t}`,{headers:Fe})).data||{};return{count:a.count||0,items:a.items||[]}}catch{return{count:0,items:[]}}},async saveTemplateSettingValues(t){try{await Promise.all(t.map(r=>Le.post("/template-setting-values",r,{headers:Fe})))}catch(r){throw r}},async saveBulkTemplateSettingValues(t){try{await Le.post("/template-setting-values/bulk",t,{headers:Fe})}catch(r){throw r}}};var nr={exports:{}},me={};/** @license React v16.13.1
 * react-is.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var Or;function Ns(){if(Or)return me;Or=1;var t=typeof Symbol=="function"&&Symbol.for,r=t?Symbol.for("react.element"):60103,a=t?Symbol.for("react.portal"):60106,n=t?Symbol.for("react.fragment"):60107,s=t?Symbol.for("react.strict_mode"):60108,i=t?Symbol.for("react.profiler"):60114,o=t?Symbol.for("react.provider"):60109,d=t?Symbol.for("react.context"):60110,m=t?Symbol.for("react.async_mode"):60111,l=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,y=t?Symbol.for("react.suspense"):60113,g=t?Symbol.for("react.suspense_list"):60120,x=t?Symbol.for("react.memo"):60115,v=t?Symbol.for("react.lazy"):60116,p=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,E=t?Symbol.for("react.responder"):60118,b=t?Symbol.for("react.scope"):60119;function k(u){if(typeof u=="object"&&u!==null){var C=u.$$typeof;switch(C){case r:switch(u=u.type,u){case m:case l:case n:case i:case s:case y:return u;default:switch(u=u&&u.$$typeof,u){case d:case f:case v:case x:case o:return u;default:return C}}case a:return C}}}function N(u){return k(u)===l}return me.AsyncMode=m,me.ConcurrentMode=l,me.ContextConsumer=d,me.ContextProvider=o,me.Element=r,me.ForwardRef=f,me.Fragment=n,me.Lazy=v,me.Memo=x,me.Portal=a,me.Profiler=i,me.StrictMode=s,me.Suspense=y,me.isAsyncMode=function(u){return N(u)||k(u)===m},me.isConcurrentMode=N,me.isContextConsumer=function(u){return k(u)===d},me.isContextProvider=function(u){return k(u)===o},me.isElement=function(u){return typeof u=="object"&&u!==null&&u.$$typeof===r},me.isForwardRef=function(u){return k(u)===f},me.isFragment=function(u){return k(u)===n},me.isLazy=function(u){return k(u)===v},me.isMemo=function(u){return k(u)===x},me.isPortal=function(u){return k(u)===a},me.isProfiler=function(u){return k(u)===i},me.isStrictMode=function(u){return k(u)===s},me.isSuspense=function(u){return k(u)===y},me.isValidElementType=function(u){return typeof u=="string"||typeof u=="function"||u===n||u===l||u===i||u===s||u===y||u===g||typeof u=="object"&&u!==null&&(u.$$typeof===v||u.$$typeof===x||u.$$typeof===o||u.$$typeof===d||u.$$typeof===f||u.$$typeof===j||u.$$typeof===E||u.$$typeof===b||u.$$typeof===p)},me.typeOf=k,me}var Fr;function xa(){return Fr||(Fr=1,nr.exports=Ns()),nr.exports}var ya=xa();function Ss(t){function r(O,R,L,T,h){for(var U=0,P=0,Z=0,ee=0,te,q,de=0,fe=0,Q,le=Q=te=0,G=0,oe=0,Re=0,ye=0,$e=L.length,ze=$e-1,Se,H="",ue="",D="",we="",S;G<$e;){if(q=L.charCodeAt(G),G===ze&&P+ee+Z+U!==0&&(P!==0&&(q=P===47?10:47),ee=Z=U=0,$e++,ze++),P+ee+Z+U===0){if(G===ze&&(0<oe&&(H=H.replace(g,"")),0<H.trim().length)){switch(q){case 32:case 9:case 59:case 13:case 10:break;default:H+=L.charAt(G)}q=59}switch(q){case 123:for(H=H.trim(),te=H.charCodeAt(0),Q=1,ye=++G;G<$e;){switch(q=L.charCodeAt(G)){case 123:Q++;break;case 125:Q--;break;case 47:switch(q=L.charCodeAt(G+1)){case 42:case 47:e:{for(le=G+1;le<ze;++le)switch(L.charCodeAt(le)){case 47:if(q===42&&L.charCodeAt(le-1)===42&&G+2!==le){G=le+1;break e}break;case 10:if(q===47){G=le+1;break e}}G=le}}break;case 91:q++;case 40:q++;case 34:case 39:for(;G++<ze&&L.charCodeAt(G)!==q;);}if(Q===0)break;G++}switch(Q=L.substring(ye,G),te===0&&(te=(H=H.replace(y,"").trim()).charCodeAt(0)),te){case 64:switch(0<oe&&(H=H.replace(g,"")),q=H.charCodeAt(1),q){case 100:case 109:case 115:case 45:oe=R;break;default:oe=W}if(Q=r(R,oe,Q,q,h+1),ye=Q.length,0<ie&&(oe=a(W,H,Re),S=d(3,Q,oe,R,_,F,ye,q,h,T),H=oe.join(""),S!==void 0&&(ye=(Q=S.trim()).length)===0&&(q=0,Q="")),0<ye)switch(q){case 115:H=H.replace(C,o);case 100:case 109:case 45:Q=H+"{"+Q+"}";break;case 107:H=H.replace(b,"$1 $2"),Q=H+"{"+Q+"}",Q=X===1||X===2&&i("@"+Q,3)?"@-webkit-"+Q+"@"+Q:"@"+Q;break;default:Q=H+Q,T===112&&(Q=(ue+=Q,""))}else Q="";break;default:Q=r(R,a(R,H,Re),Q,T,h+1)}D+=Q,Q=Re=oe=le=te=0,H="",q=L.charCodeAt(++G);break;case 125:case 59:if(H=(0<oe?H.replace(g,""):H).trim(),1<(ye=H.length))switch(le===0&&(te=H.charCodeAt(0),te===45||96<te&&123>te)&&(ye=(H=H.replace(" ",":")).length),0<ie&&(S=d(1,H,R,O,_,F,ue.length,T,h,T))!==void 0&&(ye=(H=S.trim()).length)===0&&(H="\0\0"),te=H.charCodeAt(0),q=H.charCodeAt(1),te){case 0:break;case 64:if(q===105||q===99){we+=H+L.charAt(G);break}default:H.charCodeAt(ye-1)!==58&&(ue+=s(H,te,q,H.charCodeAt(2)))}Re=oe=le=te=0,H="",q=L.charCodeAt(++G)}}switch(q){case 13:case 10:P===47?P=0:1+te===0&&T!==107&&0<H.length&&(oe=1,H+="\0"),0<ie*je&&d(0,H,R,O,_,F,ue.length,T,h,T),F=1,_++;break;case 59:case 125:if(P+ee+Z+U===0){F++;break}default:switch(F++,Se=L.charAt(G),q){case 9:case 32:if(ee+U+P===0)switch(de){case 44:case 58:case 9:case 32:Se="";break;default:q!==32&&(Se=" ")}break;case 0:Se="\\0";break;case 12:Se="\\f";break;case 11:Se="\\v";break;case 38:ee+P+U===0&&(oe=Re=1,Se="\f"+Se);break;case 108:if(ee+P+U+ne===0&&0<le)switch(G-le){case 2:de===112&&L.charCodeAt(G-3)===58&&(ne=de);case 8:fe===111&&(ne=fe)}break;case 58:ee+P+U===0&&(le=G);break;case 44:P+Z+ee+U===0&&(oe=1,Se+="\r");break;case 34:case 39:P===0&&(ee=ee===q?0:ee===0?q:ee);break;case 91:ee+P+Z===0&&U++;break;case 93:ee+P+Z===0&&U--;break;case 41:ee+P+U===0&&Z--;break;case 40:if(ee+P+U===0){if(te===0)switch(2*de+3*fe){case 533:break;default:te=1}Z++}break;case 64:P+Z+ee+U+le+Q===0&&(Q=1);break;case 42:case 47:if(!(0<ee+U+Z))switch(P){case 0:switch(2*q+3*L.charCodeAt(G+1)){case 235:P=47;break;case 220:ye=G,P=42}break;case 42:q===47&&de===42&&ye+2!==G&&(L.charCodeAt(ye+2)===33&&(ue+=L.substring(ye,G+1)),Se="",P=0)}}P===0&&(H+=Se)}fe=de,de=q,G++}if(ye=ue.length,0<ye){if(oe=R,0<ie&&(S=d(2,ue,oe,O,_,F,ye,T,h,T),S!==void 0&&(ue=S).length===0))return we+ue+D;if(ue=oe.join(",")+"{"+ue+"}",X*ne!==0){switch(X!==2||i(ue,2)||(ne=0),ne){case 111:ue=ue.replace(N,":-moz-$1")+ue;break;case 112:ue=ue.replace(k,"::-webkit-input-$1")+ue.replace(k,"::-moz-$1")+ue.replace(k,":-ms-input-$1")+ue}ne=0}}return we+ue+D}function a(O,R,L){var T=R.trim().split(j);R=T;var h=T.length,U=O.length;switch(U){case 0:case 1:var P=0;for(O=U===0?"":O[0]+" ";P<h;++P)R[P]=n(O,R[P],L).trim();break;default:var Z=P=0;for(R=[];P<h;++P)for(var ee=0;ee<U;++ee)R[Z++]=n(O[ee]+" ",T[P],L).trim()}return R}function n(O,R,L){var T=R.charCodeAt(0);switch(33>T&&(T=(R=R.trim()).charCodeAt(0)),T){case 38:return R.replace(E,"$1"+O.trim());case 58:return O.trim()+R.replace(E,"$1"+O.trim());default:if(0<1*L&&0<R.indexOf("\f"))return R.replace(E,(O.charCodeAt(0)===58?"":"$1")+O.trim())}return O+R}function s(O,R,L,T){var h=O+";",U=2*R+3*L+4*T;if(U===944){O=h.indexOf(":",9)+1;var P=h.substring(O,h.length-1).trim();return P=h.substring(0,O).trim()+P+";",X===1||X===2&&i(P,1)?"-webkit-"+P+P:P}if(X===0||X===2&&!i(h,1))return h;switch(U){case 1015:return h.charCodeAt(10)===97?"-webkit-"+h+h:h;case 951:return h.charCodeAt(3)===116?"-webkit-"+h+h:h;case 963:return h.charCodeAt(5)===110?"-webkit-"+h+h:h;case 1009:if(h.charCodeAt(4)!==100)break;case 969:case 942:return"-webkit-"+h+h;case 978:return"-webkit-"+h+"-moz-"+h+h;case 1019:case 983:return"-webkit-"+h+"-moz-"+h+"-ms-"+h+h;case 883:if(h.charCodeAt(8)===45)return"-webkit-"+h+h;if(0<h.indexOf("image-set(",11))return h.replace($,"$1-webkit-$2")+h;break;case 932:if(h.charCodeAt(4)===45)switch(h.charCodeAt(5)){case 103:return"-webkit-box-"+h.replace("-grow","")+"-webkit-"+h+"-ms-"+h.replace("grow","positive")+h;case 115:return"-webkit-"+h+"-ms-"+h.replace("shrink","negative")+h;case 98:return"-webkit-"+h+"-ms-"+h.replace("basis","preferred-size")+h}return"-webkit-"+h+"-ms-"+h+h;case 964:return"-webkit-"+h+"-ms-flex-"+h+h;case 1023:if(h.charCodeAt(8)!==99)break;return P=h.substring(h.indexOf(":",15)).replace("flex-","").replace("space-between","justify"),"-webkit-box-pack"+P+"-webkit-"+h+"-ms-flex-pack"+P+h;case 1005:return v.test(h)?h.replace(x,":-webkit-")+h.replace(x,":-moz-")+h:h;case 1e3:switch(P=h.substring(13).trim(),R=P.indexOf("-")+1,P.charCodeAt(0)+P.charCodeAt(R)){case 226:P=h.replace(u,"tb");break;case 232:P=h.replace(u,"tb-rl");break;case 220:P=h.replace(u,"lr");break;default:return h}return"-webkit-"+h+"-ms-"+P+h;case 1017:if(h.indexOf("sticky",9)===-1)break;case 975:switch(R=(h=O).length-10,P=(h.charCodeAt(R)===33?h.substring(0,R):h).substring(O.indexOf(":",7)+1).trim(),U=P.charCodeAt(0)+(P.charCodeAt(7)|0)){case 203:if(111>P.charCodeAt(8))break;case 115:h=h.replace(P,"-webkit-"+P)+";"+h;break;case 207:case 102:h=h.replace(P,"-webkit-"+(102<U?"inline-":"")+"box")+";"+h.replace(P,"-webkit-"+P)+";"+h.replace(P,"-ms-"+P+"box")+";"+h}return h+";";case 938:if(h.charCodeAt(5)===45)switch(h.charCodeAt(6)){case 105:return P=h.replace("-items",""),"-webkit-"+h+"-webkit-box-"+P+"-ms-flex-"+P+h;case 115:return"-webkit-"+h+"-ms-flex-item-"+h.replace(I,"")+h;default:return"-webkit-"+h+"-ms-flex-line-pack"+h.replace("align-content","").replace(I,"")+h}break;case 973:case 989:if(h.charCodeAt(3)!==45||h.charCodeAt(4)===122)break;case 931:case 953:if(Y.test(O)===!0)return(P=O.substring(O.indexOf(":")+1)).charCodeAt(0)===115?s(O.replace("stretch","fill-available"),R,L,T).replace(":fill-available",":stretch"):h.replace(P,"-webkit-"+P)+h.replace(P,"-moz-"+P.replace("fill-",""))+h;break;case 962:if(h="-webkit-"+h+(h.charCodeAt(5)===102?"-ms-"+h:"")+h,L+T===211&&h.charCodeAt(13)===105&&0<h.indexOf("transform",10))return h.substring(0,h.indexOf(";",27)+1).replace(p,"$1-webkit-$2")+h}return h}function i(O,R){var L=O.indexOf(R===1?":":"{"),T=O.substring(0,R!==3?L:10);return L=O.substring(L+1,O.length-1),Ae(R!==2?T:T.replace(se,"$1"),L,R)}function o(O,R){var L=s(R,R.charCodeAt(0),R.charCodeAt(1),R.charCodeAt(2));return L!==R+";"?L.replace(M," or ($1)").substring(4):"("+R+")"}function d(O,R,L,T,h,U,P,Z,ee,te){for(var q=0,de=R,fe;q<ie;++q)switch(fe=xe[q].call(f,O,de,L,T,h,U,P,Z,ee,te)){case void 0:case!1:case!0:case null:break;default:de=fe}if(de!==R)return de}function m(O){switch(O){case void 0:case null:ie=xe.length=0;break;default:if(typeof O=="function")xe[ie++]=O;else if(typeof O=="object")for(var R=0,L=O.length;R<L;++R)m(O[R]);else je=!!O|0}return m}function l(O){return O=O.prefix,O!==void 0&&(Ae=null,O?typeof O!="function"?X=1:(X=2,Ae=O):X=0),l}function f(O,R){var L=O;if(33>L.charCodeAt(0)&&(L=L.trim()),z=L,L=[z],0<ie){var T=d(-1,R,L,L,_,F,0,0,0,0);T!==void 0&&typeof T=="string"&&(R=T)}var h=r(W,L,R,0,0);return 0<ie&&(T=d(-2,h,L,L,_,F,h.length,0,0,0),T!==void 0&&(h=T)),z="",ne=0,F=_=1,h}var y=/^\0+/g,g=/[\0\r\f]/g,x=/: */g,v=/zoo|gra/,p=/([,: ])(transform)/g,j=/,\r+?/g,E=/([\t\r\n ])*\f?&/g,b=/@(k\w+)\s*(\S*)\s*/,k=/::(place)/g,N=/:(read-only)/g,u=/[svh]\w+-[tblr]{2}/,C=/\(\s*(.*)\s*\)/g,M=/([\s\S]*?);/g,I=/-self|flex-/g,se=/[^]*?(:[rp][el]a[\w-]+)[^]*/,Y=/stretch|:\s*\w+\-(?:conte|avail)/,$=/([^-])(image-set\()/,F=1,_=1,ne=0,X=1,W=[],xe=[],ie=0,Ae=null,je=0,z="";return f.use=m,f.set=l,t!==void 0&&l(t),f}var Cs={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1};function Ps(t){var r=Object.create(null);return function(a){return r[a]===void 0&&(r[a]=t(a)),r[a]}}var Ts=/^((children|dangerouslySetInnerHTML|key|ref|autoFocus|defaultValue|defaultChecked|innerHTML|suppressContentEditableWarning|suppressHydrationWarning|valueLink|abbr|accept|acceptCharset|accessKey|action|allow|allowUserMedia|allowPaymentRequest|allowFullScreen|allowTransparency|alt|async|autoComplete|autoPlay|capture|cellPadding|cellSpacing|challenge|charSet|checked|cite|classID|className|cols|colSpan|content|contentEditable|contextMenu|controls|controlsList|coords|crossOrigin|data|dateTime|decoding|default|defer|dir|disabled|disablePictureInPicture|disableRemotePlayback|download|draggable|encType|enterKeyHint|fetchpriority|fetchPriority|form|formAction|formEncType|formMethod|formNoValidate|formTarget|frameBorder|headers|height|hidden|high|href|hrefLang|htmlFor|httpEquiv|id|inputMode|integrity|is|keyParams|keyType|kind|label|lang|list|loading|loop|low|marginHeight|marginWidth|max|maxLength|media|mediaGroup|method|min|minLength|multiple|muted|name|nonce|noValidate|open|optimum|pattern|placeholder|playsInline|popover|popoverTarget|popoverTargetAction|poster|preload|profile|radioGroup|readOnly|referrerPolicy|rel|required|reversed|role|rows|rowSpan|sandbox|scope|scoped|scrolling|seamless|selected|shape|size|sizes|slot|span|spellCheck|src|srcDoc|srcLang|srcSet|start|step|style|summary|tabIndex|target|title|translate|type|useMap|value|width|wmode|wrap|about|datatype|inlist|prefix|property|resource|typeof|vocab|autoCapitalize|autoCorrect|autoSave|color|incremental|fallback|inert|itemProp|itemScope|itemType|itemID|itemRef|on|option|results|security|unselectable|accentHeight|accumulate|additive|alignmentBaseline|allowReorder|alphabetic|amplitude|arabicForm|ascent|attributeName|attributeType|autoReverse|azimuth|baseFrequency|baselineShift|baseProfile|bbox|begin|bias|by|calcMode|capHeight|clip|clipPathUnits|clipPath|clipRule|colorInterpolation|colorInterpolationFilters|colorProfile|colorRendering|contentScriptType|contentStyleType|cursor|cx|cy|d|decelerate|descent|diffuseConstant|direction|display|divisor|dominantBaseline|dur|dx|dy|edgeMode|elevation|enableBackground|end|exponent|externalResourcesRequired|fill|fillOpacity|fillRule|filter|filterRes|filterUnits|floodColor|floodOpacity|focusable|fontFamily|fontSize|fontSizeAdjust|fontStretch|fontStyle|fontVariant|fontWeight|format|from|fr|fx|fy|g1|g2|glyphName|glyphOrientationHorizontal|glyphOrientationVertical|glyphRef|gradientTransform|gradientUnits|hanging|horizAdvX|horizOriginX|ideographic|imageRendering|in|in2|intercept|k|k1|k2|k3|k4|kernelMatrix|kernelUnitLength|kerning|keyPoints|keySplines|keyTimes|lengthAdjust|letterSpacing|lightingColor|limitingConeAngle|local|markerEnd|markerMid|markerStart|markerHeight|markerUnits|markerWidth|mask|maskContentUnits|maskUnits|mathematical|mode|numOctaves|offset|opacity|operator|order|orient|orientation|origin|overflow|overlinePosition|overlineThickness|panose1|paintOrder|pathLength|patternContentUnits|patternTransform|patternUnits|pointerEvents|points|pointsAtX|pointsAtY|pointsAtZ|preserveAlpha|preserveAspectRatio|primitiveUnits|r|radius|refX|refY|renderingIntent|repeatCount|repeatDur|requiredExtensions|requiredFeatures|restart|result|rotate|rx|ry|scale|seed|shapeRendering|slope|spacing|specularConstant|specularExponent|speed|spreadMethod|startOffset|stdDeviation|stemh|stemv|stitchTiles|stopColor|stopOpacity|strikethroughPosition|strikethroughThickness|string|stroke|strokeDasharray|strokeDashoffset|strokeLinecap|strokeLinejoin|strokeMiterlimit|strokeOpacity|strokeWidth|surfaceScale|systemLanguage|tableValues|targetX|targetY|textAnchor|textDecoration|textRendering|textLength|to|transform|u1|u2|underlinePosition|underlineThickness|unicode|unicodeBidi|unicodeRange|unitsPerEm|vAlphabetic|vHanging|vIdeographic|vMathematical|values|vectorEffect|version|vertAdvY|vertOriginX|vertOriginY|viewBox|viewTarget|visibility|widths|wordSpacing|writingMode|x|xHeight|x1|x2|xChannelSelector|xlinkActuate|xlinkArcrole|xlinkHref|xlinkRole|xlinkShow|xlinkTitle|xlinkType|xmlBase|xmlns|xmlnsXlink|xmlLang|xmlSpace|y|y1|y2|yChannelSelector|z|zoomAndPan|for|class|autofocus)|(([Dd][Aa][Tt][Aa]|[Aa][Rr][Ii][Aa]|x)-.*))$/,Lr=Ps(function(t){return Ts.test(t)||t.charCodeAt(0)===111&&t.charCodeAt(1)===110&&t.charCodeAt(2)<91}),sr,_r;function Es(){if(_r)return sr;_r=1;var t=xa(),r={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},a={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},n={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},s={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},i={};i[t.ForwardRef]=n,i[t.Memo]=s;function o(v){return t.isMemo(v)?s:i[v.$$typeof]||r}var d=Object.defineProperty,m=Object.getOwnPropertyNames,l=Object.getOwnPropertySymbols,f=Object.getOwnPropertyDescriptor,y=Object.getPrototypeOf,g=Object.prototype;function x(v,p,j){if(typeof p!="string"){if(g){var E=y(p);E&&E!==g&&x(v,E,j)}var b=m(p);l&&(b=b.concat(l(p)));for(var k=o(v),N=o(p),u=0;u<b.length;++u){var C=b[u];if(!a[C]&&!(j&&j[C])&&!(N&&N[C])&&!(k&&k[C])){var M=f(p,C);try{d(v,C,M)}catch{}}}}return v}return sr=x,sr}var As=Es();const Rs=$a(As);var Be={};function Xe(){return(Xe=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(t[n]=a[n])}return t}).apply(this,arguments)}var Dr=function(t,r){for(var a=[t[0]],n=0,s=r.length;n<s;n+=1)a.push(r[n],t[n+1]);return a},dr=function(t){return t!==null&&typeof t=="object"&&(t.toString?t.toString():Object.prototype.toString.call(t))==="[object Object]"&&!ya.typeOf(t)},$t=Object.freeze([]),rt=Object.freeze({});function Et(t){return typeof t=="function"}function Ir(t){return t.displayName||t.name||"Component"}function Sr(t){return t&&typeof t.styledComponentId=="string"}var vt=typeof process<"u"&&Be!==void 0&&(Be.REACT_APP_SC_ATTR||Be.SC_ATTR)||"data-styled",Cr=typeof window<"u"&&"HTMLElement"in window,Ms=!!(typeof SC_DISABLE_SPEEDY=="boolean"?SC_DISABLE_SPEEDY:typeof process<"u"&&Be!==void 0&&(Be.REACT_APP_SC_DISABLE_SPEEDY!==void 0&&Be.REACT_APP_SC_DISABLE_SPEEDY!==""?Be.REACT_APP_SC_DISABLE_SPEEDY!=="false"&&Be.REACT_APP_SC_DISABLE_SPEEDY:Be.SC_DISABLE_SPEEDY!==void 0&&Be.SC_DISABLE_SPEEDY!==""&&Be.SC_DISABLE_SPEEDY!=="false"&&Be.SC_DISABLE_SPEEDY));function Ot(t){for(var r=arguments.length,a=new Array(r>1?r-1:0),n=1;n<r;n++)a[n-1]=arguments[n];throw new Error("An error occurred. See https://git.io/JUIaE#"+t+" for more information."+(a.length>0?" Args: "+a.join(", "):""))}var Os=(function(){function t(a){this.groupSizes=new Uint32Array(512),this.length=512,this.tag=a}var r=t.prototype;return r.indexOfGroup=function(a){for(var n=0,s=0;s<a;s++)n+=this.groupSizes[s];return n},r.insertRules=function(a,n){if(a>=this.groupSizes.length){for(var s=this.groupSizes,i=s.length,o=i;a>=o;)(o<<=1)<0&&Ot(16,""+a);this.groupSizes=new Uint32Array(o),this.groupSizes.set(s),this.length=o;for(var d=i;d<o;d++)this.groupSizes[d]=0}for(var m=this.indexOfGroup(a+1),l=0,f=n.length;l<f;l++)this.tag.insertRule(m,n[l])&&(this.groupSizes[a]++,m++)},r.clearGroup=function(a){if(a<this.length){var n=this.groupSizes[a],s=this.indexOfGroup(a),i=s+n;this.groupSizes[a]=0;for(var o=s;o<i;o++)this.tag.deleteRule(s)}},r.getGroup=function(a){var n="";if(a>=this.length||this.groupSizes[a]===0)return n;for(var s=this.groupSizes[a],i=this.indexOfGroup(a),o=i+s,d=i;d<o;d++)n+=this.tag.getRule(d)+`/*!sc*/
`;return n},t})(),It=new Map,zt=new Map,Ct=1,_t=function(t){if(It.has(t))return It.get(t);for(;zt.has(Ct);)Ct++;var r=Ct++;return It.set(t,r),zt.set(r,t),r},Fs=function(t){return zt.get(t)},Ls=function(t,r){r>=Ct&&(Ct=r+1),It.set(t,r),zt.set(r,t)},_s="style["+vt+'][data-styled-version="5.3.11"]',Ds=new RegExp("^"+vt+'\\.g(\\d+)\\[id="([\\w\\d-]+)"\\].*?"([^"]*)'),Is=function(t,r,a){for(var n,s=a.split(","),i=0,o=s.length;i<o;i++)(n=s[i])&&t.registerName(r,n)},$s=function(t,r){for(var a=(r.textContent||"").split(`/*!sc*/
`),n=[],s=0,i=a.length;s<i;s++){var o=a[s].trim();if(o){var d=o.match(Ds);if(d){var m=0|parseInt(d[1],10),l=d[2];m!==0&&(Ls(l,m),Is(t,l,d[3]),t.getTag().insertRules(m,n)),n.length=0}else n.push(o)}}},zs=function(){return typeof __webpack_nonce__<"u"?__webpack_nonce__:null},ba=function(t){var r=document.head,a=t||r,n=document.createElement("style"),s=(function(d){for(var m=d.childNodes,l=m.length;l>=0;l--){var f=m[l];if(f&&f.nodeType===1&&f.hasAttribute(vt))return f}})(a),i=s!==void 0?s.nextSibling:null;n.setAttribute(vt,"active"),n.setAttribute("data-styled-version","5.3.11");var o=zs();return o&&n.setAttribute("nonce",o),a.insertBefore(n,i),n},qs=(function(){function t(a){var n=this.element=ba(a);n.appendChild(document.createTextNode("")),this.sheet=(function(s){if(s.sheet)return s.sheet;for(var i=document.styleSheets,o=0,d=i.length;o<d;o++){var m=i[o];if(m.ownerNode===s)return m}Ot(17)})(n),this.length=0}var r=t.prototype;return r.insertRule=function(a,n){try{return this.sheet.insertRule(n,a),this.length++,!0}catch{return!1}},r.deleteRule=function(a){this.sheet.deleteRule(a),this.length--},r.getRule=function(a){var n=this.sheet.cssRules[a];return n!==void 0&&typeof n.cssText=="string"?n.cssText:""},t})(),Bs=(function(){function t(a){var n=this.element=ba(a);this.nodes=n.childNodes,this.length=0}var r=t.prototype;return r.insertRule=function(a,n){if(a<=this.length&&a>=0){var s=document.createTextNode(n),i=this.nodes[a];return this.element.insertBefore(s,i||null),this.length++,!0}return!1},r.deleteRule=function(a){this.element.removeChild(this.nodes[a]),this.length--},r.getRule=function(a){return a<this.length?this.nodes[a].textContent:""},t})(),Us=(function(){function t(a){this.rules=[],this.length=0}var r=t.prototype;return r.insertRule=function(a,n){return a<=this.length&&(this.rules.splice(a,0,n),this.length++,!0)},r.deleteRule=function(a){this.rules.splice(a,1),this.length--},r.getRule=function(a){return a<this.length?this.rules[a]:""},t})(),$r=Cr,Hs={isServer:!Cr,useCSSOMInjection:!Ms},va=(function(){function t(a,n,s){a===void 0&&(a=rt),n===void 0&&(n={}),this.options=Xe({},Hs,{},a),this.gs=n,this.names=new Map(s),this.server=!!a.isServer,!this.server&&Cr&&$r&&($r=!1,(function(i){for(var o=document.querySelectorAll(_s),d=0,m=o.length;d<m;d++){var l=o[d];l&&l.getAttribute(vt)!=="active"&&($s(i,l),l.parentNode&&l.parentNode.removeChild(l))}})(this))}t.registerId=function(a){return _t(a)};var r=t.prototype;return r.reconstructWithOptions=function(a,n){return n===void 0&&(n=!0),new t(Xe({},this.options,{},a),this.gs,n&&this.names||void 0)},r.allocateGSInstance=function(a){return this.gs[a]=(this.gs[a]||0)+1},r.getTag=function(){return this.tag||(this.tag=(s=(n=this.options).isServer,i=n.useCSSOMInjection,o=n.target,a=s?new Us(o):i?new qs(o):new Bs(o),new Os(a)));var a,n,s,i,o},r.hasNameForId=function(a,n){return this.names.has(a)&&this.names.get(a).has(n)},r.registerName=function(a,n){if(_t(a),this.names.has(a))this.names.get(a).add(n);else{var s=new Set;s.add(n),this.names.set(a,s)}},r.insertRules=function(a,n,s){this.registerName(a,n),this.getTag().insertRules(_t(a),s)},r.clearNames=function(a){this.names.has(a)&&this.names.get(a).clear()},r.clearRules=function(a){this.getTag().clearGroup(_t(a)),this.clearNames(a)},r.clearTag=function(){this.tag=void 0},r.toString=function(){return(function(a){for(var n=a.getTag(),s=n.length,i="",o=0;o<s;o++){var d=Fs(o);if(d!==void 0){var m=a.names.get(d),l=n.getGroup(o);if(m&&l&&m.size){var f=vt+".g"+o+'[id="'+d+'"]',y="";m!==void 0&&m.forEach((function(g){g.length>0&&(y+=g+",")})),i+=""+l+f+'{content:"'+y+`"}/*!sc*/
`}}}return i})(this)},t})(),Ks=/(a)(d)/gi,zr=function(t){return String.fromCharCode(t+(t>25?39:97))};function ur(t){var r,a="";for(r=Math.abs(t);r>52;r=r/52|0)a=zr(r%52)+a;return(zr(r%52)+a).replace(Ks,"$1-$2")}var gt=function(t,r){for(var a=r.length;a;)t=33*t^r.charCodeAt(--a);return t},ja=function(t){return gt(5381,t)};function Vs(t){for(var r=0;r<t.length;r+=1){var a=t[r];if(Et(a)&&!Sr(a))return!1}return!0}var Qs=ja("5.3.11"),Gs=(function(){function t(r,a,n){this.rules=r,this.staticRulesId="",this.isStatic=(n===void 0||n.isStatic)&&Vs(r),this.componentId=a,this.baseHash=gt(Qs,a),this.baseStyle=n,va.registerId(a)}return t.prototype.generateAndInjectStyles=function(r,a,n){var s=this.componentId,i=[];if(this.baseStyle&&i.push(this.baseStyle.generateAndInjectStyles(r,a,n)),this.isStatic&&!n.hash)if(this.staticRulesId&&a.hasNameForId(s,this.staticRulesId))i.push(this.staticRulesId);else{var o=jt(this.rules,r,a,n).join(""),d=ur(gt(this.baseHash,o)>>>0);if(!a.hasNameForId(s,d)){var m=n(o,"."+d,void 0,s);a.insertRules(s,d,m)}i.push(d),this.staticRulesId=d}else{for(var l=this.rules.length,f=gt(this.baseHash,n.hash),y="",g=0;g<l;g++){var x=this.rules[g];if(typeof x=="string")y+=x;else if(x){var v=jt(x,r,a,n),p=Array.isArray(v)?v.join(""):v;f=gt(f,p+g),y+=p}}if(y){var j=ur(f>>>0);if(!a.hasNameForId(s,j)){var E=n(y,"."+j,void 0,s);a.insertRules(s,j,E)}i.push(j)}}return i.join(" ")},t})(),Ws=/^\s*\/\/.*$/gm,Ys=[":","[",".","#"];function Xs(t){var r,a,n,s,i=rt,o=i.options,d=o===void 0?rt:o,m=i.plugins,l=m===void 0?$t:m,f=new Ss(d),y=[],g=(function(p){function j(E){if(E)try{p(E+"}")}catch{}}return function(E,b,k,N,u,C,M,I,se,Y){switch(E){case 1:if(se===0&&b.charCodeAt(0)===64)return p(b+";"),"";break;case 2:if(I===0)return b+"/*|*/";break;case 3:switch(I){case 102:case 112:return p(k[0]+b),"";default:return b+(Y===0?"/*|*/":"")}case-2:b.split("/*|*/}").forEach(j)}}})((function(p){y.push(p)})),x=function(p,j,E){return j===0&&Ys.indexOf(E[a.length])!==-1||E.match(s)?p:"."+r};function v(p,j,E,b){b===void 0&&(b="&");var k=p.replace(Ws,""),N=j&&E?E+" "+j+" { "+k+" }":k;return r=b,a=j,n=new RegExp("\\"+a+"\\b","g"),s=new RegExp("(\\"+a+"\\b){2,}"),f(E||!j?"":j,N)}return f.use([].concat(l,[function(p,j,E){p===2&&E.length&&E[0].lastIndexOf(a)>0&&(E[0]=E[0].replace(n,x))},g,function(p){if(p===-2){var j=y;return y=[],j}}])),v.hash=l.length?l.reduce((function(p,j){return j.name||Ot(15),gt(p,j.name)}),5381).toString():"",v}var wa=pe.createContext();wa.Consumer;var ka=pe.createContext(),Js=(ka.Consumer,new va),mr=Xs();function Zs(){return c.useContext(wa)||Js}function ei(){return c.useContext(ka)||mr}var ti=(function(){function t(r,a){var n=this;this.inject=function(s,i){i===void 0&&(i=mr);var o=n.name+i.hash;s.hasNameForId(n.id,o)||s.insertRules(n.id,o,i(n.rules,o,"@keyframes"))},this.toString=function(){return Ot(12,String(n.name))},this.name=r,this.id="sc-keyframes-"+r,this.rules=a}return t.prototype.getName=function(r){return r===void 0&&(r=mr),this.name+r.hash},t})(),ri=/([A-Z])/,ai=/([A-Z])/g,ni=/^ms-/,si=function(t){return"-"+t.toLowerCase()};function qr(t){return ri.test(t)?t.replace(ai,si).replace(ni,"-ms-"):t}var Br=function(t){return t==null||t===!1||t===""};function jt(t,r,a,n){if(Array.isArray(t)){for(var s,i=[],o=0,d=t.length;o<d;o+=1)(s=jt(t[o],r,a,n))!==""&&(Array.isArray(s)?i.push.apply(i,s):i.push(s));return i}if(Br(t))return"";if(Sr(t))return"."+t.styledComponentId;if(Et(t)){if(typeof(l=t)!="function"||l.prototype&&l.prototype.isReactComponent||!r)return t;var m=t(r);return jt(m,r,a,n)}var l;return t instanceof ti?a?(t.inject(a,n),t.getName(n)):t:dr(t)?(function f(y,g){var x,v,p=[];for(var j in y)y.hasOwnProperty(j)&&!Br(y[j])&&(Array.isArray(y[j])&&y[j].isCss||Et(y[j])?p.push(qr(j)+":",y[j],";"):dr(y[j])?p.push.apply(p,f(y[j],j)):p.push(qr(j)+": "+(x=j,(v=y[j])==null||typeof v=="boolean"||v===""?"":typeof v!="number"||v===0||x in Cs||x.startsWith("--")?String(v).trim():v+"px")+";"));return g?[g+" {"].concat(p,["}"]):p})(t):t.toString()}var Ur=function(t){return Array.isArray(t)&&(t.isCss=!0),t};function ii(t){for(var r=arguments.length,a=new Array(r>1?r-1:0),n=1;n<r;n++)a[n-1]=arguments[n];return Et(t)||dr(t)?Ur(jt(Dr($t,[t].concat(a)))):a.length===0&&t.length===1&&typeof t[0]=="string"?t:Ur(jt(Dr(t,a)))}var oi=function(t,r,a){return a===void 0&&(a=rt),t.theme!==a.theme&&t.theme||r||a.theme},li=/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~-]+/g,ci=/(^-|-$)/g;function ir(t){return t.replace(li,"-").replace(ci,"")}var di=function(t){return ur(ja(t)>>>0)};function Dt(t){return typeof t=="string"&&!0}var gr=function(t){return typeof t=="function"||typeof t=="object"&&t!==null&&!Array.isArray(t)},ui=function(t){return t!=="__proto__"&&t!=="constructor"&&t!=="prototype"};function mi(t,r,a){var n=t[a];gr(r)&&gr(n)?Na(n,r):t[a]=r}function Na(t){for(var r=arguments.length,a=new Array(r>1?r-1:0),n=1;n<r;n++)a[n-1]=arguments[n];for(var s=0,i=a;s<i.length;s++){var o=i[s];if(gr(o))for(var d in o)ui(d)&&mi(t,o[d],d)}return t}var Sa=pe.createContext();Sa.Consumer;var or={};function Ca(t,r,a){var n=Sr(t),s=!Dt(t),i=r.attrs,o=i===void 0?$t:i,d=r.componentId,m=d===void 0?(function(b,k){var N=typeof b!="string"?"sc":ir(b);or[N]=(or[N]||0)+1;var u=N+"-"+di("5.3.11"+N+or[N]);return k?k+"-"+u:u})(r.displayName,r.parentComponentId):d,l=r.displayName,f=l===void 0?(function(b){return Dt(b)?"styled."+b:"Styled("+Ir(b)+")"})(t):l,y=r.displayName&&r.componentId?ir(r.displayName)+"-"+r.componentId:r.componentId||m,g=n&&t.attrs?Array.prototype.concat(t.attrs,o).filter(Boolean):o,x=r.shouldForwardProp;n&&t.shouldForwardProp&&(x=r.shouldForwardProp?function(b,k,N){return t.shouldForwardProp(b,k,N)&&r.shouldForwardProp(b,k,N)}:t.shouldForwardProp);var v,p=new Gs(a,y,n?t.componentStyle:void 0),j=p.isStatic&&o.length===0,E=function(b,k){return(function(N,u,C,M){var I=N.attrs,se=N.componentStyle,Y=N.defaultProps,$=N.foldedComponentIds,F=N.shouldForwardProp,_=N.styledComponentId,ne=N.target,X=(function(T,h,U){T===void 0&&(T=rt);var P=Xe({},h,{theme:T}),Z={};return U.forEach((function(ee){var te,q,de,fe=ee;for(te in Et(fe)&&(fe=fe(P)),fe)P[te]=Z[te]=te==="className"?(q=Z[te],de=fe[te],q&&de?q+" "+de:q||de):fe[te]})),[P,Z]})(oi(u,c.useContext(Sa),Y)||rt,u,I),W=X[0],xe=X[1],ie=(function(T,h,U,P){var Z=Zs(),ee=ei(),te=h?T.generateAndInjectStyles(rt,Z,ee):T.generateAndInjectStyles(U,Z,ee);return te})(se,M,W),Ae=C,je=xe.$as||u.$as||xe.as||u.as||ne,z=Dt(je),O=xe!==u?Xe({},u,{},xe):u,R={};for(var L in O)L[0]!=="$"&&L!=="as"&&(L==="forwardedAs"?R.as=O[L]:(F?F(L,Lr,je):!z||Lr(L))&&(R[L]=O[L]));return u.style&&xe.style!==u.style&&(R.style=Xe({},u.style,{},xe.style)),R.className=Array.prototype.concat($,_,ie!==_?ie:null,u.className,xe.className).filter(Boolean).join(" "),R.ref=Ae,c.createElement(je,R)})(v,b,k,j)};return E.displayName=f,(v=pe.forwardRef(E)).attrs=g,v.componentStyle=p,v.displayName=f,v.shouldForwardProp=x,v.foldedComponentIds=n?Array.prototype.concat(t.foldedComponentIds,t.styledComponentId):$t,v.styledComponentId=y,v.target=n?t.target:t,v.withComponent=function(b){var k=r.componentId,N=(function(C,M){if(C==null)return{};var I,se,Y={},$=Object.keys(C);for(se=0;se<$.length;se++)I=$[se],M.indexOf(I)>=0||(Y[I]=C[I]);return Y})(r,["componentId"]),u=k&&k+"-"+(Dt(b)?b:ir(Ir(b)));return Ca(b,Xe({},N,{attrs:g,componentId:u}),a)},Object.defineProperty(v,"defaultProps",{get:function(){return this._foldedDefaultProps},set:function(b){this._foldedDefaultProps=n?Na({},t.defaultProps,b):b}}),Object.defineProperty(v,"toString",{value:function(){return"."+v.styledComponentId}}),s&&Rs(v,t,{attrs:!0,componentStyle:!0,displayName:!0,foldedComponentIds:!0,shouldForwardProp:!0,styledComponentId:!0,target:!0,withComponent:!0}),v}var De=function(t){return(function r(a,n,s){if(s===void 0&&(s=rt),!ya.isValidElementType(n))return Ot(1,String(n));var i=function(){return a(n,s,ii.apply(void 0,arguments))};return i.withConfig=function(o){return r(a,n,Xe({},s,{},o))},i.attrs=function(o){return r(a,n,Xe({},s,{attrs:Array.prototype.concat(s.attrs,o).filter(Boolean)}))},i})(Ca,t)};["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","circle","clipPath","defs","ellipse","foreignObject","g","image","line","linearGradient","marker","mask","path","pattern","polygon","polyline","radialGradient","rect","stop","svg","text","textPath","tspan"].forEach((function(t){De[t]=De(t)}));var pr={accent:"#0096ff",background:"#ffffff",color:"#000000",inputBg:"#f3f4f8",inputColor:"#000000",inputError:"#e3005e",shadow:"0 5px 10px rgba(0, 0, 0, 0.04)",radius:4,spacing:8,fontSize:"13px"},at;(function(t){t[t.slider=0]="slider",t[t.text=1]="text",t[t.color=2]="color"})(at||(at={}));var tt=function(t,r,a){if(a||arguments.length===2)for(var n=0,s=r.length,i;n<s;n++)(i||!(n in r))&&(i||(i=Array.prototype.slice.call(r,0,n)),i[n]=r[n]);return t.concat(i||Array.prototype.slice.call(r))},Pa=["padding","padding-top","padding-right","padding-bottom","padding-left"],Ta=["margin","margin-top","margin-right","margin-bottom","margin-left"],Ea=["border-radius","border-radius-top","border-radius-right","border-radius-bottom","border-radius-left"],gi=tt(tt(tt(tt(tt(["width","height"],Ea,!0),["font-size","top","right","bottom","left"],!1),Pa,!0),Ta,!0),["opacity"],!1),pi=["color","background-color","border-color"],fi=function(t){return gi.includes(t)?at.slider:pi.includes(t)?at.color:at.text},hi=function(t,r){r===void 0&&(r="px");var a=["%","vh","vw"],n=tt(tt(tt(["font-size"],Pa,!0),Ea,!0),Ta,!0);return t==="opacity"?{min:0,max:1,step:.05}:a.includes(r)||n.includes(t)?{min:0,max:100}:{min:0,step:10,max:1e3}},fr=function(t){var r=!1,a=1;if(t.length){var n=t[t.length-1];a=n.id+1,r=!n.property}r||t.push({id:a,value:"",property:""})},Aa=function(t){var r=t.replace(/\n/g,""),a=r.split(";"),n=a.filter(Boolean),s=[];return n.forEach(function(i,o){var d=i.trim(),m=d.indexOf(":"),l=m>=0,f=l?d.slice(0,m):d,y=l?d.slice(m+1,d.length).trim():"";s.push({property:f,value:y,id:o})}),fr(s),s},xi=function(t){var r=[];t.forEach(function(n){n.property.trim()&&r.push("".concat(n.property.trim(),": ").concat(n.value.trim()))});var a=r.join(`;
`);return a},yi=function(t,r,a){c.useEffect(function(){if(r){var n=Aa(t);a(function(s){return JSON.stringify(s)===JSON.stringify(n)?s:n})}},[t,r])},bi=function(t){var r=c.useCallback(function(){var a=document.activeElement;if(!(!a||a.tagName.toLowerCase()!=="input")){var n=Number(a.getAttribute("data-editor-order")),s=t.current;if(s){var i=s.querySelector('input[data-editor-order="'.concat(n+1,'"]'));i&&i.select()}}},[]);return r},Ft=c.createContext(pr),vi=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},hr=function(){return hr=Object.assign||function(t){for(var r,a=1,n=arguments.length;a<n;a++){r=arguments[a];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},hr.apply(this,arguments)},ji=De.input(Hr||(Hr=vi([`
  border-radius: `,`px;
  background-color: `,`;
  box-sizing: border-box;
  padding: 1px 3px;
  text-align: inherit;
  width: 100%;
  outline: none;
  border: 2px `,` solid;
  font-family: inherit;
  font-size: inherit;
  color: `,`;
  
  &:focus, &[value=""] {
    background-color: `,`;
    color: `,`;
  }

  &:focus {
    border-color: `,`;
  }
`],[`
  border-radius: `,`px;
  background-color: `,`;
  box-sizing: border-box;
  padding: 1px 3px;
  text-align: inherit;
  width: 100%;
  outline: none;
  border: 2px `,` solid;
  font-family: inherit;
  font-size: inherit;
  color: `,`;
  
  &:focus, &[value=""] {
    background-color: `,`;
    color: `,`;
  }

  &:focus {
    border-color: `,`;
  }
`])),function(t){var r=t.radius;return r},function(t){var r=t.inputBg,a=t.transparent;return a?"transparent":r},function(t){var r=t.isValid,a=r===void 0?!0:r,n=t.inputError;return a?"transparent":n},function(t){var r=t.inputColor,a=t.color,n=t.transparent;return n?a:r},function(t){var r=t.inputBg;return r},function(t){var r=t.inputColor;return r},function(t){var r=t.accent;return r}),Ra=c.forwardRef(function(t,r){var a=c.useContext(Ft);return pe.createElement(ji,hr({inputBg:a.inputBg,accent:a.accent,radius:a.radius||0,type:"text",ref:r,"data-editor-order":t.order,inputColor:a.inputColor,color:a.color,inputError:a.inputError},t))}),Hr,Ma=c.createContext([]),wi=function(t,r){c.useEffect(function(){var a=function(n){t.current&&!t.current.contains(n.target)&&r(!1)};return document.addEventListener("mousedown",a),function(){document.removeEventListener("mousedown",a)}},[])},Oa=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},ki=De.ul(Kr||(Kr=Oa([`
  border-radius: `,`px;
  background-color: `,`;
  position: absolute;
  top: 30px;
  left: 0;
  z-index: 2;
  list-style-type: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: `,`;
`],[`
  border-radius: `,`px;
  background-color: `,`;
  position: absolute;
  top: 30px;
  left: 0;
  z-index: 2;
  list-style-type: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: `,`;
`])),function(t){var r=t.radius;return r},function(t){var r=t.background;return r},function(t){var r=t.shadow;return r}),Ni=De.li(Vr||(Vr=Oa([`
  background: `,`;
  color: `,`;
  padding: `,`;
`],[`
  background: `,`;
  color: `,`;
  padding: `,`;
`])),function(t){var r=t.selected,a=t.accent;return r?a:"transparent"},function(t){var r=t.selected;return r?"#ffffff":"inherit"},function(t){var r=t.spacing;return"".concat(r*.5,"px ").concat(r*2,"px ").concat(r*.5,"px ").concat(r,"px")}),Si=function(t){var r=t.options,a=t.wrapperRef,n=t.onChange,s=t.onSetOpen,i=c.useContext(Ft),o=c.useState(0),d=o[0],m=o[1],l=c.useRef(null),f=c.useCallback(function(g){if(g.key==="Enter"||g.code==="Enter"){n(r[d]);return}if(g.key==="Escape"||g.code==="Escape"){s(!1);return}var x=["ArrowDown","ArrowUp"];x.includes(g.code)&&y(g.code)},[d,n]),y=c.useCallback(function(g){m(function(x){var v,p;g==="ArrowDown"?p=x+1:p=x-1;var j=(v=l.current)===null||v===void 0?void 0:v.querySelector('[data-id="item-'.concat(p,'"]'));return j?(j==null||j.scrollIntoView({block:"nearest",inline:"nearest"}),p):x})},[]);return c.useEffect(function(){m(0)},[r]),c.useEffect(function(){var g;return(g=a.current)===null||g===void 0||g.addEventListener("keydown",f,!1),function(){var x;(x=a.current)===null||x===void 0||x.removeEventListener("keydown",f,!1)}},[f]),wi(l,s),r.length?pe.createElement(ki,{background:i.background,radius:i.radius,shadow:i.shadow,ref:l},r.map(function(g,x){return pe.createElement(Ni,{key:g,selected:x===d,accent:i.accent,spacing:i.spacing,"data-id":"item-".concat(x)},g)})):null},Kr,Vr,Ci=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},Pi=De.div(Qr||(Qr=Ci([`
  margin-bottom: 4px;
  height: 25px;
  font-size: inherit;
  width: `,`;
  position: relative;
`],[`
  margin-bottom: 4px;
  height: 25px;
  font-size: inherit;
  width: `,`;
  position: relative;
`])),function(t){var r=t.fullwidth;return r?"100%":"calc(100% - 60px)"}),Ti=function(t){var r=t.value,a=r===void 0?"":r,n=t.onChange,s=t.fullwidth,i=s===void 0?!0:s,o=t.order,d=c.useState(a),m=d[0],l=d[1],f=c.useRef(null),y=c.useState(!1),g=y[0],x=y[1],v=m.trim(),p=c.useContext(Ma),j=c.useMemo(function(){return v?p.filter(function(u){return u.startsWith(v.toLowerCase())}):[]},[p,v]),E=function(u){var C=u.target.value;l(C),n(C),x(!0)},b=function(u){l(u),n(u),x(!1)},k=function(){var u;(u=f.current)===null||u===void 0||u.select()},N=function(u){u.preventDefault()};return pe.createElement(Pi,{fullwidth:i},pe.createElement("form",{onSubmit:N},pe.createElement(Ra,{ref:f,type:"text",value:m,placeholder:"Property",onChange:E,onClick:k,order:o,transparent:!0}),g&&pe.createElement(Si,{options:j,wrapperRef:f,onChange:b,onSetOpen:x})))},Qr,Ei=function(t){var r=c.useRef(null),a=t||r,n=function(){var s;(s=a.current)===null||s===void 0||s.select()};return{handleClick:n,inputRef:a}},xr=function(){return xr=Object.assign||function(t){for(var r,a=1,n=arguments.length;a<n;a++){r=arguments[a];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},xr.apply(this,arguments)},Ai=function(t,r){var a={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(a[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)r.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(a[n[s]]=t[n[s]]);return a},Pr=function(t){var r=t.value,a=t.onChange,n=t.valueRef,s=Ai(t,["value","onChange","valueRef"]),i=Ei(n),o=i.inputRef,d=i.handleClick,m=function(l){var f=l.target.value;a(f)};return pe.createElement(Ra,xr({type:"text",value:r,onChange:m,onClick:d,ref:o},s))},Tr=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},yr=function(){return yr=Object.assign||function(t){for(var r,a=1,n=arguments.length;a<n;a++){r=arguments[a];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},yr.apply(this,arguments)},Ri=function(t,r){var a={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(a[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)r.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(a[n[s]]=t[n[s]]);return a},Mi=De.div(Gr||(Gr=Tr([`
  position: relative;
`],[`
  position: relative;
`]))),Oi=De.div(Wr||(Wr=Tr([`
  position: absolute;
  top: -30px;
  right: 0;
  width: 50px;
  text-align: right;
`],[`
  position: absolute;
  top: -30px;
  right: 0;
  width: 50px;
  text-align: right;
`]))),Fi=De.input(Yr||(Yr=Tr([`
  width: 100%;
  accent-color: `,`;
`],[`
  width: 100%;
  accent-color: `,`;
`])),function(t){var r=t.accent;return r}),Li=function(t){var r=t.value,a=t.onChange,n=t.property,s=Ri(t,["value","onChange","property"]),i=c.useContext(Ft),o=parseFloat(r),d=r.replace("".concat(o),"").trim(),m=hi(n,d),l=function(y){var g=parseFloat(y.target.value);a("".concat(g).concat(d))},f=function(y){a(y)};return pe.createElement(Mi,null,pe.createElement(Oi,null,pe.createElement(Pr,yr({value:r,onChange:f},s))),pe.createElement(Fi,{type:"range",value:o,onChange:l,min:m.min,max:m.max,step:m.step||1,accent:i.accent}))},Gr,Wr,Yr,Fa=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},_i=De.div(Xr||(Xr=Fa([`
  position: relative;
`],[`
  position: relative;
`]))),Di=De.input(Jr||(Jr=Fa([`
  position: absolute;
  top: -28px;
  right: 0;
  width: 0;
  height: 0;
  border-radius: 50%;
  border: none;
  padding: 0;
  -webkit-appearance: none;
  
  &::-webkit-color-swatch-wrapper {
    padding: 0;
  }
  
  &::-webkit-color-swatch {
    border: none;
  }
  
  &:after {
    position: absolute;
    content: "";
    background: `,`;
    top: 0;
    right: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px rgba(0, 0, 0, 0.1) solid;
  }
`],[`
  position: absolute;
  top: -28px;
  right: 0;
  width: 0;
  height: 0;
  border-radius: 50%;
  border: none;
  padding: 0;
  -webkit-appearance: none;
  
  &::-webkit-color-swatch-wrapper {
    padding: 0;
  }
  
  &::-webkit-color-swatch {
    border: none;
  }
  
  &:after {
    position: absolute;
    content: "";
    background: `,`;
    top: 0;
    right: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px rgba(0, 0, 0, 0.1) solid;
  }
`])),function(t){var r=t.background;return r}),Ii=function(t){var r=t.value,a=t.onChange,n=t.order,s=function(m){var l=m.target.value;a(l)},i=(r.match(/\(/g)||[]).length,o=(r.match(/\)/g)||[]).length,d=i===o;return pe.createElement("div",null,pe.createElement(_i,null,pe.createElement(Di,{type:"color",value:r,onChange:s,background:d?r:""})),pe.createElement(Pr,{value:r,onChange:a,order:n}))},Xr,Jr,Pt=function(){return Pt=Object.assign||function(t){for(var r,a=1,n=arguments.length;a<n;a++){r=arguments[a];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},Pt.apply(this,arguments)},$i=function(t,r){var a={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(a[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)r.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(a[n[s]]=t[n[s]]);return a},zi=function(t){var r=t.mode,a=t.property,n=$i(t,["mode","property"]);switch(r){case at.slider:return pe.createElement(Li,Pt({},n,{property:a}));case at.color:return pe.createElement(Ii,Pt({},n));default:return pe.createElement(Pr,Pt({},n))}},qi=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},qt=function(){return qt=Object.assign||function(t){for(var r,a=1,n=arguments.length;a<n;a++){r=arguments[a];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},qt.apply(this,arguments)},Bi=De.div(Zr||(Zr=qi([`
  background: `,`;
  padding: `,`;
  border-radius: `,`px;
  box-shadow: `,`;
  margin: `,`px 0;
`],[`
  background: `,`;
  padding: `,`;
  border-radius: `,`px;
  box-shadow: `,`;
  margin: `,`px 0;
`])),function(t){var r=t.backgroundColor;return r},function(t){var r=t.spacing;return"".concat(r,"px ").concat(r*1.25,"px ").concat(r*1.25,"px")},function(t){var r=t.radius;return r*3},function(t){var r=t.shadow;return r},function(t){var r=t.spacing;return r}),Ui=c.memo(function(t){var r=t.data,a=t.onChange,n=t.order,s=t.onRemove,i=c.useContext(Ft),o=fi(r.property),d=c.useRef(null),m=function(p){a(qt(qt({},r),p))},l=function(p){p===void 0&&(p=" "),m({property:p})},f=function(p){m({value:p})},y=r.property.trim(),g=r.value.trim(),x=function(){y||s(r.id)},v=g?CSS.supports(y,g):!0;return pe.createElement(Bi,{onBlur:x,backgroundColor:i.background,shadow:i.shadow,radius:i.radius,spacing:i.spacing},pe.createElement(Ti,{value:r.property,onChange:l,fullwidth:o===at.text,order:n}),y&&pe.createElement(zi,{value:r.value,mode:o,onChange:f,property:r.property,valueRef:d,order:n+1,isValid:v}))}),Zr,Hi=function(){var t=document.body.style,r=Object.getOwnPropertyNames(t.hasOwnProperty("background")?t:t.__proto__);r=r.filter(function(n){return t[n]===""}).map(function(n){return n=n.replace(/[A-Z]/g,function(s){return"-"+s.toLowerCase()}),n.startsWith("webkit")&&(n="-"+n),n});var a={};return r=r.filter(function(n){return a[n]?!1:(a[n]=!0,!0)}),r},Ki=function(t,r){return Object.defineProperty?Object.defineProperty(t,"raw",{value:r}):t.raw=r,t},Tt=function(){return Tt=Object.assign||function(t){for(var r,a=1,n=arguments.length;a<n;a++){r=arguments[a];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},Tt.apply(this,arguments)},ea=function(t,r,a){if(a||arguments.length===2)for(var n=0,s=r.length,i;n<s;n++)(i||!(n in r))&&(i||(i=Array.prototype.slice.call(r,0,n)),i[n]=r[n]);return t.concat(i||Array.prototype.slice.call(r))},Vi=De.div(ta||(ta=Ki([`
  margin: -`,`px 0;
  font-size: `,`;
  color: `,`;
`],[`
  margin: -`,`px 0;
  font-size: `,`;
  color: `,`;
`])),function(t){var r=t.spacing;return r},function(t){var r=t.fontSize;return r},function(t){var r=t.color;return r}),Qi=function(t){var r=t.style,a=r===void 0?"":r,n=t.theme,s=n===void 0?{}:n,i=t.onChange,o=t.reactive,d=o===void 0?!1:o,m=c.useState(function(){return Aa(a)}),l=m[0],f=m[1],y=c.useRef(null),g=JSON.stringify(s),x=c.useMemo(function(){var N=JSON.parse(g);return Tt(Tt(Tt({},pr),JSON.parse(g)),{inputColor:N.inputColor||N.color||pr.inputColor})},[g]),v=c.useMemo(function(){return xi(l)},[l]),p=c.useMemo(function(){var N=Hi();return N},[]);yi(a,d,f);var j=bi(y),E=c.useCallback(function(N){var u=[":",";"];!u.includes(N.key)&&N.key!=="Enter"&&N.code!=="Enter"||(u.includes(N.key)&&N.preventDefault(),j())},[j]);c.useEffect(function(){var N;return(N=y.current)===null||N===void 0||N.addEventListener("keydown",E,!1),function(){var u;(u=y.current)===null||u===void 0||u.removeEventListener("keydown",E,!1)}},[E]),c.useEffect(function(){i==null||i(v)},[i,v]);var b=c.useCallback(function(N){f(function(u){var C=ea([],u,!0),M=C.findIndex(function(I){return I.id===N.id});return C.splice(M,1,N),fr(C),C})},[]),k=c.useCallback(function(N){f(function(u){var C=ea([],u,!0),M=C.findIndex(function(I){return I.id===N});return C.splice(M,1),fr(C),C})},[]);return pe.createElement(Ma.Provider,{value:p},pe.createElement(Ft.Provider,{value:x},pe.createElement(Vi,{fontSize:x.fontSize,color:x.color,spacing:x.spacing,ref:y},l.map(function(N,u){return pe.createElement(Ui,{data:N,key:N.id,onChange:b,onRemove:k,order:u*2})}))))},ta;const Gi={heading:"font-size: 24px; font-weight: bold; font-family: serif; text-decoration: none; list-style: disc; text-align: left;",body:"font-size: 14px; font-weight: normal; font-family: serif; text-decoration: none; list-style: disc; text-align: left;",emphasis:"font-size: 14px; font-weight: bold; font-family: serif; text-decoration: underline; list-style: disc; text-align: left;",list:"font-size: 14px; font-weight: normal; font-family: serif; list-style: disclosure-closed; text-align: left;",title:"font-size: 18px; font-weight: bold; font-family: sans-serif; text-decoration: none; list-style: disc; text-align: left;"},Wi=()=>`url('data:image/svg+xml;base64,${btoa('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><polygon points="6,4 12,8 6,12" fill="currentColor"/></svg>')}')`,ra=t=>{const r={};let a=0,n="";const s=i=>{if(i=i.trim(),!i)return;const o=i.indexOf(":");if(o<=0)return;const d=i.slice(0,o).trim(),m=i.slice(o+1).trim();d&&m&&(r[d]=m)};for(let i=0;i<t.length;i++){const o=t[i];o==="("?a++:o===")"&&a--,o===";"&&a===0?(s(n),n=""):n+=o}return s(n),r},aa=t=>Object.entries(t).map(([r,a])=>`${r}: ${a};`).join(" "),Yi=({setting:t,index:r,onChange:a,isDefault:n,onToggleDefault:s})=>{const{t:i}=Ie(),[o,d]=c.useState(!1),m=c.useMemo(()=>typeof t.value=="string"?t.value:"",[t.value]),l=c.useMemo(()=>ra(m),[m]);c.useMemo(()=>{const p=new Set;return t.templateSettingValues&&t.templateSettingValues.length>0&&t.templateSettingValues.forEach(j=>{j.value&&typeof j.value=="object"&&Object.keys(j.value).forEach(E=>p.add(E))}),Array.from(p)},[t.templateSettingValues]);const f=c.useMemo(()=>{const p=t.code.toLowerCase();return p.includes("header")||p.includes("footer")},[t.code]),y=p=>{const j={...p};return j["list-style"]!=="disclosure-closed"&&delete j["list-style-image"],j["list-style"]==="disclosure-closed"&&(j["list-style-image"]=Wi()),j},g=c.useCallback((p,j)=>{let E={...l,[p]:j};p==="list-style"&&["disclosure-closed","disclosure-open","none"].includes(j)&&delete E["list-style-type"],E=y(E);const b=aa(E);a(r,b)},[l,r,a]);c.useEffect(()=>{const p=ra(m),j=y(p),E=aa(j);E!==m&&a(r,E)},[]);const x=c.useCallback(p=>{a(r,p)},[r,a]),v=c.useCallback(p=>{a(r,Gi[p])},[r,a]);return!t||!t.code||!t.id?null:e.jsxs("div",{className:"mt-4 p-4 bg-gray-50 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-200",children:t.code.replace(/-/g," ")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:()=>s(t.id),className:"w-4 h-4 rounded border-gray-300 dark:border-gray-500"}),e.jsx("span",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:n?"Default":"Custom"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:i("template.quickPresets","Quick Presets")}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>v("heading"),className:"px-2 py-1 text-xs bg-white dark:bg-gray-600 border border-gray-300 dark:border-gray-500 rounded hover:bg-purple-50 dark:hover:bg-purple-900/30 transition-colors dark:text-gray-200",children:"Heading"}),e.jsx("button",{onClick:()=>v("body"),className:"px-2 py-1 text-xs bg-white dark:bg-gray-600 border border-gray-300 dark:border-gray-500 rounded hover:bg-purple-50 dark:hover:bg-purple-900/30 transition-colors dark:text-gray-200",children:"Body"}),e.jsx("button",{onClick:()=>v("emphasis"),className:"px-2 py-1 text-xs bg-white dark:bg-gray-600 border border-gray-300 dark:border-gray-500 rounded hover:bg-purple-50 dark:hover:bg-purple-900/30 transition-colors dark:text-gray-200",children:"Emphasis"}),e.jsx("button",{onClick:()=>v("list"),className:"px-2 py-1 text-xs bg-white dark:bg-gray-600 border border-gray-300 dark:border-gray-500 rounded hover:bg-purple-50 dark:hover:bg-purple-900/30 transition-colors dark:text-gray-200",children:"List"}),e.jsx("button",{onClick:()=>v("title"),className:"px-2 py-1 text-xs bg-white dark:bg-gray-600 border border-gray-300 dark:border-gray-500 rounded hover:bg-purple-50 dark:hover:bg-purple-900/30 transition-colors col-span-2 dark:text-gray-200",children:"Title"})]})]}),e.jsxs("div",{className:"space-y-3 border-t border-gray-200 dark:border-gray-600 pt-3",children:[e.jsx("p",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:i("template.commonProperties","Common Properties")}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.width","Width")}),e.jsx("input",{type:"text",value:l.width||"100%",onChange:p=>g("width",p.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.height","Height")}),e.jsx("input",{type:"text",value:l.height||"auto",onChange:p=>g("height",p.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.margin","Margin")}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Top"}),e.jsx("input",{type:"text",value:l["margin-top"]||"0",onChange:p=>g("margin-top",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Right"}),e.jsx("input",{type:"text",value:l["margin-right"]||"0",onChange:p=>g("margin-right",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Bottom"}),e.jsx("input",{type:"text",value:l["margin-bottom"]||"0",onChange:p=>g("margin-bottom",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Left"}),e.jsx("input",{type:"text",value:l["margin-left"]||"0",onChange:p=>g("margin-left",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.padding","Padding")}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Top"}),e.jsx("input",{type:"text",value:l["padding-top"]||"0",onChange:p=>g("padding-top",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Right"}),e.jsx("input",{type:"text",value:l["padding-right"]||"0",onChange:p=>g("padding-right",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Bottom"}),e.jsx("input",{type:"text",value:l["padding-bottom"]||"0",onChange:p=>g("padding-bottom",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Left"}),e.jsx("input",{type:"text",value:l["padding-left"]||"0",onChange:p=>g("padding-left",p.target.value),className:"w-full px-2 py-1 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded text-sm"})]})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.fontSize","Font Size")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"number",value:(l["font-size"]||"14px").replace("px",""),onChange:p=>g("font-size",`${p.target.value}px`),placeholder:"14",className:"flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("span",{className:"flex items-center text-gray-600 dark:text-gray-400 text-sm",children:"px"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.fontWeight","Font Weight")}),e.jsxs("select",{value:l["font-weight"]||"normal",onChange:p=>g("font-weight",p.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm",children:[e.jsx("option",{value:"normal",children:"Normal (400)"}),e.jsx("option",{value:"500",children:"Medium (500)"}),e.jsx("option",{value:"600",children:"Semi-bold (600)"}),e.jsx("option",{value:"bold",children:"Bold (700)"}),e.jsx("option",{value:"800",children:"Extra Bold (800)"}),e.jsx("option",{value:"900",children:"Black (900)"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.fontFamily","Font Family")}),e.jsxs("select",{value:l["font-family"]||"serif",onChange:p=>g("font-family",p.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm",children:[e.jsx("option",{value:"serif",children:"Serif"}),e.jsx("option",{value:"sans-serif",children:"Sans-serif"}),e.jsx("option",{value:"monospace",children:"Monospace"}),e.jsx("option",{value:"cursive",children:"Cursive"}),e.jsx("option",{value:"fantasy",children:"Fantasy"}),e.jsx("option",{value:"Georgia, serif",children:"Georgia"}),e.jsx("option",{value:"'Times New Roman', serif",children:"Times New Roman"}),e.jsx("option",{value:"Arial, sans-serif",children:"Arial"}),e.jsx("option",{value:"Verdana, sans-serif",children:"Verdana"}),e.jsx("option",{value:"'Courier New', monospace",children:"Courier New"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.textDecoration","Text Decoration")}),e.jsxs("select",{value:l["text-decoration"]||"none",onChange:p=>g("text-decoration",p.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm",children:[e.jsx("option",{value:"none",children:"None"}),e.jsx("option",{value:"underline",children:"Underline"}),e.jsx("option",{value:"overline",children:"Overline"}),e.jsx("option",{value:"line-through",children:"Line Through"}),e.jsx("option",{value:"underline overline",children:"Underline & Overline"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:i("template.textAlign","Text Align")}),e.jsxs("select",{value:l["text-align"]||"left",onChange:p=>g("text-align",p.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm",children:[e.jsx("option",{value:"Empty",children:"Empty"}),e.jsx("option",{value:"left",children:"Left"}),e.jsx("option",{value:"center",children:"Center"}),e.jsx("option",{value:"right",children:"Right"}),e.jsx("option",{value:"justify",children:"Justify"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-300 mb-1",children:i("template.listStyle","List Style")}),e.jsxs("select",{value:l["list-style"]||"disc",onChange:p=>g("list-style",p.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm",children:[e.jsx("option",{value:"disc",children:"Bullet"}),e.jsx("option",{value:"circle",children:"Circle"}),e.jsx("option",{value:"square",children:"Square"}),e.jsx("option",{value:"disclosure-closed",children:"Black Right Triangle (▶)"}),e.jsx("option",{value:"decimal",children:"Numbers (1, 2, 3)"}),e.jsx("option",{value:"lower-alpha",children:"Lowercase Letters (a, b, c)"}),e.jsx("option",{value:"upper-alpha",children:"Uppercase Letters (A, B, C)"}),e.jsx("option",{value:"lower-roman",children:"Lowercase Roman (i, ii, iii)"}),e.jsx("option",{value:"upper-roman",children:"Uppercase Roman (I, II, III)"}),e.jsx("option",{value:"none",children:"None"})]})]})]})]}),e.jsxs("button",{onClick:()=>d(!o),className:"w-full flex items-center justify-between px-3 py-2 text-xs font-medium text-gray-600 dark:text-gray-300 hover:bg-white dark:hover:bg-gray-600 rounded transition-colors border border-gray-300 dark:border-gray-500",children:[e.jsx("span",{children:i("template.advancedCSS","Advanced CSS Editor")}),e.jsx(za,{className:`h-4 w-4 transition-transform ${o?"rotate-180":""}`})]}),o&&e.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-600 pt-3 space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:i("template.customCSS","Custom CSS")}),e.jsx(Qi,{style:m,onChange:x})]})]})},Xi={collaborators:[{am:"ዮሃንስ ዶ",en:"John Doe"},{am:"ማርያም ስሚዝ",en:"Mary Smith"}],preferredLanguage:"am",content:{isWithDelegateSignature:!1,delegatorName:"",body:`This is a sample letter body demonstrating the template styling.

The body can contain multiple paragraphs and formatting.

- First bullet point item
- Second bullet point item
- Third bullet point item

This allows you to see how list styles are applied.`,date:new Date().toISOString().split("T")[0],internalCC:["Finance Department","HR Department","Legal Department"],externalCC:["External Partner A","External Partner B"],prefixCC:"CC:",suffixCC:"---",from:["John Doe","Mary Smith"],subject:"Sample Template Subject – Style Preview",sincerelyText:"Sincerely",to:["Department Head","Project Manager","Team Lead"],prefix:"RE:",suffix:"---"},recordType:"external"},Ji=()=>`url('data:image/svg+xml;base64,${btoa(`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
  <polygon points="6,4 12,8 6,12" fill="currentColor"/>
</svg>`)}')`,Zi=t=>{const r=[];let a=0,n="";for(let i=0;i<t.length;i++){const o=t[i];if(o==="("?a++:o===")"&&a--,o===";"&&a===0){const d=n.trim();if(d){const m=d.indexOf(":");if(m>0){const l=d.slice(0,m).trim(),f=d.slice(m+1).trim();l&&f&&r.push([l,f])}}n=""}else n+=o}const s=n.trim();if(s){const i=s.indexOf(":");if(i>0){const o=s.slice(0,i).trim(),d=s.slice(i+1).trim();o&&d&&r.push([o,d])}}return r},eo=t=>{const r={...t},a=["disclosure-closed","disclosure-open","none"];if(r["list-style"]){const n=r["list-style"].split(" ")[0];if(a.includes(n))return delete r["list-style-type"],r;r["list-style-type"]||(r["list-style-type"]=n)}return r["list-style-type"]&&!r["list-style"]&&(r["list-style"]=r["list-style-type"]),r},na=t=>{const r={};Zi(t).forEach(([n,s])=>{r[n]=s});const a=eo(r);return a["list-style"]==="disclosure-closed"&&(a["list-style-image"]=Ji()),a};function br(t,r){const[a,n]=c.useState(t);return c.useEffect(()=>{const s=setTimeout(()=>{n(t)},r);return()=>{clearTimeout(s)}},[t,r]),a}const to=({isOpen:t,onConfirm:r,onCancel:a})=>{const{t:n}=Ie();return t?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl max-w-md w-full mx-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-600",children:[e.jsx(On,{className:"h-5 w-5"}),e.jsx("h3",{className:"text-lg font-semibold",children:n("common.warning","Warning")})]}),e.jsx("button",{onClick:a,className:"p-1 hover:bg-gray-100 rounded-lg transition-colors",children:e.jsx(lt,{className:"h-5 w-5 text-gray-500"})})]}),e.jsx("div",{className:"p-6",children:e.jsx("p",{className:"text-gray-700",children:n("template.unsavedChangesWarning","You have unsaved changes. Are you sure you want to leave?")})}),e.jsxs("div",{className:"flex justify-end gap-3 p-4 border-t border-gray-200 bg-gray-50",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors",children:n("common.cancel","Cancel")}),e.jsx("button",{onClick:r,className:"px-4 py-2 text-sm font-medium text-white bg-red-600 rounded-lg hover:bg-red-700 transition-colors",children:n("common.leave","Leave")})]})]})}):null},ro=({visible:t})=>t?e.jsxs("div",{className:"flex items-center gap-2 text-amber-600",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-600 animate-pulse"}),e.jsx("span",{className:"text-sm font-medium",children:"Unsaved changes"})]}):null,ao=({pdfUrl:t,loading:r,error:a,onApply:n})=>{const{t:s}=Ie(),[i,o]=c.useState(!0),[d,m]=c.useState(!1);c.useEffect(()=>{t&&(o(!0),m(!1))},[t]);const l=()=>o(!1),f=()=>{o(!1),m(!0)};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"p-4 border-b",children:e.jsx("button",{onClick:n,disabled:r,className:"w-full px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:r?s("template.generatingPreview","Generating..."):s("template.applyChanges","Apply Changes")})}),a&&e.jsxs("div",{className:"mx-4 mt-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[e.jsx("p",{className:"text-sm text-red-800",children:a}),e.jsx("button",{onClick:n,className:"mt-2 text-sm text-red-600 hover:text-red-800 font-medium underline",children:s("common.retry","Retry")})]}),e.jsx("div",{className:"flex-1 overflow-hidden relative",children:t?e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white bg-opacity-75 z-10",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(kr,{className:"h-8 w-8 animate-spin text-purple-600"}),e.jsx("span",{className:"text-sm text-gray-600",children:s("template.loadingPdf","Loading PDF...")})]})}),d&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-50",children:e.jsxs("div",{className:"text-center p-6",children:[e.jsx("p",{className:"text-red-600 font-medium mb-2",children:s("template.pdfLoadError","Failed to load PDF preview")}),e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-purple-600 hover:text-purple-700 underline text-sm",children:s("template.openInNewTab","Open in new tab")})]})}),e.jsx("iframe",{src:t,className:"w-full h-full border-0",title:"PDF Preview",onLoad:l,onError:f})]}):e.jsx("div",{className:"flex items-center justify-center h-full text-gray-500",children:s("template.clickApplyToPreview",'Click "Apply Changes" to generate preview')})})]})},no=({templateId:t,onBack:r})=>{var H,ue,D,we;const{t:a}=Ie(),{userDetails:n}=qa(),s=(ue=(H=n==null?void 0:n.employee)==null?void 0:H[0])==null?void 0:ue.unitId,[i,o]=c.useState(!1),d=c.useRef(null),{data:m,isLoading:l}=pa(s),[f,y]=c.useState(null),[g,x]=c.useState([]),[v,p]=c.useState(!1),[j,E]=c.useState(null),[b,k]=c.useState(!1),[N,u]=c.useState(""),[C,M]=c.useState(""),[I,se]=c.useState([]),[Y,$]=c.useState([]),[F,_]=c.useState(!1),[ne,X]=c.useState(null),[W,xe]=c.useState(null),[ie,Ae]=c.useState(!0),[je,z]=c.useState(!0),O=c.useRef(null),[R,L]=c.useState({}),T=c.useRef({}),h=c.useCallback(S=>{const B=S.toLowerCase();return B.includes("header")?"header":B.includes("footer")?"footer":B.includes("subject")?"subject":B.includes("body")||B.includes("content")?"body":B.includes("receiver")?"receiver":B.includes("prefix")||B.includes("suffix")?"prefix-suffix":B.includes("cc")?"cc":B.includes("list")?"list":B==="letter-fonts"?"fonts":B==="letter-page-margin"?"page-margin":B.includes("reference-number")?"reference-number":"other"},[]),U={"letter-list-style":["receiver"],"letter-cc-list-style":["cc"]},P=c.useCallback(S=>U[S]?U[S]:[h(S)],[]),Z=c.useMemo(()=>{const S=new Map;return g.forEach(B=>{P(B.code).forEach(A=>{if(!S.has(A)){const K={header:a("template.headerStyle","Header Style"),footer:a("template.footerStyle","Footer Style"),subject:a("template.subjectStyle","Subject Style"),body:a("template.bodyStyle","Body Style"),receiver:a("template.receiverStyle","Receiver Style"),"prefix-suffix":a("template.prefixSuffix","Prefix / Suffix"),cc:a("template.ccStyles","CC Styles"),list:a("template.listStyle","List Style"),fonts:a("template.fonts","Fonts"),"page-margin":a("template.pageMargin","Page Margin"),"reference-number":a("template.referenceNumberStyles","Reference Number Styles"),other:a("template.other","Other")};S.set(A,{code:A,label:K[A]||A,settingIds:[]})}S.get(A).settingIds.push(B.id)})}),Array.from(S.values())},[g,a,P]),ee=c.useCallback(async()=>{try{const S=await St.getTemplate(t);y(S)}catch{X(a("error.loadingTemplate","Error loading template"))}},[t,a]),te=c.useCallback(async()=>{try{p(!0),X(null);const S=await St.getTemplateSettingsByUnit(t),V=(Array.isArray(S==null?void 0:S.items)?S.items:[]).map(K=>{var Oe;if(!K.id||!K.code)return null;let he;if(K.value!==null&&K.value!==void 0)he=K.value;else if(((Oe=K.templateSettingValues)==null?void 0:Oe.length)>0){const ce=K.templateSettingValues.find(ve=>ve.unitId!==null&&ve.unitId!==void 0);if((ce==null?void 0:ce.value)!=null)he=ce.value;else{const ve=K.templateSettingValues.find(qe=>qe.value!==null&&qe.value!==void 0);he=ve==null?void 0:ve.value}}let Ue="";return typeof he=="object"&&he!==null&&Object.keys(he).length>0?Ue=Object.entries(he).filter(([,ce])=>ce!=null&&ce!=="null").map(([ce,ve])=>`${ce}: ${ve};`).join(" "):typeof he=="string"&&he.trim()&&(Ue=he),{...K,value:Ue}}).filter(K=>K!==null);x(V);const A={};V.forEach(K=>{K&&(A[K.id]=!0)}),L(A)}catch{X(a("error.loadingSettings","Error loading style settings"))}finally{p(!1)}},[t,a]),q=c.useCallback((S,B)=>{var A;x(K=>{const he=[...K];return he[S]={...he[S],value:B},he});const V=(A=g[S])==null?void 0:A.id;V&&L(K=>({...K,[V]:!1})),_(!0)},[g]),de=c.useCallback(S=>{L(B=>{var A,K;const V=!B[S];if(V){const he=g.findIndex(Ue=>Ue.id===S);if(he>=0){const Oe=((K=(A=g[he].templateSettingValues)==null?void 0:A[0])==null?void 0:K.value)||{};let ce="";typeof Oe=="object"&&Oe!==null&&(ce=Object.entries(Oe).map(([ve,qe])=>`${ve}: ${qe};`).join(" ")),x(ve=>{const qe=[...ve];return qe[he]={...qe[he],value:ce},qe})}}return{...B,[S]:V}})},[g]),fe=c.useCallback(async()=>{var S,B;if(!(!t||!s))try{k(!0),X(null);let V;if(N){const ce=I.find(ve=>ve.id===N);ce!=null&&ce.fileInfo&&(V=ce.fileInfo)}else I.length>0&&(V=I[0].fileInfo);let A;if(C){const ce=Y.find(ve=>ve.id===C);ce!=null&&ce.fileInfo&&(A=ce.fileInfo)}else Y.length>0&&(A=Y[0].fileInfo);const K={...Xi,unitId:s,...V&&{header:V},...A&&{footer:A}},he=g.map(ce=>{const ve=typeof ce.value=="string"?ce.value:"",qe=na(ve);return{id:ce.id,code:ce.code,value:qe}}),Ue={data:K,settings:he},Oe=await St.generateSampleTemplate(t,Ue);if(Oe.pdf)E(Oe.pdf);else throw new Error(a("error.noPdfInResponse","No PDF in response"))}catch(V){const A=((B=(S=V==null?void 0:V.response)==null?void 0:S.data)==null?void 0:B.message)||(V==null?void 0:V.message)||a("error.generatingPreview","Error generating preview");X(A),ge.error(A)}finally{k(!1)}},[t,s,N,C,I,Y,g,a]),Q=c.useCallback(async()=>{var S,B;if(t)try{p(!0);const V=g.map(A=>{const K=typeof A.value=="string"?A.value:"",he=na(K);return{templateSettingId:A.id,resourceId:null,value:he}});await St.saveBulkTemplateSettingValues(V),_(!1),ge.success(a("template.saveSuccess","Style settings saved successfully"))}catch(V){const A=((B=(S=V==null?void 0:V.response)==null?void 0:S.data)==null?void 0:B.message)||(V==null?void 0:V.message)||a("error.savingSettings","Error saving style settings");ge.error(A)}finally{p(!1)}},[t,g,a]),le=c.useCallback(()=>{F?(o(!0),d.current=r):r()},[F,r]),G=c.useCallback(()=>{o(!1),d.current&&(d.current(),d.current=null)},[]),oe=c.useCallback(()=>{o(!1),d.current=null},[]),Re=c.useCallback(S=>{u(S),_(!0)},[]),ye=c.useCallback(S=>{M(S),_(!0)},[]),$e=c.useCallback(S=>{var V;xe(S);const B=g.find(A=>h(A.code)===S);B&&T.current[B.id]&&((V=T.current[B.id])==null||V.scrollIntoView({behavior:"smooth",block:"start"}))},[g,h]);c.useEffect(()=>{var S,B;m&&(se(m.headers||[]),$(m.footers||[]),!N&&((S=m.headers)==null?void 0:S.length)>0&&u(m.headers[0].id),!C&&((B=m.footers)==null?void 0:B.length)>0&&M(m.footers[0].id))},[m,N,C]),c.useEffect(()=>{t&&(ee(),te())},[t,ee,te]),c.useEffect(()=>{Z.length>0&&!W&&xe(Z[0].code)},[Z,W]),c.useEffect(()=>{const S=B=>{F&&(B.preventDefault(),B.returnValue="")};return window.addEventListener("beforeunload",S),()=>window.removeEventListener("beforeunload",S)},[F]);const ze=c.useMemo(()=>JSON.stringify(g.map(S=>({id:S.id,value:S.value}))),[g]),Se=br(ze,500);return c.useEffect(()=>{if(ie){if(je){z(!1);return}Se!==O.current&&(O.current=Se,fe())}},[Se,ie,fe]),v&&g.length===0?e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsx(kr,{className:"h-8 w-8 animate-spin text-purple-600"})}):e.jsxs("div",{className:"flex flex-col h-screen bg-gray-50",children:[e.jsx("div",{className:"bg-white border-b border-gray-200 px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("button",{onClick:le,className:"flex items-center gap-2 text-gray-600 hover:text-gray-900 transition-colors",children:[e.jsx(xn,{className:"h-5 w-5"}),e.jsx("span",{className:"font-medium",children:a("common.back","Back")})]}),e.jsx("div",{className:"h-6 w-px bg-gray-300"}),e.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:((D=f==null?void 0:f.name)==null?void 0:D.en)||a("template.styleSettings","Style Settings")})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600",children:[e.jsx("input",{type:"checkbox",checked:ie,onChange:S=>Ae(S.target.checked),className:"w-4 h-4 rounded border-gray-300"}),a("template.livePreview","Live Preview")]}),e.jsx(ro,{visible:F})]})]})}),ne&&e.jsxs("div",{className:"mx-6 mt-4 p-4 bg-red-50 border border-red-200 rounded-lg",children:[e.jsx("p",{className:"text-sm text-red-800",children:ne}),e.jsx("button",{onClick:te,className:"mt-2 text-sm text-red-600 hover:text-red-800 font-medium",children:a("common.retry","Retry")})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("div",{className:"w-1/2 flex overflow-hidden border-r border-gray-200",children:[e.jsx("div",{className:"w-56 flex-shrink-0 bg-gray-50 border-r border-gray-200 overflow-y-auto",children:e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-700 mb-3",children:a("template.styleCategories","Style Categories")}),e.jsx("nav",{className:"space-y-1",children:Z.map(S=>e.jsx("button",{onClick:()=>$e(S.code),className:be("w-full text-left px-3 py-2 rounded-lg text-sm transition-colors",W===S.code?"bg-purple-100 text-purple-700 font-medium":"text-gray-600 hover:bg-gray-100"),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:S.label}),e.jsx("span",{className:"text-xs text-gray-400",children:S.settingIds.length})]})},S.code))})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:a("template.styleEditor","Style Editor")}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-4 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-800",children:a("template.headerFooterSelection","Header & Footer")}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:a("addRecord.Header","Header")}),e.jsxs("select",{value:N,onChange:S=>Re(S.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500",children:[e.jsx("option",{value:"",children:I!=null&&I.length?a("addRecord.Select Header","Select Header"):a("addRecord.Loading Headers...","Loading Headers...")}),I==null?void 0:I.map(S=>{var B,V;return e.jsx("option",{value:S.id,children:((B=S.name)==null?void 0:B.en)||((V=S.name)==null?void 0:V.am)},S.id)})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:a("addRecord.Footer","Footer")}),e.jsxs("select",{value:C,onChange:S=>ye(S.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500",children:[e.jsx("option",{value:"",children:Y!=null&&Y.length?a("addRecord.Select Footer","Select Footer"):a("addRecord.Loading Footers...","Loading Footers...")}),Y==null?void 0:Y.map(S=>{var B,V;return e.jsx("option",{value:S.id,children:((B=S.name)==null?void 0:B.en)||((V=S.name)==null?void 0:V.am)},S.id)})]})]})]}),N&&I.length>0&&(()=>{var B,V;const S=I.find(A=>A.id===N);return S!=null&&S.presigned?e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 border-2 border-dashed border-gray-300",children:[e.jsx("p",{className:"text-sm font-medium text-gray-600 mb-2",children:a("addRecord.Header Preview","Header Preview")}),e.jsx("img",{src:S.presigned,alt:((B=S.name)==null?void 0:B.en)||((V=S.name)==null?void 0:V.am)||"Header",className:"max-w-full h-auto"})]}):null})(),C&&Y.length>0&&(()=>{var B,V;const S=Y.find(A=>A.id===C);return S!=null&&S.presigned?e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 border-2 border-dashed border-gray-300",children:[e.jsx("p",{className:"text-sm font-medium text-gray-600 mb-2",children:a("addRecord.Footer Preview","Footer Preview")}),e.jsx("img",{src:S.presigned,alt:((B=S.name)==null?void 0:B.en)||((V=S.name)==null?void 0:V.am)||"Footer",className:"max-w-full h-auto"})]}):null})()]}),g.length===0&&!v?e.jsx("div",{className:"text-center py-8 text-gray-500",children:a("template.noSettings","No style settings available")}):W&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:((we=Z.find(S=>S.code===W))==null?void 0:we.label)||W}),g.filter(S=>P(S.code).includes(W)).map(S=>{const B=g.findIndex(V=>V.id===S.id);return e.jsx("div",{ref:V=>{T.current[S.id]=V},children:e.jsx(Yi,{setting:S,index:B,onChange:q,isDefault:R[S.id]??!0,onToggleDefault:de})},S.id)}),g.filter(S=>P(S.code).includes(W)).length===0&&e.jsx("p",{className:"text-gray-500 text-sm",children:a("template.noSettingsForCategory","No settings in this category")})]})]})})]}),e.jsx("div",{className:"w-1/2 bg-white",children:e.jsx(ao,{pdfUrl:j,loading:b,error:ne,onApply:fe})})]}),e.jsx("div",{className:"bg-white border-t border-gray-200 px-6 py-4",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{onClick:Q,disabled:v||!F,className:"px-6 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors font-medium",children:v?a("template.saving","Saving..."):a("common.save","Save")})})}),e.jsx(to,{isOpen:i,onConfirm:G,onCancel:oe})]})},so=()=>{const{t}=Ie(),[r,a]=c.useState([]),[n,s]=c.useState(null),[i,o]=c.useState(!0),[d,m]=c.useState(null);c.useEffect(()=>{l()},[]);const l=async()=>{var g;try{o(!0),m(null);const x=await St.getAllTemplates();a(x.items||[]),((g=x.items)==null?void 0:g.length)>0&&s(x.items[0].id)}catch{m(t("error.loadingTemplates","Error loading templates"))}finally{o(!1)}},f=g=>{s(g)},y=()=>{s(null)};return i?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(kr,{className:"h-8 w-8 animate-spin text-purple-600"})}):d?e.jsx("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg text-red-700",children:d}):r.length===0?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-gray-500",children:t("template.noTemplates","No templates available")})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700",children:t("template.selectTemplate","Select Template")}),e.jsxs(ft,{value:n||"",onValueChange:f,children:[e.jsx(ht,{className:"w-64",children:e.jsx(xt,{placeholder:t("template.selectTemplate")})}),e.jsx(yt,{children:r.map(g=>{var x,v;return e.jsx(bt,{value:g.id,children:((x=g.name)==null?void 0:x.en)||((v=g.name)==null?void 0:v.am)},g.id)})})]})]})}),n&&e.jsx(no,{templateId:n,onBack:y})]})},io=()=>{var N,u;const{user:t}=Ba(),r=sa.language,[a,n]=c.useState(!1),[s,i]=c.useState(!1),[o,d]=c.useState(""),[m,l]=c.useState(0),f=br(o,300),y=t!=null&&t.employee&&t.employee.length>0?t.employee[0].organizationId:void 0,{getList:g}=Ya(),{data:x,isLoading:v}=y?g(y,{take:300,skip:0}):{data:void 0,isLoading:!1},p=br(C=>{window.dispatchEvent(new CustomEvent("unitChanged",{detail:C}))},300);c.useEffect(()=>{f&&window.dispatchEvent(new CustomEvent("unitChanged",{detail:f}))},[f]);const j=c.useCallback(C=>{d(C),p(C)},[p]);c.useEffect(()=>{const C=()=>{window.innerWidth>=768&&n(!1)};return window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]),c.useEffect(()=>{var C,M;!v&&((M=(C=x==null?void 0:x.data)==null?void 0:C.items)!=null&&M.length)&&!o&&d(x.data.items[0].id)},[v,x,o]);const E=[{label:"contentManagement.seal",icon:e.jsx(ga,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(Ln,{unitId:o})},{label:"contentManagement.letterTemplate",icon:e.jsx(Ua,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(Kn,{unitId:o})},{label:"recordTag.title",icon:e.jsx(Rn,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(ws,{unitId:o})},{label:"contentManagement.prefix",icon:e.jsx(Cn,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(hs,{unitId:o,initialTab:"internal"})},{label:"contentManagement.commonRemarks",icon:e.jsx(Nn,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(Gn,{unitId:o})},{label:"contentManagement.headerAndFooter",icon:e.jsx(vn,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(Wn,{unitId:o})},{label:"template.sample",icon:e.jsx(mt,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(so,{})},{label:"dashboard.recentActivities",icon:e.jsx(Tn,{className:"h-5 w-5 flex-shrink-0"}),element:e.jsx(Vn,{activities:[]})}],b=E[m],k=(b==null?void 0:b.label)==="template.sample";return e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-gray-50 to-gray-100/30 dark:from-gray-900 dark:to-gray-800",children:e.jsxs("div",{className:"w-full h-full p-4 lg:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-2xl lg:text-3xl font-bold text-gray-900 dark:text-white tracking-tight",children:w("organization.contentManagement")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2 text-sm lg:text-base",children:w("organization.contentMsg")})]}),e.jsx("div",{className:"w-full lg:w-auto",children:e.jsx(ys,{})})]}),((u=(N=x==null?void 0:x.data)==null?void 0:N.items)==null?void 0:u.length)>0&&e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-200 dark:border-gray-700 p-4 lg:p-6 transition-all duration-200 hover:shadow-md",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[e.jsx("div",{className:"p-2 bg-purple-50 dark:bg-purple-900/30 rounded-lg",children:e.jsx(yn,{className:"h-5 w-5 text-purple-600 dark:text-purple-400"})}),e.jsx("div",{children:e.jsx("label",{className:"block text-sm font-semibold text-gray-900 dark:text-white",children:w("organization.selectUnit")})})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(ft,{value:o,onValueChange:j,disabled:v,children:[e.jsx(ht,{className:be("w-full border-gray-300 dark:border-gray-600 rounded-xl shadow-sm transition-all duration-200 dark:bg-gray-700 dark:text-white","focus:ring-2 focus:ring-purple-500 focus:border-purple-500","hover:border-gray-400 dark:hover:border-gray-500",v&&"opacity-50 cursor-not-allowed"),children:e.jsx(xt,{placeholder:v?w("common.loading"):w("organization.selectUnit")})}),e.jsx(yt,{className:"rounded-xl border border-gray-200 dark:border-gray-600 shadow-lg dark:bg-gray-800",children:x==null?void 0:x.data.items.map(C=>e.jsx(bt,{value:C.id,className:"rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors dark:text-gray-200",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 truncate",children:r==="en"?C.name.en:C.name.am}),C.id===o&&e.jsx("div",{className:"w-2 h-2 bg-purple-600 dark:bg-purple-400 rounded-full"})]})},C.id))})]})})]})}),e.jsxs("div",{className:be("flex w-full min-h-[calc(100vh-12rem)] bg-transparent rounded-2xl",k?"overflow-visible":"overflow-hidden"),children:[a&&e.jsx("div",{className:"fixed inset-0 bg-black/50 dark:bg-black/70 z-40 md:hidden backdrop-blur-sm transition-opacity duration-300",onClick:()=>n(!1)}),e.jsxs("div",{className:be("md:sticky top-0 flex flex-col bg-white dark:bg-gray-800 border-r border-gray-200/60 dark:border-gray-700 transition-all duration-300 ease-in-out","backdrop-blur-sm bg-white/95 md:bg-white dark:bg-gray-800/95",a?"absolute left-0 top-0 z-40 w-72 lg:w-80":"hidden md:flex",s?"md:w-16 lg:w-20":"md:w-72 lg:w-80","h-[calc(100vh-2rem)] md:h-screen rounded-2xl md:rounded-none shadow-xl md:shadow-none"),children:[e.jsxs("div",{className:be("flex items-center p-4 border-b border-gray-200/60 dark:border-gray-700 transition-all duration-300",s?"justify-center":"justify-between"),children:[!s&&e.jsx("div",{className:"flex items-center gap-3 min-w-0",children:e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white truncate",children:w("organization.contentManagement")})}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>i(!s),className:be("hidden md:flex p-2 rounded-xl hover:bg-purple-200 dark:hover:bg-purple-900/50 transition-all duration-200","hover:shadow-sm border border-transparent hover:border-purple-200 dark:hover:border-purple-800"),title:s?w("expandSidebar"):w("collapseSidebar"),children:s?e.jsx(Xt,{className:"h-4 w-4 text-gray-600 dark:text-gray-300"}):e.jsx(Xt,{className:"h-4 w-4 text-gray-600 dark:text-gray-300"})}),e.jsx("button",{onClick:()=>n(!1),className:"md:hidden p-2 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:e.jsx(lt,{className:"h-4 w-4 text-gray-600 dark:text-gray-300"})})]})]}),e.jsx("nav",{className:"flex-1 p-3 space-y-1 overflow-y-auto",children:E.map((C,M)=>e.jsxs("button",{onClick:()=>{l(M),n(!1)},className:be("w-full flex items-center gap-3 p-3 rounded-xl text-sm font-medium cursor-pointer transition-all duration-200","border border-transparent hover:border-gray-200 dark:hover:border-gray-600 hover:shadow-sm",s?"justify-center":"",m===M?"bg-gradient-to-r from-purple-50 to-purple-50 dark:from-purple-900/30 dark:to-purple-900/20 text-purple-700 dark:text-purple-300 border-purple-200 dark:border-purple-700 shadow-sm":"text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 hover:text-gray-900 dark:hover:text-white"),children:[e.jsx("span",{className:be("transition-transform duration-200",m===M&&"scale-110"),children:C.icon}),!s&&e.jsx("span",{className:"flex-1 text-left truncate font-semibold",children:w(C.label)})]},M))})]}),e.jsxs("div",{className:be("flex-1 flex flex-col min-w-0 transition-all duration-300","md:ml-0"),children:[e.jsxs("div",{className:"md:hidden flex items-center justify-between p-4 bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm border-b border-gray-200/60 dark:border-gray-700 rounded-t-2xl",children:[e.jsx("button",{onClick:()=>n(!0),className:"p-2 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors shadow-sm border border-gray-200 dark:border-gray-600",children:e.jsx(Xt,{className:"h-5 w-5 text-gray-600 dark:text-gray-300"})}),e.jsx("div",{className:"flex-1 text-center",children:e.jsx("h1",{className:"text-lg font-semibold text-gray-900 dark:text-white truncate",children:w((b==null?void 0:b.label)||"contentmanagement")})}),e.jsx("div",{className:"w-9"})]}),e.jsxs("div",{className:be("flex-1 p-4 md:p-6",k?"overflow-visible":"overflow-auto"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 mb-6 flex-wrap",children:[e.jsx("span",{className:"text-gray-400 dark:text-gray-500",children:w("content")}),b&&e.jsxs(e.Fragment,{children:[e.jsx(vr,{className:"h-4 w-4 text-gray-400 dark:text-gray-500"}),e.jsx("span",{className:"text-gray-900 dark:text-white font-semibold bg-gray-100 dark:bg-gray-700 px-3 py-1 rounded-full text-sm",children:w(b.label)})]})]}),e.jsx("div",{className:be("w-full transition-opacity duration-300"),children:e.jsx("div",{className:be("rounded-2xl shadow-sm border border-gray-200/60 dark:border-gray-700",k?"overflow-visible":"overflow-hidden"),children:b==null?void 0:b.element})})]})]})]})]})})},Zo=()=>e.jsx(io,{});export{Zo as default};
