forlogic-core 2.3.1 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/action-plans/auth/services/AuthService.d.ts +19 -0
  2. package/dist/action-plans/exports/ui.d.ts +2 -0
  3. package/dist/action-plans/i18n/LanguageBootstrap.d.ts +14 -0
  4. package/dist/action-plans/i18n/index.d.ts +1 -0
  5. package/dist/action-plans/index.esm.js +1 -1
  6. package/dist/action-plans/index.js +1 -1
  7. package/dist/audit-trail/auth/services/AuthService.d.ts +19 -0
  8. package/dist/audit-trail/exports/ui.d.ts +2 -0
  9. package/dist/audit-trail/i18n/LanguageBootstrap.d.ts +14 -0
  10. package/dist/audit-trail/i18n/index.d.ts +1 -0
  11. package/dist/audit-trail/index.esm.js +1 -1
  12. package/dist/audit-trail/index.js +1 -1
  13. package/dist/auth/services/AuthService.d.ts +19 -0
  14. package/dist/exports/ui.d.ts +2 -0
  15. package/dist/i18n/LanguageBootstrap.d.ts +14 -0
  16. package/dist/i18n/index.d.ts +1 -0
  17. package/dist/index.css +1 -1
  18. package/dist/index.css.map +1 -1
  19. package/dist/index.esm.js +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/leadership/auth/services/AuthService.d.ts +19 -0
  22. package/dist/leadership/exports/ui.d.ts +2 -0
  23. package/dist/leadership/i18n/LanguageBootstrap.d.ts +14 -0
  24. package/dist/leadership/i18n/index.d.ts +1 -0
  25. package/dist/leadership/index.esm.js +1 -1
  26. package/dist/leadership/index.js +1 -1
  27. package/dist/places/auth/services/AuthService.d.ts +19 -0
  28. package/dist/places/exports/ui.d.ts +2 -0
  29. package/dist/places/i18n/LanguageBootstrap.d.ts +14 -0
  30. package/dist/places/i18n/index.d.ts +1 -0
  31. package/dist/places/index.esm.js +1 -1
  32. package/dist/places/index.js +1 -1
  33. package/dist/sign/auth/services/AuthService.d.ts +19 -0
  34. package/dist/sign/exports/ui.d.ts +2 -0
  35. package/dist/sign/i18n/LanguageBootstrap.d.ts +14 -0
  36. package/dist/sign/i18n/index.d.ts +1 -0
  37. package/dist/sign/index.esm.js +1 -1
  38. package/dist/sign/index.js +1 -1
  39. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("@radix-ui/react-tabs"),s=require("clsx"),r=require("tailwind-merge"),n=require("date-fns");require("sonner");var i=require("@radix-ui/react-slot"),o=require("class-variance-authority"),l=require("@radix-ui/react-dropdown-menu"),d=require("lucide-react"),c=require("i18next"),m=require("@radix-ui/react-label"),u=require("@radix-ui/react-select"),p=require("react-day-picker"),x=require("react-i18next"),h=require("@radix-ui/react-popover"),f=require("@radix-ui/react-progress"),g=require("@radix-ui/react-dialog"),v=require("@radix-ui/react-separator"),b=require("@radix-ui/react-alert-dialog");function j(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(a){if("default"!==a){var s=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,s.get?s:{enumerable:!0,get:function(){return e[a]}})}}),t.default=e,Object.freeze(t)}var y=j(t),N=j(a),w=j(l),k=j(m),C=j(u),S=j(h),P=j(f),T=j(g),E=j(v),D=j(b);function _(e){return(t={})=>{const a=t.width?String(t.width):e.defaultWidth;return e.formats[a]||e.formats[e.defaultWidth]}}function R(e){return(t,a)=>{let s;if("formatting"===(a?.context?String(a.context):"standalone")&&e.formattingValues){const t=e.defaultFormattingWidth||e.defaultWidth,r=a?.width?String(a.width):t;s=e.formattingValues[r]||e.formattingValues[t]}else{const t=e.defaultWidth,r=a?.width?String(a.width):e.defaultWidth;s=e.values[r]||e.values[t]}return s[e.argumentCallback?e.argumentCallback(t):t]}}function A(e){return(t,a={})=>{const s=a.width,r=s&&e.matchPatterns[s]||e.matchPatterns[e.defaultMatchWidth],n=t.match(r);if(!n)return null;const i=n[0],o=s&&e.parsePatterns[s]||e.parsePatterns[e.defaultParseWidth],l=Array.isArray(o)?function(e,t){for(let a=0;a<e.length;a++)if(t(e[a]))return a;return}(o,e=>e.test(i)):function(e,t){for(const a in e)if(Object.prototype.hasOwnProperty.call(e,a)&&t(e[a]))return a;return}(o,e=>e.test(i));let d;d=e.valueCallback?e.valueCallback(l):l,d=a.valueCallback?a.valueCallback(d):d;return{value:d,rest:t.slice(i.length)}}}const I={lessThanXSeconds:{one:"menos de um segundo",other:"menos de {{count}} segundos"},xSeconds:{one:"1 segundo",other:"{{count}} segundos"},halfAMinute:"meio minuto",lessThanXMinutes:{one:"menos de um minuto",other:"menos de {{count}} minutos"},xMinutes:{one:"1 minuto",other:"{{count}} minutos"},aboutXHours:{one:"cerca de 1 hora",other:"cerca de {{count}} horas"},xHours:{one:"1 hora",other:"{{count}} horas"},xDays:{one:"1 dia",other:"{{count}} dias"},aboutXWeeks:{one:"cerca de 1 semana",other:"cerca de {{count}} semanas"},xWeeks:{one:"1 semana",other:"{{count}} semanas"},aboutXMonths:{one:"cerca de 1 mês",other:"cerca de {{count}} meses"},xMonths:{one:"1 mês",other:"{{count}} meses"},aboutXYears:{one:"cerca de 1 ano",other:"cerca de {{count}} anos"},xYears:{one:"1 ano",other:"{{count}} anos"},overXYears:{one:"mais de 1 ano",other:"mais de {{count}} anos"},almostXYears:{one:"quase 1 ano",other:"quase {{count}} anos"}},z={date:_({formats:{full:"EEEE, d 'de' MMMM 'de' y",long:"d 'de' MMMM 'de' y",medium:"d MMM y",short:"dd/MM/yyyy"},defaultWidth:"full"}),time:_({formats:{full:"HH:mm:ss zzzz",long:"HH:mm:ss z",medium:"HH:mm:ss",short:"HH:mm"},defaultWidth:"full"}),dateTime:_({formats:{full:"{{date}} 'às' {{time}}",long:"{{date}} 'às' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},L={lastWeek:e=>{const t=e.getDay();return"'"+(0===t||6===t?"último":"última")+"' eeee 'às' p"},yesterday:"'ontem às' p",today:"'hoje às' p",tomorrow:"'amanhã às' p",nextWeek:"eeee 'às' p",other:"P"};var M;const W={code:"pt-BR",formatDistance:(e,t,a)=>{let s;const r=I[e];return s="string"==typeof r?r:1===t?r.one:r.other.replace("{{count}}",String(t)),a?.addSuffix?a.comparison&&a.comparison>0?"em "+s:"há "+s:s},formatLong:z,formatRelative:(e,t,a,s)=>{const r=L[e];return"function"==typeof r?r(t):r},localize:{ordinalNumber:(e,t)=>{const a=Number(e);return"week"===t?.unit?a+"ª":a+"º"},era:R({values:{narrow:["AC","DC"],abbreviated:["AC","DC"],wide:["antes de cristo","depois de cristo"]},defaultWidth:"wide"}),quarter:R({values:{narrow:["1","2","3","4"],abbreviated:["T1","T2","T3","T4"],wide:["1º trimestre","2º trimestre","3º trimestre","4º trimestre"]},defaultWidth:"wide",argumentCallback:e=>e-1}),month:R({values:{narrow:["j","f","m","a","m","j","j","a","s","o","n","d"],abbreviated:["jan","fev","mar","abr","mai","jun","jul","ago","set","out","nov","dez"],wide:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"]},defaultWidth:"wide"}),day:R({values:{narrow:["D","S","T","Q","Q","S","S"],short:["dom","seg","ter","qua","qui","sex","sab"],abbreviated:["domingo","segunda","terça","quarta","quinta","sexta","sábado"],wide:["domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado"]},defaultWidth:"wide"}),dayPeriod:R({values:{narrow:{am:"a",pm:"p",midnight:"mn",noon:"md",morning:"manhã",afternoon:"tarde",evening:"tarde",night:"noite"},abbreviated:{am:"AM",pm:"PM",midnight:"meia-noite",noon:"meio-dia",morning:"manhã",afternoon:"tarde",evening:"tarde",night:"noite"},wide:{am:"a.m.",pm:"p.m.",midnight:"meia-noite",noon:"meio-dia",morning:"manhã",afternoon:"tarde",evening:"tarde",night:"noite"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mn",noon:"md",morning:"da manhã",afternoon:"da tarde",evening:"da tarde",night:"da noite"},abbreviated:{am:"AM",pm:"PM",midnight:"meia-noite",noon:"meio-dia",morning:"da manhã",afternoon:"da tarde",evening:"da tarde",night:"da noite"},wide:{am:"a.m.",pm:"p.m.",midnight:"meia-noite",noon:"meio-dia",morning:"da manhã",afternoon:"da tarde",evening:"da tarde",night:"da noite"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(M={matchPattern:/^(\d+)[ºªo]?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)},(e,t={})=>{const a=e.match(M.matchPattern);if(!a)return null;const s=a[0],r=e.match(M.parsePattern);if(!r)return null;let n=M.valueCallback?M.valueCallback(r[0]):r[0];return n=t.valueCallback?t.valueCallback(n):n,{value:n,rest:e.slice(s.length)}}),era:A({matchPatterns:{narrow:/^(ac|dc|a|d)/i,abbreviated:/^(a\.?\s?c\.?|d\.?\s?c\.?)/i,wide:/^(antes de cristo|depois de cristo)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^ac/i,/^dc/i],wide:[/^antes de cristo/i,/^depois de cristo/i]},defaultParseWidth:"any"}),quarter:A({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^T[1234]/i,wide:/^[1234](º)? trimestre/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:e=>e+1}),month:A({matchPatterns:{narrow:/^[jfmajsond]/i,abbreviated:/^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i,wide:/^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^fev/i,/^mar/i,/^abr/i,/^mai/i,/^jun/i,/^jul/i,/^ago/i,/^set/i,/^out/i,/^nov/i,/^dez/i]},defaultParseWidth:"any"}),day:A({matchPatterns:{narrow:/^(dom|[23456]ª?|s[aá]b)/i,short:/^(dom|[23456]ª?|s[aá]b)/i,abbreviated:/^(dom|seg|ter|qua|qui|sex|s[aá]b)/i,wide:/^(domingo|(segunda|ter[cç]a|quarta|quinta|sexta)([- ]feira)?|s[aá]bado)/i},defaultMatchWidth:"wide",parsePatterns:{short:[/^d/i,/^2/i,/^3/i,/^4/i,/^5/i,/^6/i,/^s[aá]/i],narrow:[/^d/i,/^2/i,/^3/i,/^4/i,/^5/i,/^6/i,/^s[aá]/i],any:[/^d/i,/^seg/i,/^t/i,/^qua/i,/^qui/i,/^sex/i,/^s[aá]b/i]},defaultParseWidth:"any"}),dayPeriod:A({matchPatterns:{narrow:/^(a|p|mn|md|(da) (manhã|tarde|noite))/i,any:/^([ap]\.?\s?m\.?|meia[-\s]noite|meio[-\s]dia|(da) (manhã|tarde|noite))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mn|^meia[-\s]noite/i,noon:/^md|^meio[-\s]dia/i,morning:/manhã/i,afternoon:/tarde/i,evening:/tarde/i,night:/noite/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}};function F(e,t=.1){const{r:a,g:s,b:r}=function(e){const t=e.replace("#",""),a=3===t.length?t.split("").map(e=>e+e).join(""):t;return{r:parseInt(a.substring(0,2),16),g:parseInt(a.substring(2,4),16),b:parseInt(a.substring(4,6),16)}}(e);return`rgba(${a}, ${s}, ${r}, ${t})`}function q(...e){return r.twMerge(s.clsx(e))}const B=N.Root,O=y.forwardRef(({className:t,...a},s)=>e.jsx(N.List,{ref:s,className:q("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",t),...a}));O.displayName=N.List.displayName;const V=y.forwardRef(({className:t,...a},s)=>e.jsx(N.Trigger,{ref:s,className:q("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",t),...a}));V.displayName=N.Trigger.displayName;const H=y.forwardRef(({className:t,...a},s)=>e.jsx(N.Content,{ref:s,className:q("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...a}));H.displayName=N.Content.displayName;const U=o.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary-hover shadow-sm hover:shadow-md active:scale-[0.98]",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary-hover border border-input shadow-sm",tertiary:"bg-background text-foreground hover:bg-accent hover:text-accent-foreground border border-border",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground",subtle:"text-muted-foreground hover:text-foreground hover:bg-accent/50",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm hover:shadow-md",danger:"bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm hover:shadow-md",link:"text-primary underline-offset-4 hover:underline",icon:"bg-transparent border border-input hover:bg-accent hover:text-accent-foreground p-2",loading:"bg-primary/50 text-primary-foreground cursor-wait",default:"bg-primary text-primary-foreground hover:bg-primary/90",action:"bg-primary/10 text-primary hover:bg-primary/20 border border-primary/30","icon-only":"bg-transparent border border-input hover:bg-accent hover:text-accent-foreground p-2","external-link":"bg-transparent text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors","action-primary":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm","action-secondary":"bg-secondary text-secondary-foreground hover:bg-secondary/80 border border-input"},size:{sm:"h-8 px-3 text-xs rounded-lg",md:"h-10 px-4 py-2 text-sm rounded-md",lg:"h-12 px-8 text-base rounded-lg",xl:"h-14 px-10 text-lg rounded-lg",icon:"h-10 w-10","icon-sm":"h-8 w-8","icon-xs":"h-6 w-6",default:"h-10 px-4 py-2"}},defaultVariants:{variant:"primary",size:"md"}}),$=y.forwardRef(({className:t,variant:a,size:s,asChild:r=!1,...n},o)=>{const l=r?i.Slot:"button";return e.jsx(l,{className:q(U({variant:a,size:s,className:t})),ref:o,...n})});$.displayName="Button";const X=w.Root,Y=w.Trigger;y.forwardRef(({className:t,inset:a,children:s,...r},n)=>e.jsxs(w.SubTrigger,{ref:n,className:q("flex cursor-default select-none items-center px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",a&&"pl-8",t),...r,children:[s,e.jsx(d.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=w.SubTrigger.displayName;y.forwardRef(({className:t,...a},s)=>e.jsx(w.SubContent,{ref:s,className:q("z-50 min-w-[8rem] overflow-hidden border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...a})).displayName=w.SubContent.displayName;const G=y.forwardRef(({className:t,sideOffset:a=4,...s},r)=>e.jsx(w.Portal,{children:e.jsx(w.Content,{ref:r,sideOffset:a,className:q("z-[100] min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground p-1 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...s})}));G.displayName=w.Content.displayName;const K=y.forwardRef(({className:t,inset:a,...s},r)=>e.jsx(w.Item,{ref:r,className:q("relative flex cursor-default select-none items-center px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",t),...s}));K.displayName=w.Item.displayName;y.forwardRef(({className:t,children:a,checked:s,...r},n)=>e.jsxs(w.CheckboxItem,{ref:n,className:q("relative flex cursor-default select-none items-center py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:s,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(w.ItemIndicator,{children:e.jsx(d.Check,{className:"h-4 w-4"})})}),a]})).displayName=w.CheckboxItem.displayName;y.forwardRef(({className:t,children:a,...s},r)=>e.jsxs(w.RadioItem,{ref:r,className:q("relative flex cursor-default select-none items-center py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...s,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(w.ItemIndicator,{children:e.jsx(d.Circle,{className:"h-2 w-2 fill-current"})})}),a]})).displayName=w.RadioItem.displayName;y.forwardRef(({className:t,inset:a,...s},r)=>e.jsx(w.Label,{ref:r,className:q("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",t),...s})).displayName=w.Label.displayName;const Q=y.forwardRef(({className:t,...a},s)=>e.jsx(w.Separator,{ref:s,className:q("-mx-1 my-1 h-px bg-muted",t),...a}));Q.displayName=w.Separator.displayName;const J={sm:"h-4 w-4",md:"h-6 w-6",lg:"h-8 w-8"};function Z({size:t="md",className:a}){return e.jsx(d.Loader2,{className:q("animate-spin text-muted-foreground",J[t],a)})}function ee({isLoading:t,children:a,className:s,type:r="spinner",size:n="md"}){return t?"overlay"===r?e.jsxs("div",{className:q("relative",s),children:[a,e.jsx("div",{className:"absolute inset-0 bg-background/50 backdrop-blur-sm flex items-center justify-center z-10",children:e.jsx(Z,{size:n})})]}):"skeleton"===r?e.jsx("div",{className:q("animate-pulse",s),children:e.jsx("div",{className:"bg-muted rounded-md h-full w-full"})}):e.jsx("div",{className:q("flex items-center justify-center py-8",s),children:e.jsx(Z,{size:n})}):e.jsx(e.Fragment,{children:a})}var te,ae,se,re,ne;exports.ETaskPlanStatus=void 0,(te=exports.ETaskPlanStatus||(exports.ETaskPlanStatus={}))[te.waitingStart=1]="waitingStart",te[te.running=2]="running",te[te.effectivenessCheck=3]="effectivenessCheck",te[te.done=4]="done",te[te.suspended=5]="suspended",te[te.canceled=6]="canceled",exports.ETaskPlanPriority=void 0,(ae=exports.ETaskPlanPriority||(exports.ETaskPlanPriority={}))[ae.low=0]="low",ae[ae.medium=1]="medium",ae[ae.high=2]="high",exports.ETaskPlanAssociationType=void 0,(se=exports.ETaskPlanAssociationType||(exports.ETaskPlanAssociationType={}))[se.plan=2]="plan",se[se.occurrence=3]="occurrence",se[se.risk=4]="risk",se[se.decisions=5]="decisions",se[se.audit=6]="audit",se[se.strategyExtension=7]="strategyExtension",se[se.standardization=8]="standardization",se[se.supplier=9]="supplier",se[se.auditItems=10]="auditItems",exports.ETaskPlanTypeProgress=void 0,(re=exports.ETaskPlanTypeProgress||(exports.ETaskPlanTypeProgress={}))[re.currentProgress=1]="currentProgress",re[re.cumulativeProgress=2]="cumulativeProgress",exports.EAttachmentItemStatus=void 0,(ne=exports.EAttachmentItemStatus||(exports.EAttachmentItemStatus={})).uploading="uploading",ne.waiting="waiting",ne.done="done",ne.error="error",ne.canceled="canceled",ne.duplicateItem="duplicateItem";const ie={[exports.ETaskPlanStatus.waitingStart]:"#D6D6D6",[exports.ETaskPlanStatus.running]:"#DAE9F4",[exports.ETaskPlanStatus.effectivenessCheck]:"#1B75BB29",[exports.ETaskPlanStatus.done]:"#DDEECA",[exports.ETaskPlanStatus.suspended]:"#FFF2D6",[exports.ETaskPlanStatus.canceled]:"#F4433629"},oe={[exports.ETaskPlanStatus.waitingStart]:"#666666",[exports.ETaskPlanStatus.running]:"#1B75BB",[exports.ETaskPlanStatus.effectivenessCheck]:"#1B75BB",[exports.ETaskPlanStatus.done]:"#4CAF50",[exports.ETaskPlanStatus.suspended]:"#FF9800",[exports.ETaskPlanStatus.canceled]:"#F44336"},le={[exports.ETaskPlanStatus.waitingStart]:"waiting-start",[exports.ETaskPlanStatus.running]:"running",[exports.ETaskPlanStatus.effectivenessCheck]:"effectiveness-check",[exports.ETaskPlanStatus.done]:"done",[exports.ETaskPlanStatus.suspended]:"suspended",[exports.ETaskPlanStatus.canceled]:"canceled"};function de(){return{[exports.ETaskPlanStatus.waitingStart]:c.t("ap_status_waiting_start"),[exports.ETaskPlanStatus.running]:c.t("ap_status_running"),[exports.ETaskPlanStatus.effectivenessCheck]:c.t("ap_status_effectiveness_check"),[exports.ETaskPlanStatus.done]:c.t("ap_status_done"),[exports.ETaskPlanStatus.suspended]:c.t("ap_status_suspended"),[exports.ETaskPlanStatus.canceled]:c.t("ap_status_canceled")}}const ce=new Proxy({},{get:(e,t)=>{if("symbol"==typeof t)return;return de()[t]}});const me=[{id:"immediate",label:"Imediata"},{id:"corrective",label:"Corretiva"},{id:"preventive",label:"Preventiva"},{id:"improvement",label:"Oportunidade de Melhoria"},{id:"standardization",label:"Padronização"}];const ue=[{id:exports.ETaskPlanPriority.low,label:"Baixa",color:"#4CAF50"},{id:exports.ETaskPlanPriority.medium,label:"Média",color:"#FF9800"},{id:exports.ETaskPlanPriority.high,label:"Alta",color:"#F44336"}],pe=[exports.ETaskPlanStatus.done,exports.ETaskPlanStatus.canceled],xe=[exports.ETaskPlanStatus.waitingStart,exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.effectivenessCheck,exports.ETaskPlanStatus.suspended];function he(e){const{actionPlan:a,isNew:s=!1,config:r,onSave:n,onCancel:i,onDelete:o,onChangeStatus:l}=e,[d,c]=t.useState({formData:a||{},isLoading:e.isLoading||!1,isSaving:!1,activeTab:"general",isFormDisabled:!1});t.useEffect(()=>{a&&c(e=>({...e,formData:a,isFormDisabled:r?.disableFields||pe.includes(a.statusId)}))},[a,r?.disableFields]),t.useEffect(()=>{c(t=>({...t,isLoading:e.isLoading||!1}))},[e.isLoading]);const m=t.useCallback((e,t)=>{c(a=>({...a,formData:{...a.formData,[e]:t}}))},[]),u=t.useCallback(e=>{c(t=>({...t,activeTab:e}))},[]),p=t.useCallback(async()=>{if(n){c(e=>({...e,isSaving:!0}));try{await n(d.formData)}finally{c(e=>({...e,isSaving:!1}))}}},[n,d.formData]),x=t.useCallback(async e=>{if(l&&d.formData.id){c(e=>({...e,isLoading:!0}));try{await l(d.formData.id,e)}finally{c(e=>({...e,isLoading:!1}))}}},[l,d.formData.id]),h=t.useCallback(async()=>{if(o&&d.formData.id){c(e=>({...e,isLoading:!0}));try{await o(d.formData.id)}finally{c(e=>({...e,isLoading:!1}))}}},[o,d.formData.id]);return{formData:d.formData,isLoading:d.isLoading,isSaving:d.isSaving,activeTab:d.activeTab,isFormDisabled:d.isFormDisabled,updateField:m,setActiveTab:u,save:p,changeStatus:x,remove:h,cancel:i}}const fe={sm:{badge:"px-1.5 py-0.5 text-[11px] gap-1",icon:14},md:{badge:"px-2.5 py-1 text-xs gap-1.5",icon:16},lg:{badge:"px-3 py-1.5 text-sm gap-2",icon:18}};function ge({label:t,color:a,icon:s,showIcon:r,size:n="md",variant:i="filled",backgroundColor:o,className:l}){const d=fe[n],c=r??!!s;return e.jsxs("span",{className:q("inline-flex items-center rounded-md font-medium whitespace-nowrap","outline"===i&&"border",d.badge,l),style:(()=>{switch(i){case"outline":return{color:a,borderColor:F(a,.3),backgroundColor:"transparent"};case"ghost":return{color:a,backgroundColor:"transparent"};default:return{color:a,backgroundColor:o||F(a,.1)}}})(),children:[c&&s&&e.jsx(s,{size:d.icon,strokeWidth:2}),t]})}const ve={[exports.ETaskPlanStatus.waitingStart]:{label:"",color:"#8B7355",icon:d.Clock},[exports.ETaskPlanStatus.running]:{label:"",color:"#2E7D5B",icon:d.Play},[exports.ETaskPlanStatus.effectivenessCheck]:{label:"",color:"#4A6FA5",icon:d.ShieldCheck},[exports.ETaskPlanStatus.done]:{label:"",color:"#3D7A40",icon:d.CheckCircle2},[exports.ETaskPlanStatus.suspended]:{label:"",color:"#6B7280",icon:d.Pause},[exports.ETaskPlanStatus.canceled]:{label:"",color:"#B44A4A",icon:d.X}};function be({status:t,labels:a,className:s,size:r,showIcon:n,variant:i}){const o=de(),l=ve[t];if(!l)return null;const d=a?.[t]||o[t]||"";return e.jsx(ge,{label:d,color:l.color,icon:l.icon,size:r,showIcon:n,variant:i,className:s})}const je=y.forwardRef(({className:t,type:a,showCharCount:s,maxLength:r,onChange:n,...i},o)=>{const[l,d]=y.useState(0);y.useEffect(()=>{"string"==typeof i.value?d(i.value.length):"string"==typeof i.defaultValue&&d(i.defaultValue.length)},[i.value,i.defaultValue]);return e.jsxs("div",{className:"w-full",children:[e.jsx("input",{type:a,className:q("flex h-10 w-full rounded-lg border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors md:text-sm",t),ref:o,maxLength:r,onChange:e=>{d(e.target.value.length),n?.(e)},...i}),s&&r&&e.jsxs("div",{className:"text-right text-xs text-muted-foreground mt-1",children:[l," / ",r]})]})});je.displayName="Input";const ye=y.forwardRef(({className:t,showCharCount:a,maxLength:s,onChange:r,...n},i)=>{const[o,l]=y.useState(0);y.useEffect(()=>{"string"==typeof n.value?l(n.value.length):"string"==typeof n.defaultValue&&l(n.defaultValue.length)},[n.value,n.defaultValue]);return e.jsxs("div",{className:"w-full",children:[e.jsx("textarea",{className:q("flex min-h-[80px] w-full rounded-lg border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground hover:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",t),ref:i,maxLength:s,onChange:e=>{l(e.target.value.length),r?.(e)},...n}),a&&s&&e.jsxs("div",{className:"text-right text-xs text-muted-foreground mt-1",children:[o," / ",s]})]})});ye.displayName="Textarea";const Ne=o.cva("text-xs font-medium leading-none text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),we=y.forwardRef(({className:t,...a},s)=>e.jsx(k.Root,{ref:s,className:q(Ne(),t),...a}));we.displayName=k.Root.displayName;const ke=y.createContext({showCheck:!1}),Ce=({showCheck:t=!1,...a})=>e.jsx(ke.Provider,{value:{showCheck:t},children:e.jsx(C.Root,{...a})}),Se=C.Value,Pe=y.forwardRef(({className:t,children:a,...s},r)=>e.jsxs(C.Trigger,{ref:r,className:q("flex h-10 w-full items-center justify-between rounded-lg border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground hover:border-primary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors [&>span]:line-clamp-1",t),...s,children:[a,e.jsx(C.Icon,{asChild:!0,children:e.jsx(d.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Pe.displayName=C.Trigger.displayName;const Te=y.forwardRef(({className:t,...a},s)=>e.jsx(C.ScrollUpButton,{ref:s,className:q("flex cursor-default items-center justify-center py-1",t),...a,children:e.jsx(d.ChevronUp,{className:"h-4 w-4"})}));Te.displayName=C.ScrollUpButton.displayName;const Ee=y.forwardRef(({className:t,...a},s)=>e.jsx(C.ScrollDownButton,{ref:s,className:q("flex cursor-default items-center justify-center py-1",t),...a,children:e.jsx(d.ChevronDown,{className:"h-4 w-4"})}));Ee.displayName=C.ScrollDownButton.displayName;const De=y.forwardRef(({className:t,children:a,position:s="popper",container:r,collisionBoundary:n,...i},o)=>e.jsx(C.Portal,{container:r,children:e.jsxs(C.Content,{ref:o,className:q("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===s&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:s,collisionBoundary:n,...i,children:[e.jsx(Te,{}),e.jsx(C.Viewport,{className:q("p-1","popper"===s&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),e.jsx(Ee,{})]})}));De.displayName=C.Content.displayName;y.forwardRef(({className:t,...a},s)=>e.jsx(C.Label,{ref:s,className:q("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...a})).displayName=C.Label.displayName;const _e=y.forwardRef(({className:t,children:a,...s},r)=>{const{showCheck:n}=y.useContext(ke);return e.jsxs(C.Item,{ref:r,className:q("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n?"pl-8":"pl-2","data-[state=checked]:bg-accent data-[state=checked]:text-accent-foreground data-[state=checked]:font-medium data-[state=checked]:border-l-2 data-[state=checked]:border-primary",n?"data-[state=checked]:pl-[calc(2rem-2px)]":"data-[state=checked]:pl-[calc(0.5rem-2px)]",t),...s,children:[n&&e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(C.ItemIndicator,{children:e.jsx(d.Check,{className:"h-4 w-4"})})}),e.jsx(C.ItemText,{children:a})]})});_e.displayName=C.Item.displayName;function Re({className:t,classNames:a,showOutsideDays:s=!0,...r}){return e.jsx(p.DayPicker,{showOutsideDays:s,className:q("p-3 pointer-events-auto",t),locale:W,classNames:{months:"relative flex flex-col gap-4 sm:flex-row",month:"flex flex-col gap-4",month_caption:"flex h-9 w-full items-center justify-center px-8",caption_label:"text-sm font-medium",nav:"absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1 px-1",button_previous:q(U({variant:"outline"}),"z-10 h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),button_next:q(U({variant:"outline"}),"z-10 h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),month_grid:"w-full border-collapse",weekdays:"flex",weekday:"text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal w-9",week:"mt-2 flex w-full",day:"group/day relative h-9 w-9 select-none p-0 text-center text-sm [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md focus-within:relative focus-within:z-20",day_button:q(U({variant:"ghost"}),"h-9 w-9 p-0 font-normal transition-none aria-selected:opacity-100"),range_start:"bg-accent rounded-l-md",range_end:"bg-accent rounded-r-md",range_middle:"rounded-none aria-selected:bg-accent aria-selected:text-accent-foreground",selected:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground rounded-md",today:"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",outside:"text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",disabled:"text-muted-foreground opacity-50",hidden:"invisible",...a},components:{Chevron:({orientation:t})=>"left"===t?e.jsx(d.ChevronLeft,{className:"h-4 w-4"}):e.jsx(d.ChevronRight,{className:"h-4 w-4"})},...r})}y.forwardRef(({className:t,...a},s)=>e.jsx(C.Separator,{ref:s,className:q("-mx-1 my-1 h-px bg-muted",t),...a})).displayName=C.Separator.displayName,Re.displayName="Calendar";const Ae=S.Root,Ie=S.Trigger,ze=y.forwardRef(({className:t,align:a="center",sideOffset:s=4,container:r,...n},i)=>e.jsx(S.Portal,{container:r,children:e.jsx(S.Content,{ref:i,align:a,sideOffset:s,className:q("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...n})}));function Le({date:t,onDateChange:a,placeholder:s,disabled:r=!1,className:i,disabledDates:o}){const{t:l}=x.useTranslation(),c=s??l("select_date");return e.jsxs(Ae,{children:[e.jsx(Ie,{asChild:!0,children:e.jsxs($,{variant:"outline",disabled:r,className:q("w-full justify-start text-left font-normal",!t&&"text-muted-foreground",i),children:[e.jsx(d.Calendar,{className:"mr-2 h-4 w-4"}),t?n.format(t,"d 'de' MMMM 'de' yyyy",{locale:W}):e.jsx("span",{children:c})]})}),e.jsx(ze,{className:"w-auto p-0",align:"start",children:e.jsx(Re,{mode:"single",selected:t,onSelect:a,disabled:o,initialFocus:!0,className:"pointer-events-auto"})})]})}function Me({formData:a,updateField:s,disabled:r=!1,users:n=[],places:i=[],actionTypes:o,causes:l=[],parentActions:d=[],config:c}){const{t:m}=x.useTranslation(),u=c?.requiredFields,p=o||me,h=e=>{if(c?.hiddenFields?.includes(e))return!1;if(c?.visibleFields&&c.visibleFields.length>0)return c.visibleFields.includes(e);const t=`${e}Visible`;return!u||!(t in u)||!1!==u[t]},f=e=>u?!!u[e]:"name"===e,g=t.useMemo(()=>{if(a.startDate&&a.endDate){const e=new Date(a.startDate),t=new Date(a.endDate).getTime()-e.getTime();return Math.max(0,Math.ceil(t/864e5))}return a.duration||0},[a.startDate,a.endDate,a.duration]);return e.jsxs("div",{className:"space-y-6 p-1",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("name")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Nome"}),e.jsx(je,{value:a.name||"",onChange:e=>s("name",e.target.value),maxLength:500,disabled:r,placeholder:m("ap_plan_name_placeholder")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[h("responsibleWho")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("responsibleWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Responsável"}),e.jsxs(Ce,{value:a.responsibleId||"",onValueChange:e=>s("responsibleId",e),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_responsible")})}),e.jsx(De,{children:n.map(t=>e.jsx(_e,{value:t.id,children:t.name},t.id))})]})]}),h("checkerWho")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("checkerWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Verificador"}),e.jsxs(Ce,{value:a.checkerId||"",onValueChange:e=>s("checkerId",e),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_checker")})}),e.jsx(De,{children:n.map(t=>e.jsx(_e,{value:t.id,children:t.name},t.id))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[h("place")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("place")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Local"}),e.jsxs(Ce,{value:a.placeId||"",onValueChange:e=>s("placeId",e),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_place")})}),e.jsx(De,{children:We(i).map(t=>e.jsx(_e,{value:t.id,children:t.name},t.id))})]})]}),h("planType")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("planType")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Tipo de Ação"}),e.jsxs(Ce,{value:a.typeId||"",onValueChange:e=>s("typeId",e),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_type")})}),e.jsx(De,{children:p.map(t=>e.jsx(_e,{value:t.id,children:t.label},t.id))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[h("priority")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("priority")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Prioridade"}),e.jsxs(Ce,{value:a.priorityType?.toString()||"",onValueChange:e=>s("priorityType",Number(e)),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_priority")})}),e.jsx(De,{children:ue.map(t=>e.jsx(_e,{value:t.id.toString(),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:t.color}}),t.label]})},t.id))})]})]}),d.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:m("ap_belongs_to")}),e.jsxs(Ce,{value:a.parentId||"",onValueChange:e=>s("parentId",e),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_parent")})}),e.jsx(De,{children:d.map(t=>e.jsx(_e,{value:t.id,children:t.label},t.id))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[h("startDate")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("startDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Início"}),e.jsx(Le,{date:a.startDate?new Date(a.startDate):void 0,onDateChange:e=>s("startDate",e||null),disabled:r,placeholder:m("ap_select_date")})]}),h("endDate")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("endDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Término"}),e.jsx(Le,{date:a.endDate?new Date(a.endDate):void 0,onDateChange:e=>s("endDate",e||null),disabled:r,placeholder:m("ap_select_date"),disabledDates:a.startDate?e=>e<new Date(a.startDate):void 0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:m("ap_duration_days")}),e.jsx(je,{type:"number",value:g,disabled:!0,className:"bg-muted"})]})]}),h("estimatedCost")&&e.jsxs("div",{className:"space-y-2 max-w-xs",children:[e.jsx(we,{className:q(f("estimatedCost")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Custo Estimado"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"R$"}),e.jsx(je,{type:"number",min:0,step:.01,value:a.estimatedCost||"",onChange:e=>s("estimatedCost",Number(e.target.value)),disabled:r,className:"pl-9",placeholder:"0,00"})]})]}),h("cause")&&l.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:"Causa"}),e.jsxs(Ce,{value:a.causeId||"",onValueChange:e=>s("causeId",e),disabled:r,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:m("ap_select_cause")})}),e.jsx(De,{children:l.map(t=>e.jsx(_e,{value:t.id,children:t.label},t.id))})]})]}),h("description")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("description")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Descrição"}),e.jsx(ye,{value:a.description||"",onChange:e=>s("description",e.target.value),maxLength:4e3,disabled:r,rows:4,placeholder:m("ap_description_placeholder")})]}),h("justification")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:q(f("justification")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Justificativa"}),e.jsx(ye,{value:a.justification||"",onChange:e=>s("justification",e.target.value),maxLength:4e3,disabled:r,rows:4,placeholder:m("ap_justification_placeholder")})]})]})}function We(e,t=0){const a=[];for(const s of e)a.push({...s,depth:t}),s.children?.length&&a.push(...We(s.children,t+1));return a}ze.displayName=S.Content.displayName;const Fe=y.forwardRef(({className:t,value:a,...s},r)=>e.jsx(P.Root,{ref:r,className:q("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",t),...s,children:e.jsx(P.Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(a||0)}%)`}})}));Fe.displayName=P.Root.displayName;const qe=t.forwardRef(({className:t,children:a,variant:s="action",...r},n)=>e.jsx($,{ref:n,variant:s,size:"icon",className:q("h-8 w-8",t),...r,children:a||e.jsx(d.EllipsisVertical,{size:16})}));function Be(e){const{progress:a,onReportProgress:s,onEditProgress:r,onDeleteProgress:n}=e,[i,o]=t.useState(!1),[l,d]=t.useState(null),c=!!a&&xe.includes(a.status),m=t.useCallback(async e=>{if(s&&a){o(!0);try{const t=100===e.percentProgress;await s({id:a.id,...e,conclude:t})}finally{o(!1)}}},[s,a]),u=t.useCallback(async e=>{if(r){o(!0);try{await r(e)}finally{o(!1),d(null)}}},[r]),p=t.useCallback(async e=>{if(n){o(!0);try{await n(e)}finally{o(!1)}}},[n]);return{progress:a,canReportProgress:c,isSubmitting:i,editingReport:l,setEditingReport:d,reportProgress:m,editProgress:u,deleteProgress:p}}qe.displayName="ActionButton";const Oe=y.forwardRef(({className:t,orientation:a="horizontal",decorative:s=!0,...r},n)=>e.jsx(E.Root,{ref:n,decorative:s,orientation:a,className:q("shrink-0 bg-border","horizontal"===a?"h-[1px] w-full":"h-full w-[1px]",t),...r}));Oe.displayName=E.Root.displayName;const Ve=D.Root,He=D.Portal,Ue=y.forwardRef(({className:t,...a},s)=>e.jsx(D.Overlay,{className:q("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...a,ref:s}));Ue.displayName=D.Overlay.displayName;const $e=y.forwardRef(({className:t,...a},s)=>e.jsxs(He,{children:[e.jsx(Ue,{}),e.jsx(D.Content,{ref:s,className:q("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...a})]}));$e.displayName=D.Content.displayName;const Xe=({className:t,...a})=>e.jsx("div",{className:q("flex flex-col space-y-2 text-center sm:text-left",t),...a});Xe.displayName="AlertDialogHeader";const Ye=({className:t,...a})=>e.jsx("div",{className:q("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...a});Ye.displayName="AlertDialogFooter";const Ge=y.forwardRef(({className:t,...a},s)=>e.jsx(D.Title,{ref:s,className:q("text-lg font-semibold",t),...a}));Ge.displayName=D.Title.displayName;const Ke=y.forwardRef(({className:t,...a},s)=>e.jsx(D.Description,{ref:s,className:q("text-sm text-muted-foreground",t),...a}));Ke.displayName=D.Description.displayName;const Qe=y.forwardRef(({className:t,...a},s)=>e.jsx(D.Action,{ref:s,className:q(U(),t),...a}));Qe.displayName=D.Action.displayName;const Je=y.forwardRef(({className:t,...a},s)=>e.jsx(D.Cancel,{ref:s,className:q(U({variant:"outline"}),"mt-2 sm:mt-0",t),...a}));Je.displayName=D.Cancel.displayName;const Ze=T.Root,et=T.Portal,tt=y.forwardRef(({className:t,...a},s)=>e.jsx(T.Overlay,{ref:s,className:q("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...a}));tt.displayName=T.Overlay.displayName;const at={sm:{width:"30vw",minWidth:"320px",maxWidth:"480px",maxHeight:"320px"},md:{width:"50vw",minWidth:"480px",maxWidth:"720px",maxHeight:"70vh"},lg:{width:"85vw",height:"85vh",maxWidth:"1440px",minHeight:"480px",maxHeight:"900px"}},st=y.forwardRef(({className:t,children:a,size:s,variant:r="informative",isDirty:n,customWidth:i,customMinWidth:o,customMaxWidth:l,customHeight:m,customMinHeight:u,customMaxHeight:p,unsavedChangesTitle:x=c.t("unsaved_changes"),unsavedChangesDescription:h=c.t("unsaved_changes_description"),cancelText:f=c.t("cancel"),leaveWithoutSavingText:g=c.t("leave_without_saving"),style:v,onInteractOutside:b,onEscapeKeyDown:j,...N},w)=>{const[k,C]=y.useState(!1),S=y.useRef(null),P=y.useRef(!1),E=s??(i||o||l||m||u||p?void 0:"md"),D=E?at[E]:{},_={...i??D.width?{width:i??D.width}:{},...o??D.minWidth?{minWidth:o??D.minWidth}:{},...l??D.maxWidth?{maxWidth:l??D.maxWidth}:{},...m??D.height?{height:m??D.height}:{},...u??D.minHeight?{minHeight:u??D.minHeight}:{},...p??D.maxHeight?{maxHeight:p??D.maxHeight}:{},...v},R=y.useCallback(e=>{"form"===r&&n?(S.current=e,C(!0)):e()},[r,n]),A=y.useRef(null),I="destructive"!==r;if("development"===process.env.NODE_ENV&&a){const e=y.Children.toArray(a);e.some(e=>y.isValidElement(e)&&"DialogFooter"===e.type?.displayName),e.some(e=>y.isValidElement(e)&&"DialogBody"===e.type?.displayName)}return e.jsxs(et,{children:[e.jsx(tt,{}),e.jsxs(T.Content,{ref:w,className:q("fixed left-[50%] top-[50%] z-50 flex flex-col translate-x-[-50%] translate-y-[-50%] border-0 border-l-[10px] border-l-primary bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-lg max-sm:!w-[calc(100vw-2rem)] max-sm:!h-[calc(100dvh-2rem)] max-sm:!min-w-0 max-sm:!min-h-0 max-sm:!max-w-none max-sm:!max-h-none max-sm:p-4",t),style:_,onInteractOutside:e=>{"form"!==r&&"destructive"!==r?b?.(e):e.preventDefault()},onEscapeKeyDown:e=>{if("destructive"!==r)return"form"===r&&n?(e.preventDefault(),void R(()=>{P.current=!0,A.current?.click()})):void j?.(e);e.preventDefault()},...N,children:[a,I&&e.jsxs(T.Close,{ref:A,onClick:e=>{P.current?P.current=!1:"form"===r&&n&&(e.preventDefault(),R(()=>{P.current=!0,A.current?.click()}))},className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-0 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(d.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]}),e.jsx(Ve,{open:k,onOpenChange:C,children:e.jsxs($e,{children:[e.jsxs(Xe,{children:[e.jsx(Ge,{children:x}),e.jsx(Ke,{children:h})]}),e.jsxs(Ye,{children:[e.jsx(Je,{onClick:()=>{C(!1),S.current=null},children:f}),e.jsx(Qe,{onClick:()=>{C(!1),S.current?.(),S.current=null},children:g})]})]})})]})});st.displayName=T.Content.displayName;const rt=({className:t,showSeparator:a=!1,children:s,...r})=>e.jsxs("div",{className:q("flex flex-col flex-shrink-0",t),...r,children:[e.jsx("div",{className:"flex flex-col text-left",children:s}),a&&e.jsx(Oe,{className:"mt-2"})]});rt.displayName="DialogHeader";const nt=({className:t,children:a,...s})=>e.jsxs("div",{className:"flex-shrink-0 pt-4",children:[e.jsx(Oe,{className:"mb-4"}),e.jsx("div",{className:q("flex flex-row justify-end gap-2",t),...s,children:a})]});nt.displayName="DialogFooter";const it=y.forwardRef(({className:t,...a},s)=>e.jsx(T.Title,{ref:s,className:q("text-xl font-semibold leading-none tracking-tight",t),...a}));it.displayName=T.Title.displayName;function ot(e){if(!e)return"";let t=(e||"").trim();if(!t)return"00:00";if(t.includes(":")){const e=t.split(":");if(e.length>=2){const t=e[0].replace(/\D/g,""),a=e[1].replace(/\D/g,"");let s=parseInt(t)||0,r=parseInt(a)||0;return s+=Math.floor(r/60),r%=60,`${s.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}}if(t=t.replace(/\D/g,""),!t)return"00:00";let a=0,s=0;return 4===t.length?(a=parseInt(t.substring(0,2))||0,s=parseInt(t.substring(2,4))||0,a+=Math.floor(s/60),s%=60):(a=parseInt(t)||0,s=0),`${a.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}function lt(e){if(null==e)return"00:00";const t=String(e).replace(/\D/g,"");if(t.length<3){let e=parseInt(t)||0;const a=Math.floor(e/60);return e%=60,`${a.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}{const e=t.slice(-2),a=t.slice(0,-2);let s=parseInt(a)||0,r=parseInt(e)||0;return s+=Math.floor(r/60),r%=60,`${s.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}}function dt(e){return 100===e?"#84c148":e>0?"#1b75bb":""}function ct({open:a,onOpenChange:s,report:r,onSave:n,isSubmitting:i=!1}){const{t:o}=x.useTranslation(),[l,d]=t.useState(r?.percentProgress||0),[c,m]=t.useState(r?.timeProgress||""),[u,p]=t.useState(r?.comments||""),h=l!==(r?.percentProgress??0)||c!==(r?.timeProgress??"")||u!==(r?.comments??"");t.useEffect(()=>{r&&(d(r.percentProgress),m(r.timeProgress||""),p(r.comments||""))},[r]);return e.jsx(Ze,{open:a,onOpenChange:s,children:e.jsxs(st,{className:"sm:max-w-md",variant:"form",isDirty:h,children:[e.jsx(rt,{children:e.jsx(it,{children:o("ap_edit_progress")})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:o("ap_progress_percent")}),e.jsx(je,{type:"number",min:0,max:100,value:l,onChange:e=>d(Number(e.target.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:o("ap_time_spent")}),e.jsx(je,{value:c,onChange:e=>m(e.target.value),onBlur:()=>m(ot(c)||""),placeholder:"00:00"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:o("ap_comments")}),e.jsx(ye,{value:u,onChange:e=>p(e.target.value),rows:3,maxLength:4e3})]})]}),e.jsxs(nt,{children:[e.jsx($,{variant:"outline",onClick:()=>s(!1),disabled:i,children:"Cancelar"}),e.jsx($,{onClick:()=>{r&&n({...r,percentProgress:l,timeProgress:ot(c)||"00:00",comments:u})},disabled:i,children:i?"Salvando...":"Salvar"})]})]})})}function mt(a){const{t:s}=x.useTranslation(),{progress:r,canReportProgress:n,isSubmitting:i,editingReport:o,setEditingReport:l,reportProgress:d,editProgress:c,deleteProgress:m}=Be(a),[u,p]=t.useState(""),[h,f]=t.useState(""),[g,v]=t.useState("");if(!r)return e.jsx("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Sem dados de progresso disponíveis"});const b=dt(r.percentProgress),j=!u,y=!u&&!h&&!g;return e.jsxs("div",{className:"space-y-6 p-1",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium",children:s("ap_overall_progress")}),e.jsxs("span",{className:"font-semibold",style:{color:b||void 0},children:[r.percentProgress,"%"]})]}),e.jsx(Fe,{value:r.percentProgress,className:"h-3"}),r.timeProgress&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Tempo total: ",lt(r.timeProgress)]})]}),n&&e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[e.jsx("h4",{className:"text-sm font-medium",children:s("ap_report_progress")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:s("ap_progress_percent")}),e.jsx(je,{type:"number",min:0,max:100,value:u,onChange:e=>p(e.target.value),placeholder:"0"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:s("ap_time_spent")}),e.jsx(je,{value:h,onChange:e=>f(e.target.value),onBlur:()=>f(ot(h)||""),placeholder:"00:00"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:s("ap_comments")}),e.jsx(ye,{value:g,onChange:e=>v(e.target.value),rows:3,maxLength:4e3,placeholder:s("ap_progress_comment_placeholder")})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx($,{variant:"outline",size:"sm",onClick:()=>{p(""),f(""),v("")},disabled:y||i,children:"Limpar"}),e.jsx($,{size:"sm",onClick:async()=>{const e=Number(u);(e||0===e)&&(await d({percentProgress:e,timeProgress:ot(h)||"00:00",comments:g}),p(""),f(""),v(""))},disabled:j||i,children:i?"Reportando...":"Reportar"})]})]}),r.reports.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium",children:s("ap_reports_history")}),e.jsx("div",{className:"space-y-2",children:r.reports.map(t=>e.jsx(ut,{report:t,onEdit:()=>l(t),onDelete:()=>m(t.id),disabled:!n},t.id))})]}),e.jsx(ct,{open:!!o,onOpenChange:e=>!e&&l(null),report:o,onSave:c,isSubmitting:i})]})}function ut({report:t,onEdit:a,onDelete:s,disabled:r}){const n=t.date?new Date(t.date):null,i=dt(t.percentProgress);return e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-card p-3",children:[e.jsx("div",{className:"flex-shrink-0 h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground",children:t.userName?.charAt(0)?.toUpperCase()||"?"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"font-medium truncate",children:t.userName}),n&&e.jsx("span",{className:"text-xs text-muted-foreground",children:n.toLocaleDateString("pt-BR")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{style:{color:i||void 0},className:"font-semibold",children:[t.percentProgress,"%"]}),t.timeProgress&&e.jsxs("span",{children:["Tempo: ",lt(t.timeProgress)]})]}),t.comments&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.comments})]}),!r&&e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx(qe,{})}),e.jsxs(G,{align:"end",children:[e.jsx(K,{onClick:a,children:c.t("edit")}),e.jsx(K,{className:"text-destructive",onClick:s,children:c.t("ap_delete")})]})]})]})}function pt({predecessors:a=[],availablePredecessors:s=[],onAdd:r,onRemove:n,disabled:i=!1}){const{t:o}=x.useTranslation(),[l,c]=t.useState(""),m=s.filter(e=>!a.some(t=>t.predecessorId===e.id));return e.jsxs("div",{className:"space-y-6 p-1",children:[!i&&m.length>0&&e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(we,{children:o("ap_add_predecessor")}),e.jsxs(Ce,{value:l,onValueChange:c,children:[e.jsx(Pe,{children:e.jsx(Se,{placeholder:o("ap_select_action")})}),e.jsx(De,{children:m.map(t=>e.jsx(_e,{value:t.id,children:t.label},t.id))})]})]}),e.jsxs($,{size:"sm",onClick:()=>{l&&r&&(r(l),c(""))},disabled:!l,children:[e.jsx(d.Plus,{className:"h-4 w-4 mr-1"}),"Adicionar"]})]}),a.length>0?e.jsx("div",{className:"space-y-2",children:a.map(t=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.predecessorCode&&e.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:t.predecessorCode}),e.jsx("span",{className:"text-sm font-medium",children:t.predecessorName}),null!=t.predecessorStatus&&e.jsx(be,{status:t.predecessorStatus})]}),!i&&n&&e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx(qe,{})}),e.jsx(G,{align:"end",children:e.jsx(K,{className:"text-destructive",onClick:()=>n(t.predecessorId),children:"Remover"})})]})]},t.id))}):e.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum predecessor adicionado"})]})}function xt({costs:a=[],onAdd:s,onEdit:r,onDelete:n,disabled:i=!1}){const{t:o}=x.useTranslation(),[l,c]=t.useState(""),[m,u]=t.useState(""),p=a.reduce((e,t)=>e+(t.value||0),0);return e.jsxs("div",{className:"space-y-6 p-1",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:o("ap_total_cost")}),e.jsxs("span",{className:"text-lg font-semibold text-foreground",children:["R$ ",p.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),!i&&s&&e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[e.jsx("h4",{className:"text-sm font-medium",children:o("ap_add_cost")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:"Descrição"}),e.jsx(je,{value:l,onChange:e=>c(e.target.value),placeholder:o("ap_cost_description")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{children:"Valor (R$)"}),e.jsx(je,{type:"number",min:0,step:.01,value:m,onChange:e=>u(e.target.value),placeholder:"0,00"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs($,{size:"sm",onClick:()=>{l&&m&&s&&(s({description:l,value:Number(m),date:(new Date).toISOString()}),c(""),u(""))},disabled:!l||!m,children:[e.jsx(d.Plus,{className:"h-4 w-4 mr-1"}),"Adicionar"]})})]}),a.length>0?e.jsx("div",{className:"space-y-2",children:a.map(t=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:t.description}),t.date&&e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(t.date).toLocaleDateString("pt-BR")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm font-semibold whitespace-nowrap",children:["R$ ",t.value.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]}),!i&&(r||n)&&e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx(qe,{})}),e.jsxs(G,{align:"end",children:[r&&e.jsx(K,{onClick:()=>r(t),children:o("edit")}),n&&e.jsx(K,{className:"text-destructive",onClick:()=>n(t.id),children:o("ap_delete")})]})]})]})]},t.id))}):e.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum custo registrado"})]})}y.forwardRef(({className:t,...a},s)=>e.jsx(T.Description,{ref:s,className:q("text-sm text-muted-foreground",t),...a})).displayName=T.Description.displayName;const ht=o.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",danger:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground",success:"border-transparent bg-success text-success-foreground hover:bg-success/90",warning:"border-transparent bg-warning text-warning-foreground hover:bg-warning/90",info:"border-transparent bg-primary/10 text-primary hover:bg-primary/20",sharp:"border-transparent bg-[hsl(78,70%,46%)] text-foreground hover:bg-[hsl(78,70%,40%)]"}},defaultVariants:{variant:"default"}}),ft=y.forwardRef(({className:t,variant:a,...s},r)=>e.jsx("div",{ref:r,className:q(ht({variant:a}),t),...s}));function gt({comments:a=[],currentUserId:s,onAdd:r,onEdit:n,onDelete:i,disabled:o=!1,maxLength:l=4e3}){const{t:c}=x.useTranslation(),[m,u]=t.useState(""),[p,h]=t.useState(!1),[f,g]=t.useState(null),[v,b]=t.useState(""),j=()=>{g(null),b("")};return e.jsxs("div",{className:"space-y-6 p-1",children:[!o&&r&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(ye,{value:m,onChange:e=>u(e.target.value),placeholder:c("ap_add_comment_placeholder"),maxLength:l,rows:3}),e.jsxs("div",{className:"flex items-center justify-between",children:[l&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[m.length,"/",l]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsx($,{variant:"outline",size:"sm",onClick:()=>u(""),disabled:!m||p,children:"Limpar"}),e.jsx($,{size:"sm",onClick:async()=>{if(m.trim()&&r){h(!0);try{await r(m),u("")}finally{h(!1)}}},disabled:!m.trim()||p,children:p?"Enviando...":"Comentar"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[a.length>0?e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"text-sm font-medium",children:c("ap_comments")}),e.jsx(ft,{variant:"info",className:"text-[10px] px-1.5 py-0",children:a.length})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(d.MessageSquare,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"Nenhum comentário adicionado"})]}),a.map(t=>e.jsxs("div",{className:"flex gap-3 rounded-lg border bg-card p-3",children:[e.jsx("div",{className:"flex-shrink-0 h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground overflow-hidden",children:t.userPhotoUrl?e.jsx("img",{src:t.userPhotoUrl,alt:t.userName,className:"h-full w-full object-cover"}):t.userName?.charAt(0)?.toUpperCase()||"?"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"font-medium truncate",children:t.userName}),t.userEmail&&e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:t.userEmail}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:vt(t.dateEdited||t.dateCreation)}),t.dateEdited&&e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"editado"})]}),f===t.id?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ye,{value:v,onChange:e=>b(e.target.value),maxLength:l,rows:3}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx($,{variant:"outline",size:"sm",onClick:j,disabled:p,children:"Cancelar"}),e.jsx($,{size:"sm",onClick:()=>(async e=>{if(v.trim()&&n){h(!0);try{await n({...e,text:v,stringText:v}),g(null),b("")}finally{h(!1)}}})(t),disabled:!v.trim()||p,children:p?"Salvando...":"Salvar"})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.stringText||t.text})]}),!o&&s===t.userId&&f!==t.id&&e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx(qe,{})}),e.jsxs(G,{align:"end",children:[n&&e.jsx(K,{onClick:()=>(e=>{g(e.id),b(e.stringText||e.text)})(t),children:c("edit")}),i&&e.jsx(K,{className:"text-destructive",onClick:()=>(async e=>{if(i){h(!0);try{await i(e)}finally{h(!1)}}})(t.id),children:"Excluir"})]})]})]},t.id))]})]})}function vt(e){const{t:t}=x.useTranslation();if(!e)return"";const a=new Date(e);return`${a.toLocaleDateString("pt-BR")} ${a.toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}`}function bt({history:t=[],isLoading:a=!1}){const{t:s}=x.useTranslation();return a?e.jsx("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Carregando histórico..."}):0===t.length?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(d.Clock,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:s("ap_no_history")})]}):e.jsx("div",{className:"p-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-4 top-0 bottom-0 w-px bg-border"}),e.jsx("div",{className:"space-y-0",children:t.map((t,a)=>e.jsxs("div",{className:"relative flex gap-4 pb-6 last:pb-0",children:[e.jsx("div",{className:"relative z-10 flex-shrink-0 h-8 w-8 rounded-full bg-primary/10 border-2 border-primary/30 flex items-center justify-center",children:t.icon?e.jsx("span",{className:"text-xs text-primary",children:t.icon}):e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0 rounded-lg border bg-card p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t.translateEvent||t.eventName}),t.eventDescription&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.eventDescription})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-shrink-0 h-6 w-6 rounded-full bg-muted overflow-hidden flex items-center justify-center text-[10px] font-medium text-muted-foreground",children:t.userPhotoUrl?e.jsx("img",{src:t.userPhotoUrl,alt:t.userName,className:"h-full w-full object-cover"}):t.userName?.charAt(0)?.toUpperCase()||"?"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-medium truncate block",children:t.userName}),t.userEmail&&e.jsx("span",{className:"text-[10px] text-muted-foreground truncate block",children:t.userEmail})]})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(d.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:jt(t.date)})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(d.Clock,{className:"h-3 w-3"}),e.jsx("span",{children:yt(t.date)})]}),t.isMobileRequest&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(d.Smartphone,{className:"h-3 w-3"}),e.jsx("span",{children:s("ap_via_app")})]})]})]})]},t.id))})]})})}function jt(e){const{t:t}=x.useTranslation();return new Date(e).toLocaleDateString("pt-BR")}function yt(e){const{t:t}=x.useTranslation();return new Date(e).toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}function Nt({attachments:a=[],onUpload:s,onDelete:r,onRename:n,onDownload:i,onView:o,disabled:l=!1}){const{t:c}=x.useTranslation(),m=t.useRef(null),[u,p]=t.useState(null),[h,f]=t.useState(""),g=async e=>{h.trim()&&n&&(await n(e.id,h),p(null),f(""))},v=()=>{p(null),f("")};return e.jsxs("div",{className:"space-y-4 p-1",children:[!l&&s&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:m,type:"file",multiple:!0,className:"hidden",onChange:e=>{const t=e.target.files;if(t&&s){for(let e=0;e<t.length;e++){const a=t.item(e);a&&s(a)}m.current&&(m.current.value="")}}}),e.jsxs($,{size:"sm",onClick:()=>m.current?.click(),children:[e.jsx(d.Plus,{className:"h-4 w-4 mr-1"}),"Adicionar anexo"]})]}),a.length>0?e.jsx("div",{className:"space-y-2",children:a.map(t=>e.jsxs("div",{className:q("flex items-center gap-3 rounded-lg border bg-card p-3",t.status===exports.EAttachmentItemStatus.error&&"border-destructive/50 bg-destructive/5",t.status===exports.EAttachmentItemStatus.canceled&&"opacity-50"),children:[e.jsx("div",{className:"flex-shrink-0 h-9 w-9 rounded bg-muted flex items-center justify-center",children:e.jsx("span",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:t.extension.replace(".","").substring(0,4)})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[u===t.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"flex-1 text-sm border rounded px-2 py-1 bg-background",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&g(t),"Escape"===e.key&&v()},autoFocus:!0}),e.jsx($,{size:"sm",variant:"outline",onClick:v,children:c("cancel")}),e.jsx($,{size:"sm",onClick:()=>g(t),children:c("save")})]}):e.jsx("button",{type:"button",className:"text-sm font-medium truncate block text-left hover:underline cursor-pointer",onClick:()=>o?.(t.id),children:t.name}),(t.status===exports.EAttachmentItemStatus.uploading||t.status===exports.EAttachmentItemStatus.waiting)&&e.jsx(Fe,{value:t.progress||0,className:"h-1.5"}),t.status===exports.EAttachmentItemStatus.error&&e.jsx("p",{className:"text-xs text-destructive",children:"Erro ao enviar arquivo"}),t.status===exports.EAttachmentItemStatus.duplicateItem&&e.jsx("p",{className:"text-xs text-warning",children:"Arquivo duplicado"}),t.status===exports.EAttachmentItemStatus.canceled&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload cancelado"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.status===exports.EAttachmentItemStatus.done&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:wt(t.size)}),e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx(qe,{})}),e.jsxs(G,{align:"end",children:[n&&!l&&e.jsx(K,{onClick:()=>(e=>{const t=e.name.replace(e.extension,"");p(e.id),f(t)})(t),children:"Renomear"}),o&&e.jsx(K,{onClick:()=>o(t.id),children:"Visualizar"}),i&&e.jsx(K,{onClick:()=>i(t.id),children:"Download"}),r&&!l&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{}),e.jsx(K,{className:"text-destructive",onClick:()=>r(t.id),children:"Excluir"})]})]})]})]}),t.status===exports.EAttachmentItemStatus.uploading&&e.jsx($,{variant:"outline",size:"sm",onClick:()=>r?.(t.id),children:"Cancelar"})]})]},t.id))}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(d.Paperclip,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"Nenhum anexo adicionado"})]})]})}function wt(e){const{t:t}=x.useTranslation();if(0===e)return"0 B";const a=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,a)).toFixed(1))} ${["B","KB","MB","GB"][a]}`}ft.displayName="Badge",exports.ActionPlanAttachmentsTab=Nt,exports.ActionPlanCommentsTab=gt,exports.ActionPlanCostTab=xt,exports.ActionPlanGeneralTab=Me,exports.ActionPlanHistoryTab=bt,exports.ActionPlanPage=function(t){const{formData:a,isLoading:s,isSaving:r,activeTab:n,isFormDisabled:i,updateField:o,setActiveTab:l,save:c,changeStatus:m,remove:u,cancel:p}=he(t),{t:h}=x.useTranslation(),{isNew:f=!1,config:g,users:v,places:b,actionTypes:j,causes:y,parentActions:N,progress:w,predecessors:k,availablePredecessors:C,costs:S,comments:P,history:T,attachments:E,attachmentsSlot:D,commentsSlot:_,historySlot:R,onAddPredecessor:A,onRemovePredecessor:I,onAddCost:z,onEditCost:L,onDeleteCost:M,onAddComment:W,onEditComment:F,onDeleteComment:q,onUploadAttachment:U,onDeleteAttachment:Q,onRenameAttachment:J,onDownloadAttachment:Z,onViewAttachment:te}=t;if(s&&!a.id)return e.jsx(ee,{isLoading:!0,children:e.jsx("div",{})});const ae=function(e){const{t:t}=x.useTranslation();if(!e)return[];return{[exports.ETaskPlanStatus.waitingStart]:[exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.suspended,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.running]:[exports.ETaskPlanStatus.effectivenessCheck,exports.ETaskPlanStatus.done,exports.ETaskPlanStatus.suspended,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.effectivenessCheck]:[exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.done,exports.ETaskPlanStatus.suspended,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.done]:[exports.ETaskPlanStatus.running],[exports.ETaskPlanStatus.suspended]:[exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.canceled]:[exports.ETaskPlanStatus.waitingStart]}[e]||[]}(a.statusId);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between border-b bg-card px-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[p&&e.jsx($,{variant:"ghost",size:"icon",onClick:p,children:e.jsx(d.ArrowLeft,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-lg font-semibold",children:f?h("ap_new_action"):a.name||h("ap_action_plan")}),!f&&a.statusId&&e.jsx(be,{status:a.statusId})]}),a.code&&e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:a.code})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!f&&ae.length>0&&!i&&e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx($,{variant:"outline",size:"sm",children:"Alterar Status"})}),e.jsx(G,{align:"end",children:ae.map(t=>e.jsx(K,{onClick:()=>m(t),children:ce[t]},t))})]}),!f&&t.onDelete&&e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx($,{variant:"ghost",size:"icon",children:e.jsx(d.MoreVertical,{className:"h-4 w-4"})})}),e.jsx(G,{align:"end",children:e.jsx(K,{className:"text-destructive",onClick:u,children:"Excluir"})})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:e.jsx("div",{className:"max-w-4xl mx-auto px-6 py-6",children:e.jsxs(B,{value:n,onValueChange:l,children:[e.jsxs(O,{className:"mb-6",children:[e.jsx(V,{value:"general",children:"Geral"}),!f&&e.jsx(V,{value:"progress",children:"Progresso"}),!f&&g?.enablePredecessors&&e.jsx(V,{value:"predecessors",children:h("ap_predecessors")}),!f&&g?.enableCosts&&e.jsx(V,{value:"costs",children:"Custos"}),!f&&g?.enableAttachments&&e.jsx(V,{value:"attachments",children:h("ap_attachments")}),!f&&g?.enableComments&&e.jsx(V,{value:"comments",children:h("ap_comments")}),!f&&g?.enableHistory&&e.jsx(V,{value:"history",children:"Histórico"})]}),e.jsx(H,{value:"general",children:e.jsx(Me,{formData:a,updateField:o,disabled:i,users:v,places:b,actionTypes:j,causes:y,parentActions:N,config:g})}),!f&&e.jsx(H,{value:"progress",children:e.jsx(mt,{...t})}),!f&&g?.enablePredecessors&&e.jsx(H,{value:"predecessors",children:e.jsx(pt,{predecessors:k,availablePredecessors:C,onAdd:A,onRemove:I,disabled:i})}),!f&&g?.enableCosts&&e.jsx(H,{value:"costs",children:e.jsx(xt,{costs:S,onAdd:z,onEdit:L,onDelete:M,disabled:i})}),!f&&g?.enableAttachments&&e.jsx(H,{value:"attachments",children:D||e.jsx(Nt,{attachments:E,onUpload:U,onDelete:Q,onRename:J,onDownload:Z,onView:te,disabled:i})}),!f&&g?.enableComments&&e.jsx(H,{value:"comments",children:_||e.jsx(gt,{comments:P,onAdd:W,onEdit:F,onDelete:q,disabled:i})}),!f&&g?.enableHistory&&e.jsx(H,{value:"history",children:R||e.jsx(bt,{history:T})})]})})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 border-t bg-card px-6 py-4",children:[p&&e.jsx($,{variant:"outline",onClick:p,disabled:r,children:"Cancelar"}),e.jsx($,{onClick:c,disabled:r||i,children:r?"Salvando...":"Salvar"})]})]})},exports.ActionPlanPredecessorsTab=pt,exports.ActionPlanProgressDialog=ct,exports.ActionPlanProgressTab=mt,exports.ActionPlanStatusBadge=be,exports.CLOSED_STATUSES=pe,exports.DEFAULT_ACTION_TYPES=me,exports.PRIORITIES=ue,exports.PROGRESS_ALLOWED_STATUSES=xe,exports.STATUS_COLORS=ie,exports.STATUS_LABELS=ce,exports.STATUS_MAP=le,exports.STATUS_TEXT_COLORS=oe,exports.formatTime=lt,exports.formatTimeProgress=ot,exports.getActionTypes=function(){return[{id:"immediate",label:c.t("ap_type_immediate")},{id:"corrective",label:c.t("ap_type_corrective")},{id:"preventive",label:c.t("ap_type_preventive")},{id:"improvement",label:c.t("ap_type_improvement")},{id:"standardization",label:c.t("ap_type_standardization")}]},exports.getPriorities=function(){return[{id:exports.ETaskPlanPriority.low,label:c.t("ap_priority_low"),color:"#4CAF50"},{id:exports.ETaskPlanPriority.medium,label:c.t("ap_priority_medium"),color:"#FF9800"},{id:exports.ETaskPlanPriority.high,label:c.t("ap_priority_high"),color:"#F44336"}]},exports.getProgressColor=dt,exports.getStatusLabels=de,exports.useActionPlan=he,exports.useActionPlanProgress=Be;
1
+ "use strict";var e,s,t,a,n,r=require("react/jsx-runtime"),i=require("forlogic-core"),l=require("lucide-react"),c=require("i18next"),o=require("react"),d=require("react-i18next");exports.ETaskPlanStatus=void 0,(e=exports.ETaskPlanStatus||(exports.ETaskPlanStatus={}))[e.waitingStart=1]="waitingStart",e[e.running=2]="running",e[e.effectivenessCheck=3]="effectivenessCheck",e[e.done=4]="done",e[e.suspended=5]="suspended",e[e.canceled=6]="canceled",exports.ETaskPlanPriority=void 0,(s=exports.ETaskPlanPriority||(exports.ETaskPlanPriority={}))[s.low=0]="low",s[s.medium=1]="medium",s[s.high=2]="high",exports.ETaskPlanAssociationType=void 0,(t=exports.ETaskPlanAssociationType||(exports.ETaskPlanAssociationType={}))[t.plan=2]="plan",t[t.occurrence=3]="occurrence",t[t.risk=4]="risk",t[t.decisions=5]="decisions",t[t.audit=6]="audit",t[t.strategyExtension=7]="strategyExtension",t[t.standardization=8]="standardization",t[t.supplier=9]="supplier",t[t.auditItems=10]="auditItems",exports.ETaskPlanTypeProgress=void 0,(a=exports.ETaskPlanTypeProgress||(exports.ETaskPlanTypeProgress={}))[a.currentProgress=1]="currentProgress",a[a.cumulativeProgress=2]="cumulativeProgress",exports.EAttachmentItemStatus=void 0,(n=exports.EAttachmentItemStatus||(exports.EAttachmentItemStatus={})).uploading="uploading",n.waiting="waiting",n.done="done",n.error="error",n.canceled="canceled",n.duplicateItem="duplicateItem";const u={[exports.ETaskPlanStatus.waitingStart]:"#D6D6D6",[exports.ETaskPlanStatus.running]:"#DAE9F4",[exports.ETaskPlanStatus.effectivenessCheck]:"#1B75BB29",[exports.ETaskPlanStatus.done]:"#DDEECA",[exports.ETaskPlanStatus.suspended]:"#FFF2D6",[exports.ETaskPlanStatus.canceled]:"#F4433629"},x={[exports.ETaskPlanStatus.waitingStart]:"#666666",[exports.ETaskPlanStatus.running]:"#1B75BB",[exports.ETaskPlanStatus.effectivenessCheck]:"#1B75BB",[exports.ETaskPlanStatus.done]:"#4CAF50",[exports.ETaskPlanStatus.suspended]:"#FF9800",[exports.ETaskPlanStatus.canceled]:"#F44336"},m={[exports.ETaskPlanStatus.waitingStart]:"waiting-start",[exports.ETaskPlanStatus.running]:"running",[exports.ETaskPlanStatus.effectivenessCheck]:"effectiveness-check",[exports.ETaskPlanStatus.done]:"done",[exports.ETaskPlanStatus.suspended]:"suspended",[exports.ETaskPlanStatus.canceled]:"canceled"};function p(){return{[exports.ETaskPlanStatus.waitingStart]:c.t("ap_status_waiting_start"),[exports.ETaskPlanStatus.running]:c.t("ap_status_running"),[exports.ETaskPlanStatus.effectivenessCheck]:c.t("ap_status_effectiveness_check"),[exports.ETaskPlanStatus.done]:c.t("ap_status_done"),[exports.ETaskPlanStatus.suspended]:c.t("ap_status_suspended"),[exports.ETaskPlanStatus.canceled]:c.t("ap_status_canceled")}}const h=new Proxy({},{get:(e,s)=>{if("symbol"==typeof s)return;return p()[s]}});const g=[{id:"immediate",label:"Imediata"},{id:"corrective",label:"Corretiva"},{id:"preventive",label:"Preventiva"},{id:"improvement",label:"Oportunidade de Melhoria"},{id:"standardization",label:"Padronização"}];const j=[{id:exports.ETaskPlanPriority.low,label:"Baixa",color:"#4CAF50"},{id:exports.ETaskPlanPriority.medium,label:"Média",color:"#FF9800"},{id:exports.ETaskPlanPriority.high,label:"Alta",color:"#F44336"}],f=[exports.ETaskPlanStatus.done,exports.ETaskPlanStatus.canceled],v=[exports.ETaskPlanStatus.waitingStart,exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.effectivenessCheck,exports.ETaskPlanStatus.suspended];function b(e){const{actionPlan:s,isNew:t=!1,config:a,onSave:n,onCancel:r,onDelete:i,onChangeStatus:l}=e,[c,d]=o.useState({formData:s||{},isLoading:e.isLoading||!1,isSaving:!1,activeTab:"general",isFormDisabled:!1});o.useEffect(()=>{s&&d(e=>({...e,formData:s,isFormDisabled:a?.disableFields||f.includes(s.statusId)}))},[s,a?.disableFields]),o.useEffect(()=>{d(s=>({...s,isLoading:e.isLoading||!1}))},[e.isLoading]);const u=o.useCallback((e,s)=>{d(t=>({...t,formData:{...t.formData,[e]:s}}))},[]),x=o.useCallback(e=>{d(s=>({...s,activeTab:e}))},[]),m=o.useCallback(async()=>{if(n){d(e=>({...e,isSaving:!0}));try{await n(c.formData)}finally{d(e=>({...e,isSaving:!1}))}}},[n,c.formData]),p=o.useCallback(async e=>{if(l&&c.formData.id){d(e=>({...e,isLoading:!0}));try{await l(c.formData.id,e)}finally{d(e=>({...e,isLoading:!1}))}}},[l,c.formData.id]),h=o.useCallback(async()=>{if(i&&c.formData.id){d(e=>({...e,isLoading:!0}));try{await i(c.formData.id)}finally{d(e=>({...e,isLoading:!1}))}}},[i,c.formData.id]);return{formData:c.formData,isLoading:c.isLoading,isSaving:c.isSaving,activeTab:c.activeTab,isFormDisabled:c.isFormDisabled,updateField:u,setActiveTab:x,save:m,changeStatus:p,remove:h,cancel:r}}const S={[exports.ETaskPlanStatus.waitingStart]:{label:"",color:"#8B7355",icon:l.Clock},[exports.ETaskPlanStatus.running]:{label:"",color:"#2E7D5B",icon:l.Play},[exports.ETaskPlanStatus.effectivenessCheck]:{label:"",color:"#4A6FA5",icon:l.ShieldCheck},[exports.ETaskPlanStatus.done]:{label:"",color:"#3D7A40",icon:l.CheckCircle2},[exports.ETaskPlanStatus.suspended]:{label:"",color:"#6B7280",icon:l.Pause},[exports.ETaskPlanStatus.canceled]:{label:"",color:"#B44A4A",icon:l.X}};function N({status:e,labels:s,className:t,size:a,showIcon:n,variant:l}){const c=p(),o=S[e];if(!o)return null;const d=s?.[e]||c[e]||"";return r.jsx(i.StatusBadge,{label:d,color:o.color,icon:o.icon,size:a,showIcon:n,variant:l,className:t})}function T({formData:e,updateField:s,disabled:t=!1,users:a=[],places:n=[],actionTypes:l,causes:c=[],parentActions:u=[],config:x}){const{t:m}=d.useTranslation(),p=x?.requiredFields,h=l||g,f=e=>{if(x?.hiddenFields?.includes(e))return!1;if(x?.visibleFields&&x.visibleFields.length>0)return x.visibleFields.includes(e);const s=`${e}Visible`;return!p||!(s in p)||!1!==p[s]},v=e=>p?!!p[e]:"name"===e,b=o.useMemo(()=>{if(e.startDate&&e.endDate){const s=new Date(e.startDate),t=new Date(e.endDate).getTime()-s.getTime();return Math.max(0,Math.ceil(t/864e5))}return e.duration||0},[e.startDate,e.endDate,e.duration]);return r.jsxs("div",{className:"space-y-6 p-1",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("name")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Nome"}),r.jsx(i.Input,{value:e.name||"",onChange:e=>s("name",e.target.value),maxLength:500,disabled:t,placeholder:m("ap_plan_name_placeholder")})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("responsibleWho")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("responsibleWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Responsável"}),r.jsxs(i.Select,{value:e.responsibleId||"",onValueChange:e=>s("responsibleId",e),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_responsible")})}),r.jsx(i.SelectContent,{children:a.map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.name},e.id))})]})]}),f("checkerWho")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("checkerWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Verificador"}),r.jsxs(i.Select,{value:e.checkerId||"",onValueChange:e=>s("checkerId",e),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_checker")})}),r.jsx(i.SelectContent,{children:a.map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.name},e.id))})]})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("place")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("place")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Local"}),r.jsxs(i.Select,{value:e.placeId||"",onValueChange:e=>s("placeId",e),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_place")})}),r.jsx(i.SelectContent,{children:y(n).map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.name},e.id))})]})]}),f("planType")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("planType")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Tipo de Ação"}),r.jsxs(i.Select,{value:e.typeId||"",onValueChange:e=>s("typeId",e),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_type")})}),r.jsx(i.SelectContent,{children:h.map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.label},e.id))})]})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("priority")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("priority")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Prioridade"}),r.jsxs(i.Select,{value:e.priorityType?.toString()||"",onValueChange:e=>s("priorityType",Number(e)),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_priority")})}),r.jsx(i.SelectContent,{children:j.map(e=>r.jsx(i.SelectItem,{value:e.id.toString(),children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})},e.id))})]})]}),u.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:m("ap_belongs_to")}),r.jsxs(i.Select,{value:e.parentId||"",onValueChange:e=>s("parentId",e),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_parent")})}),r.jsx(i.SelectContent,{children:u.map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.label},e.id))})]})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[f("startDate")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("startDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Início"}),r.jsx(i.DatePicker,{date:e.startDate?new Date(e.startDate):void 0,onDateChange:e=>s("startDate",e||null),disabled:t,placeholder:m("ap_select_date")})]}),f("endDate")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("endDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Término"}),r.jsx(i.DatePicker,{date:e.endDate?new Date(e.endDate):void 0,onDateChange:e=>s("endDate",e||null),disabled:t,placeholder:m("ap_select_date"),disabledDates:e.startDate?s=>s<new Date(e.startDate):void 0})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:m("ap_duration_days")}),r.jsx(i.Input,{type:"number",value:b,disabled:!0,className:"bg-muted"})]})]}),f("estimatedCost")&&r.jsxs("div",{className:"space-y-2 max-w-xs",children:[r.jsx(i.Label,{className:i.cn(v("estimatedCost")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Custo Estimado"}),r.jsxs("div",{className:"relative",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"R$"}),r.jsx(i.Input,{type:"number",min:0,step:.01,value:e.estimatedCost||"",onChange:e=>s("estimatedCost",Number(e.target.value)),disabled:t,className:"pl-9",placeholder:"0,00"})]})]}),f("cause")&&c.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:"Causa"}),r.jsxs(i.Select,{value:e.causeId||"",onValueChange:e=>s("causeId",e),disabled:t,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:m("ap_select_cause")})}),r.jsx(i.SelectContent,{children:c.map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.label},e.id))})]})]}),f("description")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("description")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Descrição"}),r.jsx(i.Textarea,{value:e.description||"",onChange:e=>s("description",e.target.value),maxLength:4e3,disabled:t,rows:4,placeholder:m("ap_description_placeholder")})]}),f("justification")&&r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{className:i.cn(v("justification")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Justificativa"}),r.jsx(i.Textarea,{value:e.justification||"",onChange:e=>s("justification",e.target.value),maxLength:4e3,disabled:t,rows:4,placeholder:m("ap_justification_placeholder")})]})]})}function y(e,s=0){const t=[];for(const a of e)t.push({...a,depth:s}),a.children?.length&&t.push(...y(a.children,s+1));return t}function P(e){const{progress:s,onReportProgress:t,onEditProgress:a,onDeleteProgress:n}=e,[r,i]=o.useState(!1),[l,c]=o.useState(null),d=!!s&&v.includes(s.status),u=o.useCallback(async e=>{if(t&&s){i(!0);try{const a=100===e.percentProgress;await t({id:s.id,...e,conclude:a})}finally{i(!1)}}},[t,s]),x=o.useCallback(async e=>{if(a){i(!0);try{await a(e)}finally{i(!1),c(null)}}},[a]),m=o.useCallback(async e=>{if(n){i(!0);try{await n(e)}finally{i(!1)}}},[n]);return{progress:s,canReportProgress:d,isSubmitting:r,editingReport:l,setEditingReport:c,reportProgress:u,editProgress:x,deleteProgress:m}}function C(e){if(!e)return"";let s=(e||"").trim();if(!s)return"00:00";if(s.includes(":")){const e=s.split(":");if(e.length>=2){const s=e[0].replace(/\D/g,""),t=e[1].replace(/\D/g,"");let a=parseInt(s)||0,n=parseInt(t)||0;return a+=Math.floor(n/60),n%=60,`${a.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}}if(s=s.replace(/\D/g,""),!s)return"00:00";let t=0,a=0;return 4===s.length?(t=parseInt(s.substring(0,2))||0,a=parseInt(s.substring(2,4))||0,t+=Math.floor(a/60),a%=60):(t=parseInt(s)||0,a=0),`${t.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function k(e){if(null==e)return"00:00";const s=String(e).replace(/\D/g,"");if(s.length<3){let e=parseInt(s)||0;const t=Math.floor(e/60);return e%=60,`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}{const e=s.slice(-2),t=s.slice(0,-2);let a=parseInt(t)||0,n=parseInt(e)||0;return a+=Math.floor(n/60),n%=60,`${a.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}}function w(e){return 100===e?"#84c148":e>0?"#1b75bb":""}function D({open:e,onOpenChange:s,report:t,onSave:a,isSubmitting:n=!1}){const{t:l}=d.useTranslation(),[c,u]=o.useState(t?.percentProgress||0),[x,m]=o.useState(t?.timeProgress||""),[p,h]=o.useState(t?.comments||""),g=c!==(t?.percentProgress??0)||x!==(t?.timeProgress??"")||p!==(t?.comments??"");o.useEffect(()=>{t&&(u(t.percentProgress),m(t.timeProgress||""),h(t.comments||""))},[t]);return r.jsx(i.Dialog,{open:e,onOpenChange:s,children:r.jsxs(i.DialogContent,{className:"sm:max-w-md",variant:"form",isDirty:g,children:[r.jsx(i.DialogHeader,{children:r.jsx(i.DialogTitle,{children:l("ap_edit_progress")})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:l("ap_progress_percent")}),r.jsx(i.Input,{type:"number",min:0,max:100,value:c,onChange:e=>u(Number(e.target.value))})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:l("ap_time_spent")}),r.jsx(i.Input,{value:x,onChange:e=>m(e.target.value),onBlur:()=>m(C(x)||""),placeholder:"00:00"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:l("ap_comments")}),r.jsx(i.Textarea,{value:p,onChange:e=>h(e.target.value),rows:3,maxLength:4e3})]})]}),r.jsxs(i.DialogFooter,{children:[r.jsx(i.Button,{variant:"outline",onClick:()=>s(!1),disabled:n,children:"Cancelar"}),r.jsx(i.Button,{onClick:()=>{t&&a({...t,percentProgress:c,timeProgress:C(x)||"00:00",comments:p})},disabled:n,children:n?"Salvando...":"Salvar"})]})]})})}function E(e){const{t:s}=d.useTranslation(),{progress:t,canReportProgress:a,isSubmitting:n,editingReport:l,setEditingReport:c,reportProgress:u,editProgress:x,deleteProgress:m}=P(e),[p,h]=o.useState(""),[g,j]=o.useState(""),[f,v]=o.useState("");if(!t)return r.jsx("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Sem dados de progresso disponíveis"});const b=w(t.percentProgress),S=!p,N=!p&&!g&&!f;return r.jsxs("div",{className:"space-y-6 p-1",children:[r.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"font-medium",children:s("ap_overall_progress")}),r.jsxs("span",{className:"font-semibold",style:{color:b||void 0},children:[t.percentProgress,"%"]})]}),r.jsx(i.Progress,{value:t.percentProgress,className:"h-3"}),t.timeProgress&&r.jsxs("div",{className:"text-xs text-muted-foreground",children:["Tempo total: ",k(t.timeProgress)]})]}),a&&r.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[r.jsx("h4",{className:"text-sm font-medium",children:s("ap_report_progress")}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:s("ap_progress_percent")}),r.jsx(i.Input,{type:"number",min:0,max:100,value:p,onChange:e=>h(e.target.value),placeholder:"0"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:s("ap_time_spent")}),r.jsx(i.Input,{value:g,onChange:e=>j(e.target.value),onBlur:()=>j(C(g)||""),placeholder:"00:00"})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:s("ap_comments")}),r.jsx(i.Textarea,{value:f,onChange:e=>v(e.target.value),rows:3,maxLength:4e3,placeholder:s("ap_progress_comment_placeholder")})]}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx(i.Button,{variant:"outline",size:"sm",onClick:()=>{h(""),j(""),v("")},disabled:N||n,children:"Limpar"}),r.jsx(i.Button,{size:"sm",onClick:async()=>{const e=Number(p);(e||0===e)&&(await u({percentProgress:e,timeProgress:C(g)||"00:00",comments:f}),h(""),j(""),v(""))},disabled:S||n,children:n?"Reportando...":"Reportar"})]})]}),t.reports.length>0&&r.jsxs("div",{className:"space-y-3",children:[r.jsx("h4",{className:"text-sm font-medium",children:s("ap_reports_history")}),r.jsx("div",{className:"space-y-2",children:t.reports.map(e=>r.jsx(_,{report:e,onEdit:()=>c(e),onDelete:()=>m(e.id),disabled:!a},e.id))})]}),r.jsx(D,{open:!!l,onOpenChange:e=>!e&&c(null),report:l,onSave:x,isSubmitting:n})]})}function _({report:e,onEdit:s,onDelete:t,disabled:a}){const n=e.date?new Date(e.date):null,l=w(e.percentProgress);return r.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-card p-3",children:[r.jsx("div",{className:"flex-shrink-0 h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground",children:e.userName?.charAt(0)?.toUpperCase()||"?"}),r.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:"font-medium truncate",children:e.userName}),n&&r.jsx("span",{className:"text-xs text-muted-foreground",children:n.toLocaleDateString("pt-BR")})]}),r.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[r.jsxs("span",{style:{color:l||void 0},className:"font-semibold",children:[e.percentProgress,"%"]}),e.timeProgress&&r.jsxs("span",{children:["Tempo: ",k(e.timeProgress)]})]}),e.comments&&r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:e.comments})]}),!a&&r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.ActionButton,{})}),r.jsxs(i.DropdownMenuContent,{align:"end",children:[r.jsx(i.DropdownMenuItem,{onClick:s,children:c.t("edit")}),r.jsx(i.DropdownMenuItem,{className:"text-destructive",onClick:t,children:c.t("ap_delete")})]})]})]})}function A({predecessors:e=[],availablePredecessors:s=[],onAdd:t,onRemove:a,disabled:n=!1}){const{t:c}=d.useTranslation(),[u,x]=o.useState(""),m=s.filter(s=>!e.some(e=>e.predecessorId===s.id));return r.jsxs("div",{className:"space-y-6 p-1",children:[!n&&m.length>0&&r.jsxs("div",{className:"flex items-end gap-3",children:[r.jsxs("div",{className:"flex-1 space-y-2",children:[r.jsx(i.Label,{children:c("ap_add_predecessor")}),r.jsxs(i.Select,{value:u,onValueChange:x,children:[r.jsx(i.SelectTrigger,{children:r.jsx(i.SelectValue,{placeholder:c("ap_select_action")})}),r.jsx(i.SelectContent,{children:m.map(e=>r.jsx(i.SelectItem,{value:e.id,children:e.label},e.id))})]})]}),r.jsxs(i.Button,{size:"sm",onClick:()=>{u&&t&&(t(u),x(""))},disabled:!u,children:[r.jsx(l.Plus,{className:"h-4 w-4 mr-1"}),"Adicionar"]})]}),e.length>0?r.jsx("div",{className:"space-y-2",children:e.map(e=>r.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[e.predecessorCode&&r.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:e.predecessorCode}),r.jsx("span",{className:"text-sm font-medium",children:e.predecessorName}),null!=e.predecessorStatus&&r.jsx(N,{status:e.predecessorStatus})]}),!n&&a&&r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.ActionButton,{})}),r.jsx(i.DropdownMenuContent,{align:"end",children:r.jsx(i.DropdownMenuItem,{className:"text-destructive",onClick:()=>a(e.predecessorId),children:"Remover"})})]})]},e.id))}):r.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum predecessor adicionado"})]})}function I({costs:e=[],onAdd:s,onEdit:t,onDelete:a,disabled:n=!1}){const{t:c}=d.useTranslation(),[u,x]=o.useState(""),[m,p]=o.useState(""),h=e.reduce((e,s)=>e+(s.value||0),0);return r.jsxs("div",{className:"space-y-6 p-1",children:[r.jsxs("div",{className:"rounded-lg border bg-card p-4 flex items-center justify-between",children:[r.jsx("span",{className:"text-sm font-medium",children:c("ap_total_cost")}),r.jsxs("span",{className:"text-lg font-semibold text-foreground",children:["R$ ",h.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),!n&&s&&r.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[r.jsx("h4",{className:"text-sm font-medium",children:c("ap_add_cost")}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:"Descrição"}),r.jsx(i.Input,{value:u,onChange:e=>x(e.target.value),placeholder:c("ap_cost_description")})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Label,{children:"Valor (R$)"}),r.jsx(i.Input,{type:"number",min:0,step:.01,value:m,onChange:e=>p(e.target.value),placeholder:"0,00"})]})]}),r.jsx("div",{className:"flex justify-end",children:r.jsxs(i.Button,{size:"sm",onClick:()=>{u&&m&&s&&(s({description:u,value:Number(m),date:(new Date).toISOString()}),x(""),p(""))},disabled:!u||!m,children:[r.jsx(l.Plus,{className:"h-4 w-4 mr-1"}),"Adicionar"]})})]}),e.length>0?r.jsx("div",{className:"space-y-2",children:e.map(e=>r.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium truncate",children:e.description}),e.date&&r.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(e.date).toLocaleDateString("pt-BR")})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("span",{className:"text-sm font-semibold whitespace-nowrap",children:["R$ ",e.value.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]}),!n&&(t||a)&&r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.ActionButton,{})}),r.jsxs(i.DropdownMenuContent,{align:"end",children:[t&&r.jsx(i.DropdownMenuItem,{onClick:()=>t(e),children:c("edit")}),a&&r.jsx(i.DropdownMenuItem,{className:"text-destructive",onClick:()=>a(e.id),children:c("ap_delete")})]})]})]})]},e.id))}):r.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum custo registrado"})]})}function L({comments:e=[],currentUserId:s,onAdd:t,onEdit:a,onDelete:n,disabled:c=!1,maxLength:u=4e3}){const{t:x}=d.useTranslation(),[m,p]=o.useState(""),[h,g]=o.useState(!1),[j,f]=o.useState(null),[v,b]=o.useState(""),S=()=>{f(null),b("")};return r.jsxs("div",{className:"space-y-6 p-1",children:[!c&&t&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(i.Textarea,{value:m,onChange:e=>p(e.target.value),placeholder:x("ap_add_comment_placeholder"),maxLength:u,rows:3}),r.jsxs("div",{className:"flex items-center justify-between",children:[u&&r.jsxs("span",{className:"text-xs text-muted-foreground",children:[m.length,"/",u]}),r.jsxs("div",{className:"flex gap-2 ml-auto",children:[r.jsx(i.Button,{variant:"outline",size:"sm",onClick:()=>p(""),disabled:!m||h,children:"Limpar"}),r.jsx(i.Button,{size:"sm",onClick:async()=>{if(m.trim()&&t){g(!0);try{await t(m),p("")}finally{g(!1)}}},disabled:!m.trim()||h,children:h?"Enviando...":"Comentar"})]})]})]}),r.jsxs("div",{className:"space-y-1",children:[e.length>0?r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx("span",{className:"text-sm font-medium",children:x("ap_comments")}),r.jsx(i.Badge,{variant:"info",className:"text-[10px] px-1.5 py-0",children:e.length})]}):r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[r.jsx(l.MessageSquare,{className:"h-8 w-8 mb-2 opacity-50"}),r.jsx("p",{className:"text-sm",children:"Nenhum comentário adicionado"})]}),e.map(e=>r.jsxs("div",{className:"flex gap-3 rounded-lg border bg-card p-3",children:[r.jsx("div",{className:"flex-shrink-0 h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground overflow-hidden",children:e.userPhotoUrl?r.jsx("img",{src:e.userPhotoUrl,alt:e.userName,className:"h-full w-full object-cover"}):e.userName?.charAt(0)?.toUpperCase()||"?"}),r.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:"font-medium truncate",children:e.userName}),e.userEmail&&r.jsx("span",{className:"text-xs text-muted-foreground truncate",children:e.userEmail}),r.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:B(e.dateEdited||e.dateCreation)}),e.dateEdited&&r.jsx("span",{className:"text-xs text-muted-foreground italic",children:"editado"})]}),j===e.id?r.jsxs("div",{className:"space-y-2",children:[r.jsx(i.Textarea,{value:v,onChange:e=>b(e.target.value),maxLength:u,rows:3}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx(i.Button,{variant:"outline",size:"sm",onClick:S,disabled:h,children:"Cancelar"}),r.jsx(i.Button,{size:"sm",onClick:()=>(async e=>{if(v.trim()&&a){g(!0);try{await a({...e,text:v,stringText:v}),f(null),b("")}finally{g(!1)}}})(e),disabled:!v.trim()||h,children:h?"Salvando...":"Salvar"})]})]}):r.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:e.stringText||e.text})]}),!c&&s===e.userId&&j!==e.id&&r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.ActionButton,{})}),r.jsxs(i.DropdownMenuContent,{align:"end",children:[a&&r.jsx(i.DropdownMenuItem,{onClick:()=>(e=>{f(e.id),b(e.stringText||e.text)})(e),children:x("edit")}),n&&r.jsx(i.DropdownMenuItem,{className:"text-destructive",onClick:()=>(async e=>{if(n){g(!0);try{await n(e)}finally{g(!1)}}})(e.id),children:"Excluir"})]})]})]},e.id))]})]})}function B(e){const{t:s}=d.useTranslation();if(!e)return"";const t=new Date(e);return`${t.toLocaleDateString("pt-BR")} ${t.toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}`}function M({history:e=[],isLoading:s=!1}){const{t:t}=d.useTranslation();return s?r.jsx("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Carregando histórico..."}):0===e.length?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[r.jsx(l.Clock,{className:"h-8 w-8 mb-2 opacity-50"}),r.jsx("p",{className:"text-sm",children:t("ap_no_history")})]}):r.jsx("div",{className:"p-1",children:r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute left-4 top-0 bottom-0 w-px bg-border"}),r.jsx("div",{className:"space-y-0",children:e.map((e,s)=>r.jsxs("div",{className:"relative flex gap-4 pb-6 last:pb-0",children:[r.jsx("div",{className:"relative z-10 flex-shrink-0 h-8 w-8 rounded-full bg-primary/10 border-2 border-primary/30 flex items-center justify-center",children:e.icon?r.jsx("span",{className:"text-xs text-primary",children:e.icon}):r.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})}),r.jsxs("div",{className:"flex-1 min-w-0 rounded-lg border bg-card p-3 space-y-2",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium",children:e.translateEvent||e.eventName}),e.eventDescription&&r.jsx("p",{className:"text-xs text-muted-foreground",children:e.eventDescription})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-shrink-0 h-6 w-6 rounded-full bg-muted overflow-hidden flex items-center justify-center text-[10px] font-medium text-muted-foreground",children:e.userPhotoUrl?r.jsx("img",{src:e.userPhotoUrl,alt:e.userName,className:"h-full w-full object-cover"}):e.userName?.charAt(0)?.toUpperCase()||"?"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("span",{className:"text-xs font-medium truncate block",children:e.userName}),e.userEmail&&r.jsx("span",{className:"text-[10px] text-muted-foreground truncate block",children:e.userEmail})]})]}),r.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(l.Calendar,{className:"h-3 w-3"}),r.jsx("span",{children:F(e.date)})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(l.Clock,{className:"h-3 w-3"}),r.jsx("span",{children:R(e.date)})]}),e.isMobileRequest&&r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(l.Smartphone,{className:"h-3 w-3"}),r.jsx("span",{children:t("ap_via_app")})]})]})]})]},e.id))})]})})}function F(e){const{t:s}=d.useTranslation();return new Date(e).toLocaleDateString("pt-BR")}function R(e){const{t:s}=d.useTranslation();return new Date(e).toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}function z({attachments:e=[],onUpload:s,onDelete:t,onRename:a,onDownload:n,onView:c,disabled:u=!1}){const{t:x}=d.useTranslation(),m=o.useRef(null),[p,h]=o.useState(null),[g,j]=o.useState(""),f=async e=>{g.trim()&&a&&(await a(e.id,g),h(null),j(""))},v=()=>{h(null),j("")};return r.jsxs("div",{className:"space-y-4 p-1",children:[!u&&s&&r.jsxs(r.Fragment,{children:[r.jsx("input",{ref:m,type:"file",multiple:!0,className:"hidden",onChange:e=>{const t=e.target.files;if(t&&s){for(let e=0;e<t.length;e++){const a=t.item(e);a&&s(a)}m.current&&(m.current.value="")}}}),r.jsxs(i.Button,{size:"sm",onClick:()=>m.current?.click(),children:[r.jsx(l.Plus,{className:"h-4 w-4 mr-1"}),"Adicionar anexo"]})]}),e.length>0?r.jsx("div",{className:"space-y-2",children:e.map(e=>r.jsxs("div",{className:i.cn("flex items-center gap-3 rounded-lg border bg-card p-3",e.status===exports.EAttachmentItemStatus.error&&"border-destructive/50 bg-destructive/5",e.status===exports.EAttachmentItemStatus.canceled&&"opacity-50"),children:[r.jsx("div",{className:"flex-shrink-0 h-9 w-9 rounded bg-muted flex items-center justify-center",children:r.jsx("span",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:e.extension.replace(".","").substring(0,4)})}),r.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[p===e.id?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{className:"flex-1 text-sm border rounded px-2 py-1 bg-background",value:g,onChange:e=>j(e.target.value),onKeyDown:s=>{"Enter"===s.key&&f(e),"Escape"===s.key&&v()},autoFocus:!0}),r.jsx(i.Button,{size:"sm",variant:"outline",onClick:v,children:x("cancel")}),r.jsx(i.Button,{size:"sm",onClick:()=>f(e),children:x("save")})]}):r.jsx("button",{type:"button",className:"text-sm font-medium truncate block text-left hover:underline cursor-pointer",onClick:()=>c?.(e.id),children:e.name}),(e.status===exports.EAttachmentItemStatus.uploading||e.status===exports.EAttachmentItemStatus.waiting)&&r.jsx(i.Progress,{value:e.progress||0,className:"h-1.5"}),e.status===exports.EAttachmentItemStatus.error&&r.jsx("p",{className:"text-xs text-destructive",children:"Erro ao enviar arquivo"}),e.status===exports.EAttachmentItemStatus.duplicateItem&&r.jsx("p",{className:"text-xs text-warning",children:"Arquivo duplicado"}),e.status===exports.EAttachmentItemStatus.canceled&&r.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload cancelado"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[e.status===exports.EAttachmentItemStatus.done&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:V(e.size)}),r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.ActionButton,{})}),r.jsxs(i.DropdownMenuContent,{align:"end",children:[a&&!u&&r.jsx(i.DropdownMenuItem,{onClick:()=>(e=>{const s=e.name.replace(e.extension,"");h(e.id),j(s)})(e),children:"Renomear"}),c&&r.jsx(i.DropdownMenuItem,{onClick:()=>c(e.id),children:"Visualizar"}),n&&r.jsx(i.DropdownMenuItem,{onClick:()=>n(e.id),children:"Download"}),t&&!u&&r.jsxs(r.Fragment,{children:[r.jsx(i.DropdownMenuSeparator,{}),r.jsx(i.DropdownMenuItem,{className:"text-destructive",onClick:()=>t(e.id),children:"Excluir"})]})]})]})]}),e.status===exports.EAttachmentItemStatus.uploading&&r.jsx(i.Button,{variant:"outline",size:"sm",onClick:()=>t?.(e.id),children:"Cancelar"})]})]},e.id))}):r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[r.jsx(l.Paperclip,{className:"h-8 w-8 mb-2 opacity-50"}),r.jsx("p",{className:"text-sm",children:"Nenhum anexo adicionado"})]})]})}function V(e){const{t:s}=d.useTranslation();if(0===e)return"0 B";const t=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,t)).toFixed(1))} ${["B","KB","MB","GB"][t]}`}exports.ActionPlanAttachmentsTab=z,exports.ActionPlanCommentsTab=L,exports.ActionPlanCostTab=I,exports.ActionPlanGeneralTab=T,exports.ActionPlanHistoryTab=M,exports.ActionPlanPage=function(e){const{formData:s,isLoading:t,isSaving:a,activeTab:n,isFormDisabled:c,updateField:o,setActiveTab:u,save:x,changeStatus:m,remove:p,cancel:g}=b(e),{t:j}=d.useTranslation(),{isNew:f=!1,config:v,users:S,places:y,actionTypes:P,causes:C,parentActions:k,progress:w,predecessors:D,availablePredecessors:_,costs:B,comments:F,history:R,attachments:V,attachmentsSlot:U,commentsSlot:$,historySlot:O,onAddPredecessor:q,onRemovePredecessor:H,onAddCost:W,onEditCost:G,onDeleteCost:K,onAddComment:X,onEditComment:J,onDeleteComment:Y,onUploadAttachment:Q,onDeleteAttachment:Z,onRenameAttachment:ee,onDownloadAttachment:se,onViewAttachment:te}=e;if(t&&!s.id)return r.jsx(i.LoadingState,{isLoading:!0,children:r.jsx("div",{})});const ae=function(e){const{t:s}=d.useTranslation();if(!e)return[];return{[exports.ETaskPlanStatus.waitingStart]:[exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.suspended,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.running]:[exports.ETaskPlanStatus.effectivenessCheck,exports.ETaskPlanStatus.done,exports.ETaskPlanStatus.suspended,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.effectivenessCheck]:[exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.done,exports.ETaskPlanStatus.suspended,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.done]:[exports.ETaskPlanStatus.running],[exports.ETaskPlanStatus.suspended]:[exports.ETaskPlanStatus.running,exports.ETaskPlanStatus.canceled],[exports.ETaskPlanStatus.canceled]:[exports.ETaskPlanStatus.waitingStart]}[e]||[]}(s.statusId);return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsxs("div",{className:"flex items-center justify-between border-b bg-card px-6 py-4",children:[r.jsxs("div",{className:"flex items-center gap-4",children:[g&&r.jsx(i.Button,{variant:"ghost",size:"icon",onClick:g,children:r.jsx(l.ArrowLeft,{className:"h-4 w-4"})}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("h1",{className:"text-lg font-semibold",children:f?j("ap_new_action"):s.name||j("ap_action_plan")}),!f&&s.statusId&&r.jsx(N,{status:s.statusId})]}),s.code&&r.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:s.code})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[!f&&ae.length>0&&!c&&r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.Button,{variant:"outline",size:"sm",children:"Alterar Status"})}),r.jsx(i.DropdownMenuContent,{align:"end",children:ae.map(e=>r.jsx(i.DropdownMenuItem,{onClick:()=>m(e),children:h[e]},e))})]}),!f&&e.onDelete&&r.jsxs(i.DropdownMenu,{children:[r.jsx(i.DropdownMenuTrigger,{asChild:!0,children:r.jsx(i.Button,{variant:"ghost",size:"icon",children:r.jsx(l.MoreVertical,{className:"h-4 w-4"})})}),r.jsx(i.DropdownMenuContent,{align:"end",children:r.jsx(i.DropdownMenuItem,{className:"text-destructive",onClick:p,children:"Excluir"})})]})]})]}),r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:r.jsx("div",{className:"max-w-4xl mx-auto px-6 py-6",children:r.jsxs(i.Tabs,{value:n,onValueChange:u,children:[r.jsxs(i.TabsList,{className:"mb-6",children:[r.jsx(i.TabsTrigger,{value:"general",children:"Geral"}),!f&&r.jsx(i.TabsTrigger,{value:"progress",children:"Progresso"}),!f&&v?.enablePredecessors&&r.jsx(i.TabsTrigger,{value:"predecessors",children:j("ap_predecessors")}),!f&&v?.enableCosts&&r.jsx(i.TabsTrigger,{value:"costs",children:"Custos"}),!f&&v?.enableAttachments&&r.jsx(i.TabsTrigger,{value:"attachments",children:j("ap_attachments")}),!f&&v?.enableComments&&r.jsx(i.TabsTrigger,{value:"comments",children:j("ap_comments")}),!f&&v?.enableHistory&&r.jsx(i.TabsTrigger,{value:"history",children:"Histórico"})]}),r.jsx(i.TabsContent,{value:"general",children:r.jsx(T,{formData:s,updateField:o,disabled:c,users:S,places:y,actionTypes:P,causes:C,parentActions:k,config:v})}),!f&&r.jsx(i.TabsContent,{value:"progress",children:r.jsx(E,{...e})}),!f&&v?.enablePredecessors&&r.jsx(i.TabsContent,{value:"predecessors",children:r.jsx(A,{predecessors:D,availablePredecessors:_,onAdd:q,onRemove:H,disabled:c})}),!f&&v?.enableCosts&&r.jsx(i.TabsContent,{value:"costs",children:r.jsx(I,{costs:B,onAdd:W,onEdit:G,onDelete:K,disabled:c})}),!f&&v?.enableAttachments&&r.jsx(i.TabsContent,{value:"attachments",children:U||r.jsx(z,{attachments:V,onUpload:Q,onDelete:Z,onRename:ee,onDownload:se,onView:te,disabled:c})}),!f&&v?.enableComments&&r.jsx(i.TabsContent,{value:"comments",children:$||r.jsx(L,{comments:F,onAdd:X,onEdit:J,onDelete:Y,disabled:c})}),!f&&v?.enableHistory&&r.jsx(i.TabsContent,{value:"history",children:O||r.jsx(M,{history:R})})]})})}),r.jsxs("div",{className:"flex items-center justify-end gap-3 border-t bg-card px-6 py-4",children:[g&&r.jsx(i.Button,{variant:"outline",onClick:g,disabled:a,children:"Cancelar"}),r.jsx(i.Button,{onClick:x,disabled:a||c,children:a?"Salvando...":"Salvar"})]})]})},exports.ActionPlanPredecessorsTab=A,exports.ActionPlanProgressDialog=D,exports.ActionPlanProgressTab=E,exports.ActionPlanStatusBadge=N,exports.CLOSED_STATUSES=f,exports.DEFAULT_ACTION_TYPES=g,exports.PRIORITIES=j,exports.PROGRESS_ALLOWED_STATUSES=v,exports.STATUS_COLORS=u,exports.STATUS_LABELS=h,exports.STATUS_MAP=m,exports.STATUS_TEXT_COLORS=x,exports.formatTime=k,exports.formatTimeProgress=C,exports.getActionTypes=function(){return[{id:"immediate",label:c.t("ap_type_immediate")},{id:"corrective",label:c.t("ap_type_corrective")},{id:"preventive",label:c.t("ap_type_preventive")},{id:"improvement",label:c.t("ap_type_improvement")},{id:"standardization",label:c.t("ap_type_standardization")}]},exports.getPriorities=function(){return[{id:exports.ETaskPlanPriority.low,label:c.t("ap_priority_low"),color:"#4CAF50"},{id:exports.ETaskPlanPriority.medium,label:c.t("ap_priority_medium"),color:"#FF9800"},{id:exports.ETaskPlanPriority.high,label:c.t("ap_priority_high"),color:"#F44336"}]},exports.getProgressColor=w,exports.getStatusLabels=p,exports.useActionPlan=b,exports.useActionPlanProgress=P;
@@ -42,4 +42,23 @@ export declare class AuthService {
42
42
  * Extrai alias do access token (campo default)
43
43
  */
44
44
  private static extractAliasFromAccessToken;
45
+ /**
46
+ * Detecta o alias a partir do subdomínio da URL atual.
47
+ *
48
+ * Padrões reconhecidos:
49
+ * - `educacao.sabergestao.com.br` → "sabergestao"
50
+ * - `<modulo>.<alias>.<tld>` → alias
51
+ * - `<alias>.qualiex.com` → alias
52
+ * - localhost / *.lovable.app / *.lovable.dev → null
53
+ */
54
+ private static getSubdomainAlias;
55
+ /**
56
+ * Resolve o alias ativo seguindo prioridade:
57
+ * 1. Subdomínio da URL (se válido contra companies)
58
+ * 2. Alias do Supabase token (se válido)
59
+ * 3. Alias armazenado (se válido)
60
+ * 4. `default` do access token (se válido)
61
+ * 5. Primeira company
62
+ */
63
+ private static resolveAliasFromContext;
45
64
  }
@@ -1,3 +1,5 @@
1
+ export * as AccordionPrimitive from '@radix-ui/react-accordion';
2
+ export * as DialogPrimitive from '@radix-ui/react-dialog';
1
3
  export * from '../components/ui/accordion';
2
4
  export * from '../components/ui/alert';
3
5
  export * from '../components/ui/alert-dialog';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Componente interno (renderiza `null`) que aplica automaticamente o idioma
3
+ * do usuário ao i18next assim que `useModuleAccess` resolver a associação atual.
4
+ *
5
+ * - Fonte de verdade: `association.language` (vindo de `/users/{userId}/associations`).
6
+ * - Não persiste em `localStorage` — o React-Query já cacheia o resultado e o
7
+ * próximo boot refaz a chamada para revalidar.
8
+ * - Reage a `switchUnit`: ao trocar de unidade, useModuleAccess refaz a query
9
+ * e o efeito reaplica o idioma da nova associação.
10
+ *
11
+ * Para que funcione, deve ser montado dentro do `AuthProvider`, `LocaleProvider`
12
+ * e `ModuleProvider`. `CoreProviders` já cuida disso.
13
+ */
14
+ export declare function LanguageBootstrap(): any;
@@ -5,6 +5,7 @@
5
5
  * Import this instead of importing directly from react-i18next.
6
6
  */
7
7
  export { default as i18n, addAppTranslations } from './config';
8
+ export { LanguageBootstrap } from './LanguageBootstrap';
8
9
  export { useTranslation } from 'react-i18next';
9
10
  export { I18nextProvider } from 'react-i18next';
10
11
  export { mergeTranslationFiles } from './utils';
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as r from"react";import{useState as a,useCallback as n,useEffect as o,useRef as s}from"react";import{ChevronDown as i,ChevronUp as d,Check as l,RotateCcw as c,Download as m,Filter as u,Loader2 as p,X as f,FileText as h,Layers as g,Clock as x,User as v,Eye as y}from"lucide-react";import{Slot as b}from"@radix-ui/react-slot";import{cva as w}from"class-variance-authority";import{clsx as N}from"clsx";import{twMerge as I}from"tailwind-merge";import"date-fns";import"sonner";import*as D from"@radix-ui/react-label";import*as k from"@radix-ui/react-select";import C from"i18next";import{useTranslation as E}from"react-i18next";function S(...e){return I(N(e))}const R=w("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary-hover shadow-sm hover:shadow-md active:scale-[0.98]",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary-hover border border-input shadow-sm",tertiary:"bg-background text-foreground hover:bg-accent hover:text-accent-foreground border border-border",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground",subtle:"text-muted-foreground hover:text-foreground hover:bg-accent/50",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm hover:shadow-md",danger:"bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm hover:shadow-md",link:"text-primary underline-offset-4 hover:underline",icon:"bg-transparent border border-input hover:bg-accent hover:text-accent-foreground p-2",loading:"bg-primary/50 text-primary-foreground cursor-wait",default:"bg-primary text-primary-foreground hover:bg-primary/90",action:"bg-primary/10 text-primary hover:bg-primary/20 border border-primary/30","icon-only":"bg-transparent border border-input hover:bg-accent hover:text-accent-foreground p-2","external-link":"bg-transparent text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors","action-primary":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm","action-secondary":"bg-secondary text-secondary-foreground hover:bg-secondary/80 border border-input"},size:{sm:"h-8 px-3 text-xs rounded-lg",md:"h-10 px-4 py-2 text-sm rounded-md",lg:"h-12 px-8 text-base rounded-lg",xl:"h-14 px-10 text-lg rounded-lg",icon:"h-10 w-10","icon-sm":"h-8 w-8","icon-xs":"h-6 w-6",default:"h-10 px-4 py-2"}},defaultVariants:{variant:"primary",size:"md"}}),$=r.forwardRef(({className:t,variant:r,size:a,asChild:n=!1,...o},s)=>e(n?b:"button",{className:S(R({variant:r,size:a,className:t})),ref:s,...o}));$.displayName="Button";const j=w("text-xs font-medium leading-none text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),z=r.forwardRef(({className:t,...r},a)=>e(D.Root,{ref:a,className:S(j(),t),...r}));z.displayName=D.Root.displayName;const T=r.createContext({showCheck:!1}),V=({showCheck:t=!1,...r})=>e(T.Provider,{value:{showCheck:t},children:e(k.Root,{...r})}),P=k.Value,A=r.forwardRef(({className:r,children:a,...n},o)=>t(k.Trigger,{ref:o,className:S("flex h-10 w-full items-center justify-between rounded-lg border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground hover:border-primary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors [&>span]:line-clamp-1",r),...n,children:[a,e(k.Icon,{asChild:!0,children:e(i,{className:"h-4 w-4 opacity-50"})})]}));A.displayName=k.Trigger.displayName;const B=r.forwardRef(({className:t,...r},a)=>e(k.ScrollUpButton,{ref:a,className:S("flex cursor-default items-center justify-center py-1",t),...r,children:e(d,{className:"h-4 w-4"})}));B.displayName=k.ScrollUpButton.displayName;const F=r.forwardRef(({className:t,...r},a)=>e(k.ScrollDownButton,{ref:a,className:S("flex cursor-default items-center justify-center py-1",t),...r,children:e(i,{className:"h-4 w-4"})}));F.displayName=k.ScrollDownButton.displayName;const L=r.forwardRef(({className:r,children:a,position:n="popper",container:o,collisionBoundary:s,...i},d)=>e(k.Portal,{container:o,children:t(k.Content,{ref:d,className:S("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===n&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",r),position:n,collisionBoundary:s,...i,children:[e(B,{}),e(k.Viewport,{className:S("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),e(F,{})]})}));L.displayName=k.Content.displayName;r.forwardRef(({className:t,...r},a)=>e(k.Label,{ref:a,className:S("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...r})).displayName=k.Label.displayName;const M=r.forwardRef(({className:a,children:n,...o},s)=>{const{showCheck:i}=r.useContext(T);return t(k.Item,{ref:s,className:S("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",i?"pl-8":"pl-2","data-[state=checked]:bg-accent data-[state=checked]:text-accent-foreground data-[state=checked]:font-medium data-[state=checked]:border-l-2 data-[state=checked]:border-primary",i?"data-[state=checked]:pl-[calc(2rem-2px)]":"data-[state=checked]:pl-[calc(0.5rem-2px)]",a),...o,children:[i&&e("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e(k.ItemIndicator,{children:e(l,{className:"h-4 w-4"})})}),e(k.ItemText,{children:n})]})});M.displayName=k.Item.displayName;r.forwardRef(({className:t,...r},a)=>e(k.Separator,{ref:a,className:S("-mx-1 my-1 h-px bg-muted",t),...r})).displayName=k.Separator.displayName;const _=r.forwardRef(({className:a,type:n,showCharCount:o,maxLength:s,onChange:i,...d},l)=>{const[c,m]=r.useState(0);r.useEffect(()=>{"string"==typeof d.value?m(d.value.length):"string"==typeof d.defaultValue&&m(d.defaultValue.length)},[d.value,d.defaultValue]);return t("div",{className:"w-full",children:[e("input",{type:n,className:S("flex h-10 w-full rounded-lg border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors md:text-sm",a),ref:l,maxLength:s,onChange:e=>{m(e.target.value.length),i?.(e)},...d}),o&&s&&t("div",{className:"text-right text-xs text-muted-foreground mt-1",children:[c," / ",s]})]})});function U({queryParams:r,events:o,softwares:s,users:i=[],permissions:d={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},isLoading:l=!1,onFilter:p,onReset:f,onExport:h,onSoftwareChange:g}){const[x,v]=a(r.softwareId),[y,b]=a(r.eventId),[w,N]=a(r.userId||"all"),[I,D]=a(O(r.startDate)),[k,C]=a(O(r.endDate)),E=n(e=>{const t=parseInt(e);v(t),g?.(t)},[g]),S=n(()=>{p({...r,softwareId:x,eventId:y,userId:"all"===w?void 0:w,startDate:new Date(I),endDate:new Date(k),software:s.find(e=>e.id===x)?.software||r.software,event:o.find(e=>e.id===y)?.name||r.event})},[r,x,y,w,I,k,s,o,p]),R=n(()=>{const e=new Date;e.setHours(0,0,0,0),D(O(e)),C(O(e)),b(r.eventId),d.viewAllEvents&&N("all"),f?.()},[r.eventId,d.viewAllEvents,f]),j=d.viewOnlyMyEvents&&!d.viewAllEvents,T=x&&y&&I&&k;return t("div",{className:"flex flex-wrap items-end gap-3 rounded-lg border border-border bg-card p-3",children:[t("div",{className:"flex flex-col gap-1 min-w-[180px]",children:[e(z,{className:"text-xs text-muted-foreground",children:"Módulo *"}),t(V,{value:String(x),onValueChange:E,disabled:l,children:[e(A,{className:"h-8 text-xs",children:e(P,{placeholder:"Selecione..."})}),e(L,{children:s.map(t=>e(M,{value:String(t.id),className:"text-xs",children:t.translation},t.id))})]})]}),t("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[e(z,{className:"text-xs text-muted-foreground",children:"Evento *"}),t(V,{value:String(y),onValueChange:e=>b(parseInt(e)),disabled:l,children:[e(A,{className:"h-8 text-xs",children:e(P,{placeholder:"Selecione..."})}),e(L,{children:o.map(t=>e(M,{value:String(t.id),className:"text-xs",children:t.translation},t.id))})]})]}),t("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[e(z,{className:"text-xs text-muted-foreground",children:"Usuário *"}),t(V,{value:w,onValueChange:N,disabled:l||j,children:[e(A,{className:"h-8 text-xs",children:e(P,{placeholder:"Selecione..."})}),t(L,{children:[e(M,{value:"all",className:"text-xs",children:"Todos"}),i.map(t=>e(M,{value:t.id,className:"text-xs",children:t.name},t.id))]})]})]}),t("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[e(z,{className:"text-xs text-muted-foreground",children:"De *"}),e(_,{type:"date",value:I,onChange:e=>D(e.target.value),className:"h-8 text-xs",max:k,disabled:l})]}),t("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[e(z,{className:"text-xs text-muted-foreground",children:"Até *"}),e(_,{type:"date",value:k,onChange:e=>C(e.target.value),className:"h-8 text-xs",min:I,disabled:l})]}),t("div",{className:"flex items-center gap-2 ml-auto",children:[t($,{variant:"outline",size:"sm",onClick:R,disabled:l,children:[e(c,{className:"h-3.5 w-3.5 mr-1"}),"Limpar"]}),d.download&&h&&t($,{variant:"outline",size:"sm",onClick:()=>h("xlsx"),disabled:l,children:[e(m,{className:"h-3.5 w-3.5 mr-1"}),"Exportar"]}),t($,{size:"sm",onClick:S,disabled:l||!T,children:[e(u,{className:"h-3.5 w-3.5 mr-1"}),"Filtrar"]})]})]})}function O(e){return(e instanceof Date?e:new Date(e)).toISOString().split("T")[0]}_.displayName="Input";const q={sm:"h-4 w-4",md:"h-6 w-6",lg:"h-8 w-8"};function H({size:t="md",className:r}){return e(p,{className:S("animate-spin text-muted-foreground",q[t],r)})}function J(e,t,r,a="Anônimo"){return e.map(e=>({...e,translatedSoftware:G(e.software,r),user:e.userEmail||e.userName||a,translatedEvent:Z(e.eventName,t),date:new Date(e.dateTime)})).sort((e,t)=>(t.date?.getTime()??0)-(e.date?.getTime()??0))}function Z(e,t){const r=t.find(t=>t.name===e);return r?.translation||e}function G(e,t){const r=e.includes(".")?e.split(".").pop():e,a=t.find(e=>e.software===r);return a?.translation||r}function K(e,t){const r=[],a={...re,...t?.labels},n=e.eventName;r.push({name:a.event,value:n});const o=e.entities?.[0];if(o&&(r.push({name:a.entityName,value:Q(o)}),o.description&&r.push({name:a.description,value:o.description}),o.justification&&r.push({name:a.justification,value:o.justification}),o.statusName&&r.push({name:a.status,value:o.statusName}),o.equipmentType&&r.push({name:a.type,value:o.equipmentType}),o.extra?.length)){[...new Set(o.extra.map(e=>e.property))].forEach(e=>{const t=o.extra.filter(t=>t.property===e).map(e=>e.value||"").join(", ");r.push({name:ee(e),value:t})})}e.entities?.forEach(e=>{e.data?.forEach(e=>{if("Removed"===e.property)return;if(""===e.newValue&&!e.tagTranslate)return;const o=W(e,n,t?.translateProperty),s=X(e,null,n,a,t);s&&r.push({name:o,value:s})})}),e.entities?.forEach(e=>{if(e.association?.length){const t=e.association.filter(e=>""!==e.id).map(e=>{const t=Q(e);return`(${e.softwareName||e.type}) ${t}`});t.length&&r.push({name:a.references,value:t.join(", ")})}}),o?.isElectronicSigned&&r.push({name:a.security,value:"🛡️ "+a.electronicSigned}),r.push({name:a.accomplishedBy,value:e.userName?`${e.userName} (${e.userEmail})`:e.userEmail});const s=t?.formatDate?t.formatDate(e.dateTime):te(e.dateTime);return r.push({name:a.accomplishedIn,value:s}),r}function Q(e){return e.code&&e.name&&e.code!==e.name?`${e.code} ${e.name}`:e.name||e.code||""}function W(e,t,r){if(e.propertyCustomName)return e.propertyCustomName;const a=ee(e.property);return r?r(t,a):a}function X(e,t,r,a,n){if(e.propertyResource||(e.propertyResource=t?`${t.propertyResource}.${e.property}`:e.property),e.children?.length){if(e.newValue){const t=W(e,r,n?.translateProperty),o=function(e,t){switch(e.state){case"Added":return t.stateAdded;case"Modified":return e.children?.some(e=>"Removed"===e.property)?t.stateRemoved:t.stateModified;default:return""}}(e,a);let s=`${t}: "${Y(e,"newValue",a,n)}" ${o}`;const i=e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,X(t,e,r,a,n)));return i.some(Boolean)&&(s+="\n"+i.filter(Boolean).join("\n")),s}return e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,X(t,e,r,a,n))).filter(Boolean).join("\n")}if("Removed"===e.property)return"";if("Modified"===e.state){const o=Y(e,"oldValue",a,n),s=Y(e,"newValue",a,n);return`${t?W(e,r,n?.translateProperty)+": ":""}${a.changedFrom} "${o}" ${a.changedTo} "${s}"`}const o=Y(e,"newValue",a,n);return t?`${W(e,r,n?.translateProperty)}: ${o}`:o}function Y(e,t,r,a){const n=e[t];return null==n||""===n?"Modified"===e.state||"Added"===e.state||"Unchanged"===e.state?r.uninformed:"":"string"==typeof n&&function(e){if("string"!=typeof e)return!1;if(!/^\d{4}[-/]\d{2}[-/]\d{2}/.test(e))return!1;const t=new Date(e);return!isNaN(t.getTime())}(n)?a?.formatDate?a.formatDate(n):te(n):String(n)}function ee(e){return e.replace(/([A-Z])/g,(e,t,r)=>`${r>0?"-":""}${t.toLowerCase()}`)}function te(e){try{return new Date(e).toLocaleString()}catch{return e}}const re={event:"Evento",entityName:"Item",description:C.t("audit_description"),justification:"Justificativa",status:"Status",type:"Tipo",references:C.t("audit_references"),security:C.t("audit_security"),electronicSigned:C.t("audit_esign"),accomplishedBy:"Realizado por",accomplishedIn:"Realizado em",changedFrom:"de",changedTo:"para",uninformed:C.t("audit_not_informed"),stateAdded:"(adicionado)",stateModified:"(modificado)",stateRemoved:"(removido)"};function ae({documentId:r,onFetchDetails:s,onClose:i,labels:d,translateProperty:l,translatePropertyValue:c,formatDate:m}){const[u,p]=a(!1),[h,g]=a([]),[x,v]=a(null),y=n(async e=>{p(!0),v(null);try{const t=K(await s(e),{translateProperty:l,translatePropertyValue:c,formatDate:m,labels:d});g(t)}catch(t){v("Erro ao carregar detalhes da trilha de auditoria."),g([])}finally{p(!1)}},[s,l,c,m,d]);return o(()=>{r&&y(r)},[r,y]),r?t("div",{className:"flex flex-col h-full bg-background",children:[t("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-muted/30",children:[e("h3",{className:"text-sm font-semibold text-foreground",children:"Detalhes da Auditoria"}),e($,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:i,children:e(f,{className:"h-4 w-4"})})]}),e("div",{className:"flex-1 overflow-y-auto",children:u?t("div",{className:"flex items-center justify-center p-6",children:[e(H,{size:"md"}),e("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando detalhes..."})]}):x?e("div",{className:"p-6 text-sm text-destructive",children:x}):e("table",{className:"w-full text-xs",children:e("tbody",{children:h.map((r,a)=>t("tr",{className:a%2==0?"bg-background":"bg-muted/20",children:[e("td",{className:"px-4 py-2.5 font-semibold text-foreground whitespace-nowrap align-top w-[180px] border-b border-border/50",children:r.name}),e("td",{className:"px-4 py-2.5 text-muted-foreground break-words border-b border-border/50",children:e("span",{dangerouslySetInnerHTML:{__html:r.value.replace(/\n/g,"<br />")}})})]},a))})})})]}):null}function ne({title:r,softwares:i,softwareId:d,permissions:l={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},callbacks:c,limit:m=2e3,currentUserId:u,labels:p,formatDate:f,anonymousLabel:b=C.t("anonymous")}){const{t:w}=E();r??w("audit_trail");const[N,I]=a(!0),[D,k]=a([]),[R,$]=a([]),[j,z]=a([]),[T,V]=a(null),[P,A]=a(!1),B=s(null),F=new Date;F.setHours(0,0,0,0);const[L,M]=a({software:i.find(e=>e.id===d)?.software||"",softwareId:d,event:"All",eventId:1,startDate:F,endDate:F,limit:m,softwares:i,userId:l.viewOnlyMyEvents&&!l.viewAllEvents?u:void 0});o(()=>{(async()=>{I(!0);try{const[e,t]=await Promise.all([c.onFetchEvents(L.softwareId),c.onFetchUsers?.()??Promise.resolve([])]);$(e),z(t),await _(L,e)}catch(e){}finally{I(!1)}})()},[]);const _=n(async(e,t)=>{try{const r=J((await c.onFetchTrails(e)).data,t||R,i,b);k(r)}catch(r){}},[c,R,i,b]),O=n(async e=>{I(!0),M(e);try{await _(e)}finally{I(!1)}},[_]),q=n(async e=>{try{const t=await c.onFetchEvents(e);$(t)}catch(t){}},[c]),Z=n(e=>{V(e.documentId),A(!0)},[]),G=n(()=>{A(!1),V(null)},[]),K=n(async()=>{const e={...L,startDate:F,endDate:F,eventId:1,userId:l.viewAllEvents?void 0:u};M(e),I(!0);try{await _(e)}finally{I(!1)}},[L,_]),Q=n(e=>{c.onExport?.(e,D)},[c,D]),W=n(e=>{try{return new Date(e).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}},[]);return t("div",{className:"flex flex-col h-full",children:[e("div",{className:"p-3",children:e(U,{queryParams:L,events:R,softwares:i,users:j,permissions:l,isLoading:N,onFilter:O,onReset:K,onExport:l.download?Q:void 0,onSoftwareChange:q})}),t("div",{className:"flex flex-1 min-h-0 relative",children:[t("div",{className:S("flex-1 overflow-auto transition-all duration-300",P?"mr-[400px]":""),children:[N?t("div",{className:"flex items-center justify-center h-64",children:[e(H,{size:"md"}),e("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando trilha de auditoria..."})]}):0===D.length?t("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground",children:[e(h,{className:"h-12 w-12 mb-3 opacity-30"}),e("p",{className:"text-sm",children:"Nenhum registro encontrado"}),e("p",{className:"text-xs mt-1",children:"Ajuste os filtros e tente novamente"})]}):t("table",{className:"w-full text-xs border-collapse",children:[e("thead",{className:"sticky top-0 z-10",children:t("tr",{className:"bg-muted/60 border-b border-border",children:[e("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:t("div",{className:"flex items-center gap-1.5",children:[e(g,{className:"h-3 w-3"}),"Módulo"]})}),e("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:t("div",{className:"flex items-center gap-1.5",children:[e(x,{className:"h-3 w-3"}),"Data"]})}),e("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:t("div",{className:"flex items-center gap-1.5",children:[e(v,{className:"h-3 w-3"}),"Usuário"]})}),e("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:t("div",{className:"flex items-center gap-1.5",children:[e(h,{className:"h-3 w-3"}),"Evento"]})}),e("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:"Item"}),e("th",{className:"px-3 py-2 w-10"})]})}),e("tbody",{children:D.map((r,a)=>t("tr",{onClick:()=>Z(r),className:S("cursor-pointer border-b border-border/50 transition-colors","hover:bg-accent/50",T===r.documentId&&"bg-accent",a%2==0?"bg-background":"bg-muted/10"),children:[e("td",{className:"px-3 py-2 text-foreground",children:r.translatedSoftware}),e("td",{className:"px-3 py-2 text-muted-foreground whitespace-nowrap",children:r.date?W(r.date.toISOString()):"—"}),e("td",{className:"px-3 py-2 text-foreground",children:r.user}),e("td",{className:"px-3 py-2 text-foreground",children:r.translatedEvent}),e("td",{className:"px-3 py-2 text-foreground truncate max-w-[200px]",title:r.entityName,children:r.entityName}),e("td",{className:"px-3 py-2",children:e(y,{className:"h-3.5 w-3.5 text-muted-foreground"})})]},r.documentId||a))})]}),!N&&D.length>0&&t("div",{className:"px-3 py-2 text-xs text-muted-foreground border-t border-border bg-muted/20",children:[D.length," registro",1!==D.length?"s":""]})]}),e("div",{ref:B,className:S("fixed right-0 top-0 h-full w-[400px] border-l border-border bg-background shadow-lg z-30","transition-transform duration-300 ease-in-out",P?"translate-x-0":"translate-x-full"),children:P&&e(ae,{documentId:T,onFetchDetails:c.onFetchDetails,onClose:G,labels:p,translateProperty:c.translateProperty,translatePropertyValue:c.translatePropertyValue,formatDate:f||W})})]})]})}export{ae as AuditTrailDetails,U as AuditTrailFilter,ne as AuditTrailPage,K as buildDetailRows,ee as camelToDash,J as processTrails};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useState as a,useCallback as r,useEffect as n,useRef as s}from"react";import{RotateCcw as l,Download as o,Filter as i,X as d,FileText as c,Layers as m,Clock as u,User as p,Eye as f}from"lucide-react";import{Label as h,Select as x,SelectTrigger as v,SelectValue as g,SelectContent as y,SelectItem as w,Input as N,Button as b,Spinner as D,cn as E}from"forlogic-core";import I from"i18next";import{useTranslation as S}from"react-i18next";function $({queryParams:n,events:s,softwares:d,users:c=[],permissions:m={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},isLoading:u=!1,onFilter:p,onReset:f,onExport:D,onSoftwareChange:E}){const[I,S]=a(n.softwareId),[$,A]=a(n.eventId),[R,P]=a(n.userId||"all"),[T,j]=a(C(n.startDate)),[V,k]=a(C(n.endDate)),F=r(e=>{const t=parseInt(e);S(t),E?.(t)},[E]),M=r(()=>{p({...n,softwareId:I,eventId:$,userId:"all"===R?void 0:R,startDate:new Date(T),endDate:new Date(V),software:d.find(e=>e.id===I)?.software||n.software,event:s.find(e=>e.id===$)?.name||n.event})},[n,I,$,R,T,V,d,s,p]),z=r(()=>{const e=new Date;e.setHours(0,0,0,0),j(C(e)),k(C(e)),A(n.eventId),m.viewAllEvents&&P("all"),f?.()},[n.eventId,m.viewAllEvents,f]),_=m.viewOnlyMyEvents&&!m.viewAllEvents,L=I&&$&&T&&V;return e("div",{className:"flex flex-wrap items-end gap-3 rounded-lg border border-border bg-card p-3",children:[e("div",{className:"flex flex-col gap-1 min-w-[180px]",children:[t(h,{className:"text-xs text-muted-foreground",children:"Módulo *"}),e(x,{value:String(I),onValueChange:F,disabled:u,children:[t(v,{className:"h-8 text-xs",children:t(g,{placeholder:"Selecione..."})}),t(y,{children:d.map(e=>t(w,{value:String(e.id),className:"text-xs",children:e.translation},e.id))})]})]}),e("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[t(h,{className:"text-xs text-muted-foreground",children:"Evento *"}),e(x,{value:String($),onValueChange:e=>A(parseInt(e)),disabled:u,children:[t(v,{className:"h-8 text-xs",children:t(g,{placeholder:"Selecione..."})}),t(y,{children:s.map(e=>t(w,{value:String(e.id),className:"text-xs",children:e.translation},e.id))})]})]}),e("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[t(h,{className:"text-xs text-muted-foreground",children:"Usuário *"}),e(x,{value:R,onValueChange:P,disabled:u||_,children:[t(v,{className:"h-8 text-xs",children:t(g,{placeholder:"Selecione..."})}),e(y,{children:[t(w,{value:"all",className:"text-xs",children:"Todos"}),c.map(e=>t(w,{value:e.id,className:"text-xs",children:e.name},e.id))]})]})]}),e("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[t(h,{className:"text-xs text-muted-foreground",children:"De *"}),t(N,{type:"date",value:T,onChange:e=>j(e.target.value),className:"h-8 text-xs",max:V,disabled:u})]}),e("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[t(h,{className:"text-xs text-muted-foreground",children:"Até *"}),t(N,{type:"date",value:V,onChange:e=>k(e.target.value),className:"h-8 text-xs",min:T,disabled:u})]}),e("div",{className:"flex items-center gap-2 ml-auto",children:[e(b,{variant:"outline",size:"sm",onClick:z,disabled:u,children:[t(l,{className:"h-3.5 w-3.5 mr-1"}),"Limpar"]}),m.download&&D&&e(b,{variant:"outline",size:"sm",onClick:()=>D("xlsx"),disabled:u,children:[t(o,{className:"h-3.5 w-3.5 mr-1"}),"Exportar"]}),e(b,{size:"sm",onClick:M,disabled:u||!L,children:[t(i,{className:"h-3.5 w-3.5 mr-1"}),"Filtrar"]})]})]})}function C(e){return(e instanceof Date?e:new Date(e)).toISOString().split("T")[0]}function A(e,t,a,r="Anônimo"){return e.map(e=>({...e,translatedSoftware:P(e.software,a),user:e.userEmail||e.userName||r,translatedEvent:R(e.eventName,t),date:new Date(e.dateTime)})).sort((e,t)=>(t.date?.getTime()??0)-(e.date?.getTime()??0))}function R(e,t){const a=t.find(t=>t.name===e);return a?.translation||e}function P(e,t){const a=e.includes(".")?e.split(".").pop():e,r=t.find(e=>e.software===a);return r?.translation||a}function T(e,t){const a=[],r={..._,...t?.labels},n=e.eventName;a.push({name:r.event,value:n});const s=e.entities?.[0];if(s&&(a.push({name:r.entityName,value:j(s)}),s.description&&a.push({name:r.description,value:s.description}),s.justification&&a.push({name:r.justification,value:s.justification}),s.statusName&&a.push({name:r.status,value:s.statusName}),s.equipmentType&&a.push({name:r.type,value:s.equipmentType}),s.extra?.length)){[...new Set(s.extra.map(e=>e.property))].forEach(e=>{const t=s.extra.filter(t=>t.property===e).map(e=>e.value||"").join(", ");a.push({name:M(e),value:t})})}e.entities?.forEach(e=>{e.data?.forEach(e=>{if("Removed"===e.property)return;if(""===e.newValue&&!e.tagTranslate)return;const s=V(e,n,t?.translateProperty),l=k(e,null,n,r,t);l&&a.push({name:s,value:l})})}),e.entities?.forEach(e=>{if(e.association?.length){const t=e.association.filter(e=>""!==e.id).map(e=>{const t=j(e);return`(${e.softwareName||e.type}) ${t}`});t.length&&a.push({name:r.references,value:t.join(", ")})}}),s?.isElectronicSigned&&a.push({name:r.security,value:"🛡️ "+r.electronicSigned}),a.push({name:r.accomplishedBy,value:e.userName?`${e.userName} (${e.userEmail})`:e.userEmail});const l=t?.formatDate?t.formatDate(e.dateTime):z(e.dateTime);return a.push({name:r.accomplishedIn,value:l}),a}function j(e){return e.code&&e.name&&e.code!==e.name?`${e.code} ${e.name}`:e.name||e.code||""}function V(e,t,a){if(e.propertyCustomName)return e.propertyCustomName;const r=M(e.property);return a?a(t,r):r}function k(e,t,a,r,n){if(e.propertyResource||(e.propertyResource=t?`${t.propertyResource}.${e.property}`:e.property),e.children?.length){if(e.newValue){const t=V(e,a,n?.translateProperty),s=function(e,t){switch(e.state){case"Added":return t.stateAdded;case"Modified":return e.children?.some(e=>"Removed"===e.property)?t.stateRemoved:t.stateModified;default:return""}}(e,r);let l=`${t}: "${F(e,"newValue",r,n)}" ${s}`;const o=e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,k(t,e,a,r,n)));return o.some(Boolean)&&(l+="\n"+o.filter(Boolean).join("\n")),l}return e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,k(t,e,a,r,n))).filter(Boolean).join("\n")}if("Removed"===e.property)return"";if("Modified"===e.state){const s=F(e,"oldValue",r,n),l=F(e,"newValue",r,n);return`${t?V(e,a,n?.translateProperty)+": ":""}${r.changedFrom} "${s}" ${r.changedTo} "${l}"`}const s=F(e,"newValue",r,n);return t?`${V(e,a,n?.translateProperty)}: ${s}`:s}function F(e,t,a,r){const n=e[t];return null==n||""===n?"Modified"===e.state||"Added"===e.state||"Unchanged"===e.state?a.uninformed:"":"string"==typeof n&&function(e){if("string"!=typeof e)return!1;if(!/^\d{4}[-/]\d{2}[-/]\d{2}/.test(e))return!1;const t=new Date(e);return!isNaN(t.getTime())}(n)?r?.formatDate?r.formatDate(n):z(n):String(n)}function M(e){return e.replace(/([A-Z])/g,(e,t,a)=>`${a>0?"-":""}${t.toLowerCase()}`)}function z(e){try{return new Date(e).toLocaleString()}catch{return e}}const _={event:"Evento",entityName:"Item",description:I.t("audit_description"),justification:"Justificativa",status:"Status",type:"Tipo",references:I.t("audit_references"),security:I.t("audit_security"),electronicSigned:I.t("audit_esign"),accomplishedBy:"Realizado por",accomplishedIn:"Realizado em",changedFrom:"de",changedTo:"para",uninformed:I.t("audit_not_informed"),stateAdded:"(adicionado)",stateModified:"(modificado)",stateRemoved:"(removido)"};function L({documentId:s,onFetchDetails:l,onClose:o,labels:i,translateProperty:c,translatePropertyValue:m,formatDate:u}){const[p,f]=a(!1),[h,x]=a([]),[v,g]=a(null),y=r(async e=>{f(!0),g(null);try{const t=T(await l(e),{translateProperty:c,translatePropertyValue:m,formatDate:u,labels:i});x(t)}catch(t){g("Erro ao carregar detalhes da trilha de auditoria."),x([])}finally{f(!1)}},[l,c,m,u,i]);return n(()=>{s&&y(s)},[s,y]),s?e("div",{className:"flex flex-col h-full bg-background",children:[e("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-muted/30",children:[t("h3",{className:"text-sm font-semibold text-foreground",children:"Detalhes da Auditoria"}),t(b,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:o,children:t(d,{className:"h-4 w-4"})})]}),t("div",{className:"flex-1 overflow-y-auto",children:p?e("div",{className:"flex items-center justify-center p-6",children:[t(D,{size:"md"}),t("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando detalhes..."})]}):v?t("div",{className:"p-6 text-sm text-destructive",children:v}):t("table",{className:"w-full text-xs",children:t("tbody",{children:h.map((a,r)=>e("tr",{className:r%2==0?"bg-background":"bg-muted/20",children:[t("td",{className:"px-4 py-2.5 font-semibold text-foreground whitespace-nowrap align-top w-[180px] border-b border-border/50",children:a.name}),t("td",{className:"px-4 py-2.5 text-muted-foreground break-words border-b border-border/50",children:t("span",{dangerouslySetInnerHTML:{__html:a.value.replace(/\n/g,"<br />")}})})]},r))})})})]}):null}function B({title:l,softwares:o,softwareId:i,permissions:d={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},callbacks:h,limit:x=2e3,currentUserId:v,labels:g,formatDate:y,anonymousLabel:w=I.t("anonymous")}){const{t:N}=S();l??N("audit_trail");const[b,C]=a(!0),[R,P]=a([]),[T,j]=a([]),[V,k]=a([]),[F,M]=a(null),[z,_]=a(!1),B=s(null),O=new Date;O.setHours(0,0,0,0);const[U,q]=a({software:o.find(e=>e.id===i)?.software||"",softwareId:i,event:"All",eventId:1,startDate:O,endDate:O,limit:x,softwares:o,userId:d.viewOnlyMyEvents&&!d.viewAllEvents?v:void 0});n(()=>{(async()=>{C(!0);try{const[e,t]=await Promise.all([h.onFetchEvents(U.softwareId),h.onFetchUsers?.()??Promise.resolve([])]);j(e),k(t),await H(U,e)}catch(e){}finally{C(!1)}})()},[]);const H=r(async(e,t)=>{try{const a=A((await h.onFetchTrails(e)).data,t||T,o,w);P(a)}catch(a){}},[h,T,o,w]),J=r(async e=>{C(!0),q(e);try{await H(e)}finally{C(!1)}},[H]),Z=r(async e=>{try{const t=await h.onFetchEvents(e);j(t)}catch(t){}},[h]),G=r(e=>{M(e.documentId),_(!0)},[]),K=r(()=>{_(!1),M(null)},[]),Q=r(async()=>{const e={...U,startDate:O,endDate:O,eventId:1,userId:d.viewAllEvents?void 0:v};q(e),C(!0);try{await H(e)}finally{C(!1)}},[U,H]),W=r(e=>{h.onExport?.(e,R)},[h,R]),X=r(e=>{try{return new Date(e).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}},[]);return e("div",{className:"flex flex-col h-full",children:[t("div",{className:"p-3",children:t($,{queryParams:U,events:T,softwares:o,users:V,permissions:d,isLoading:b,onFilter:J,onReset:Q,onExport:d.download?W:void 0,onSoftwareChange:Z})}),e("div",{className:"flex flex-1 min-h-0 relative",children:[e("div",{className:E("flex-1 overflow-auto transition-all duration-300",z?"mr-[400px]":""),children:[b?e("div",{className:"flex items-center justify-center h-64",children:[t(D,{size:"md"}),t("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando trilha de auditoria..."})]}):0===R.length?e("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground",children:[t(c,{className:"h-12 w-12 mb-3 opacity-30"}),t("p",{className:"text-sm",children:"Nenhum registro encontrado"}),t("p",{className:"text-xs mt-1",children:"Ajuste os filtros e tente novamente"})]}):e("table",{className:"w-full text-xs border-collapse",children:[t("thead",{className:"sticky top-0 z-10",children:e("tr",{className:"bg-muted/60 border-b border-border",children:[t("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e("div",{className:"flex items-center gap-1.5",children:[t(m,{className:"h-3 w-3"}),"Módulo"]})}),t("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e("div",{className:"flex items-center gap-1.5",children:[t(u,{className:"h-3 w-3"}),"Data"]})}),t("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e("div",{className:"flex items-center gap-1.5",children:[t(p,{className:"h-3 w-3"}),"Usuário"]})}),t("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e("div",{className:"flex items-center gap-1.5",children:[t(c,{className:"h-3 w-3"}),"Evento"]})}),t("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:"Item"}),t("th",{className:"px-3 py-2 w-10"})]})}),t("tbody",{children:R.map((a,r)=>e("tr",{onClick:()=>G(a),className:E("cursor-pointer border-b border-border/50 transition-colors","hover:bg-accent/50",F===a.documentId&&"bg-accent",r%2==0?"bg-background":"bg-muted/10"),children:[t("td",{className:"px-3 py-2 text-foreground",children:a.translatedSoftware}),t("td",{className:"px-3 py-2 text-muted-foreground whitespace-nowrap",children:a.date?X(a.date.toISOString()):"—"}),t("td",{className:"px-3 py-2 text-foreground",children:a.user}),t("td",{className:"px-3 py-2 text-foreground",children:a.translatedEvent}),t("td",{className:"px-3 py-2 text-foreground truncate max-w-[200px]",title:a.entityName,children:a.entityName}),t("td",{className:"px-3 py-2",children:t(f,{className:"h-3.5 w-3.5 text-muted-foreground"})})]},a.documentId||r))})]}),!b&&R.length>0&&e("div",{className:"px-3 py-2 text-xs text-muted-foreground border-t border-border bg-muted/20",children:[R.length," registro",1!==R.length?"s":""]})]}),t("div",{ref:B,className:E("fixed right-0 top-0 h-full w-[400px] border-l border-border bg-background shadow-lg z-30","transition-transform duration-300 ease-in-out",z?"translate-x-0":"translate-x-full"),children:z&&t(L,{documentId:F,onFetchDetails:h.onFetchDetails,onClose:K,labels:g,translateProperty:h.translateProperty,translatePropertyValue:h.translatePropertyValue,formatDate:y||X})})]})]})}export{L as AuditTrailDetails,$ as AuditTrailFilter,B as AuditTrailPage,T as buildDetailRows,M as camelToDash,A as processTrails};
@@ -1 +1 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("lucide-react"),r=require("@radix-ui/react-slot"),s=require("class-variance-authority"),n=require("clsx"),o=require("tailwind-merge");require("date-fns"),require("sonner");var i=require("@radix-ui/react-label"),l=require("@radix-ui/react-select"),d=require("i18next"),c=require("react-i18next");function u(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(a){if("default"!==a){var r=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,r.get?r:{enumerable:!0,get:function(){return e[a]}})}}),t.default=e,Object.freeze(t)}var m=u(t),x=u(i),p=u(l);function f(...e){return o.twMerge(n.clsx(e))}const h=s.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{primary:"bg-primary text-primary-foreground hover:bg-primary-hover shadow-sm hover:shadow-md active:scale-[0.98]",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary-hover border border-input shadow-sm",tertiary:"bg-background text-foreground hover:bg-accent hover:text-accent-foreground border border-border",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground",subtle:"text-muted-foreground hover:text-foreground hover:bg-accent/50",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm hover:shadow-md",danger:"bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm hover:shadow-md",link:"text-primary underline-offset-4 hover:underline",icon:"bg-transparent border border-input hover:bg-accent hover:text-accent-foreground p-2",loading:"bg-primary/50 text-primary-foreground cursor-wait",default:"bg-primary text-primary-foreground hover:bg-primary/90",action:"bg-primary/10 text-primary hover:bg-primary/20 border border-primary/30","icon-only":"bg-transparent border border-input hover:bg-accent hover:text-accent-foreground p-2","external-link":"bg-transparent text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors","action-primary":"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm","action-secondary":"bg-secondary text-secondary-foreground hover:bg-secondary/80 border border-input"},size:{sm:"h-8 px-3 text-xs rounded-lg",md:"h-10 px-4 py-2 text-sm rounded-md",lg:"h-12 px-8 text-base rounded-lg",xl:"h-14 px-10 text-lg rounded-lg",icon:"h-10 w-10","icon-sm":"h-8 w-8","icon-xs":"h-6 w-6",default:"h-10 px-4 py-2"}},defaultVariants:{variant:"primary",size:"md"}}),g=m.forwardRef(({className:t,variant:a,size:s,asChild:n=!1,...o},i)=>{const l=n?r.Slot:"button";return e.jsx(l,{className:f(h({variant:a,size:s,className:t})),ref:i,...o})});g.displayName="Button";const v=s.cva("text-xs font-medium leading-none text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),y=m.forwardRef(({className:t,...a},r)=>e.jsx(x.Root,{ref:r,className:f(v(),t),...a}));y.displayName=x.Root.displayName;const b=m.createContext({showCheck:!1}),w=({showCheck:t=!1,...a})=>e.jsx(b.Provider,{value:{showCheck:t},children:e.jsx(p.Root,{...a})}),j=p.Value,N=m.forwardRef(({className:t,children:r,...s},n)=>e.jsxs(p.Trigger,{ref:n,className:f("flex h-10 w-full items-center justify-between rounded-lg border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground hover:border-primary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors [&>span]:line-clamp-1",t),...s,children:[r,e.jsx(p.Icon,{asChild:!0,children:e.jsx(a.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));N.displayName=p.Trigger.displayName;const C=m.forwardRef(({className:t,...r},s)=>e.jsx(p.ScrollUpButton,{ref:s,className:f("flex cursor-default items-center justify-center py-1",t),...r,children:e.jsx(a.ChevronUp,{className:"h-4 w-4"})}));C.displayName=p.ScrollUpButton.displayName;const k=m.forwardRef(({className:t,...r},s)=>e.jsx(p.ScrollDownButton,{ref:s,className:f("flex cursor-default items-center justify-center py-1",t),...r,children:e.jsx(a.ChevronDown,{className:"h-4 w-4"})}));k.displayName=p.ScrollDownButton.displayName;const S=m.forwardRef(({className:t,children:a,position:r="popper",container:s,collisionBoundary:n,...o},i)=>e.jsx(p.Portal,{container:s,children:e.jsxs(p.Content,{ref:i,className:f("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===r&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:r,collisionBoundary:n,...o,children:[e.jsx(C,{}),e.jsx(p.Viewport,{className:f("p-1","popper"===r&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),e.jsx(k,{})]})}));S.displayName=p.Content.displayName;m.forwardRef(({className:t,...a},r)=>e.jsx(p.Label,{ref:r,className:f("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...a})).displayName=p.Label.displayName;const D=m.forwardRef(({className:t,children:r,...s},n)=>{const{showCheck:o}=m.useContext(b);return e.jsxs(p.Item,{ref:n,className:f("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",o?"pl-8":"pl-2","data-[state=checked]:bg-accent data-[state=checked]:text-accent-foreground data-[state=checked]:font-medium data-[state=checked]:border-l-2 data-[state=checked]:border-primary",o?"data-[state=checked]:pl-[calc(2rem-2px)]":"data-[state=checked]:pl-[calc(0.5rem-2px)]",t),...s,children:[o&&e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(p.ItemIndicator,{children:e.jsx(a.Check,{className:"h-4 w-4"})})}),e.jsx(p.ItemText,{children:r})]})});D.displayName=p.Item.displayName;m.forwardRef(({className:t,...a},r)=>e.jsx(p.Separator,{ref:r,className:f("-mx-1 my-1 h-px bg-muted",t),...a})).displayName=p.Separator.displayName;const I=m.forwardRef(({className:t,type:a,showCharCount:r,maxLength:s,onChange:n,...o},i)=>{const[l,d]=m.useState(0);m.useEffect(()=>{"string"==typeof o.value?d(o.value.length):"string"==typeof o.defaultValue&&d(o.defaultValue.length)},[o.value,o.defaultValue]);return e.jsxs("div",{className:"w-full",children:[e.jsx("input",{type:a,className:f("flex h-10 w-full rounded-lg border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors md:text-sm",t),ref:i,maxLength:s,onChange:e=>{d(e.target.value.length),n?.(e)},...o}),r&&s&&e.jsxs("div",{className:"text-right text-xs text-muted-foreground mt-1",children:[l," / ",s]})]})});function E({queryParams:r,events:s,softwares:n,users:o=[],permissions:i={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},isLoading:l=!1,onFilter:d,onReset:c,onExport:u,onSoftwareChange:m}){const[x,p]=t.useState(r.softwareId),[f,h]=t.useState(r.eventId),[v,b]=t.useState(r.userId||"all"),[C,k]=t.useState(R(r.startDate)),[E,T]=t.useState(R(r.endDate)),$=t.useCallback(e=>{const t=parseInt(e);p(t),m?.(t)},[m]),P=t.useCallback(()=>{d({...r,softwareId:x,eventId:f,userId:"all"===v?void 0:v,startDate:new Date(C),endDate:new Date(E),software:n.find(e=>e.id===x)?.software||r.software,event:s.find(e=>e.id===f)?.name||r.event})},[r,x,f,v,C,E,n,s,d]),z=t.useCallback(()=>{const e=new Date;e.setHours(0,0,0,0),k(R(e)),T(R(e)),h(r.eventId),i.viewAllEvents&&b("all"),c?.()},[r.eventId,i.viewAllEvents,c]),A=i.viewOnlyMyEvents&&!i.viewAllEvents,V=x&&f&&C&&E;return e.jsxs("div",{className:"flex flex-wrap items-end gap-3 rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"flex flex-col gap-1 min-w-[180px]",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Módulo *"}),e.jsxs(w,{value:String(x),onValueChange:$,disabled:l,children:[e.jsx(N,{className:"h-8 text-xs",children:e.jsx(j,{placeholder:"Selecione..."})}),e.jsx(S,{children:n.map(t=>e.jsx(D,{value:String(t.id),className:"text-xs",children:t.translation},t.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Evento *"}),e.jsxs(w,{value:String(f),onValueChange:e=>h(parseInt(e)),disabled:l,children:[e.jsx(N,{className:"h-8 text-xs",children:e.jsx(j,{placeholder:"Selecione..."})}),e.jsx(S,{children:s.map(t=>e.jsx(D,{value:String(t.id),className:"text-xs",children:t.translation},t.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Usuário *"}),e.jsxs(w,{value:v,onValueChange:b,disabled:l||A,children:[e.jsx(N,{className:"h-8 text-xs",children:e.jsx(j,{placeholder:"Selecione..."})}),e.jsxs(S,{children:[e.jsx(D,{value:"all",className:"text-xs",children:"Todos"}),o.map(t=>e.jsx(D,{value:t.id,className:"text-xs",children:t.name},t.id))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"De *"}),e.jsx(I,{type:"date",value:C,onChange:e=>k(e.target.value),className:"h-8 text-xs",max:E,disabled:l})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Até *"}),e.jsx(I,{type:"date",value:E,onChange:e=>T(e.target.value),className:"h-8 text-xs",min:C,disabled:l})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs(g,{variant:"outline",size:"sm",onClick:z,disabled:l,children:[e.jsx(a.RotateCcw,{className:"h-3.5 w-3.5 mr-1"}),"Limpar"]}),i.download&&u&&e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>u("xlsx"),disabled:l,children:[e.jsx(a.Download,{className:"h-3.5 w-3.5 mr-1"}),"Exportar"]}),e.jsxs(g,{size:"sm",onClick:P,disabled:l||!V,children:[e.jsx(a.Filter,{className:"h-3.5 w-3.5 mr-1"}),"Filtrar"]})]})]})}function R(e){return(e instanceof Date?e:new Date(e)).toISOString().split("T")[0]}I.displayName="Input";const T={sm:"h-4 w-4",md:"h-6 w-6",lg:"h-8 w-8"};function $({size:t="md",className:r}){return e.jsx(a.Loader2,{className:f("animate-spin text-muted-foreground",T[t],r)})}function P(e,t,a,r="Anônimo"){return e.map(e=>({...e,translatedSoftware:A(e.software,a),user:e.userEmail||e.userName||r,translatedEvent:z(e.eventName,t),date:new Date(e.dateTime)})).sort((e,t)=>(t.date?.getTime()??0)-(e.date?.getTime()??0))}function z(e,t){const a=t.find(t=>t.name===e);return a?.translation||e}function A(e,t){const a=e.includes(".")?e.split(".").pop():e,r=t.find(e=>e.software===a);return r?.translation||a}function V(e,t){const a=[],r={..._,...t?.labels},s=e.eventName;a.push({name:r.event,value:s});const n=e.entities?.[0];if(n&&(a.push({name:r.entityName,value:q(n)}),n.description&&a.push({name:r.description,value:n.description}),n.justification&&a.push({name:r.justification,value:n.justification}),n.statusName&&a.push({name:r.status,value:n.statusName}),n.equipmentType&&a.push({name:r.type,value:n.equipmentType}),n.extra?.length)){[...new Set(n.extra.map(e=>e.property))].forEach(e=>{const t=n.extra.filter(t=>t.property===e).map(e=>e.value||"").join(", ");a.push({name:M(e),value:t})})}e.entities?.forEach(e=>{e.data?.forEach(e=>{if("Removed"===e.property)return;if(""===e.newValue&&!e.tagTranslate)return;const n=F(e,s,t?.translateProperty),o=L(e,null,s,r,t);o&&a.push({name:n,value:o})})}),e.entities?.forEach(e=>{if(e.association?.length){const t=e.association.filter(e=>""!==e.id).map(e=>{const t=q(e);return`(${e.softwareName||e.type}) ${t}`});t.length&&a.push({name:r.references,value:t.join(", ")})}}),n?.isElectronicSigned&&a.push({name:r.security,value:"🛡️ "+r.electronicSigned}),a.push({name:r.accomplishedBy,value:e.userName?`${e.userName} (${e.userEmail})`:e.userEmail});const o=t?.formatDate?t.formatDate(e.dateTime):O(e.dateTime);return a.push({name:r.accomplishedIn,value:o}),a}function q(e){return e.code&&e.name&&e.code!==e.name?`${e.code} ${e.name}`:e.name||e.code||""}function F(e,t,a){if(e.propertyCustomName)return e.propertyCustomName;const r=M(e.property);return a?a(t,r):r}function L(e,t,a,r,s){if(e.propertyResource||(e.propertyResource=t?`${t.propertyResource}.${e.property}`:e.property),e.children?.length){if(e.newValue){const t=F(e,a,s?.translateProperty),n=function(e,t){switch(e.state){case"Added":return t.stateAdded;case"Modified":return e.children?.some(e=>"Removed"===e.property)?t.stateRemoved:t.stateModified;default:return""}}(e,r);let o=`${t}: "${B(e,"newValue",r,s)}" ${n}`;const i=e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,L(t,e,a,r,s)));return i.some(Boolean)&&(o+="\n"+i.filter(Boolean).join("\n")),o}return e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,L(t,e,a,r,s))).filter(Boolean).join("\n")}if("Removed"===e.property)return"";if("Modified"===e.state){const n=B(e,"oldValue",r,s),o=B(e,"newValue",r,s);return`${t?F(e,a,s?.translateProperty)+": ":""}${r.changedFrom} "${n}" ${r.changedTo} "${o}"`}const n=B(e,"newValue",r,s);return t?`${F(e,a,s?.translateProperty)}: ${n}`:n}function B(e,t,a,r){const s=e[t];return null==s||""===s?"Modified"===e.state||"Added"===e.state||"Unchanged"===e.state?a.uninformed:"":"string"==typeof s&&function(e){if("string"!=typeof e)return!1;if(!/^\d{4}[-/]\d{2}[-/]\d{2}/.test(e))return!1;const t=new Date(e);return!isNaN(t.getTime())}(s)?r?.formatDate?r.formatDate(s):O(s):String(s)}function M(e){return e.replace(/([A-Z])/g,(e,t,a)=>`${a>0?"-":""}${t.toLowerCase()}`)}function O(e){try{return new Date(e).toLocaleString()}catch{return e}}const _={event:"Evento",entityName:"Item",description:d.t("audit_description"),justification:"Justificativa",status:"Status",type:"Tipo",references:d.t("audit_references"),security:d.t("audit_security"),electronicSigned:d.t("audit_esign"),accomplishedBy:"Realizado por",accomplishedIn:"Realizado em",changedFrom:"de",changedTo:"para",uninformed:d.t("audit_not_informed"),stateAdded:"(adicionado)",stateModified:"(modificado)",stateRemoved:"(removido)"};function U({documentId:r,onFetchDetails:s,onClose:n,labels:o,translateProperty:i,translatePropertyValue:l,formatDate:d}){const[c,u]=t.useState(!1),[m,x]=t.useState([]),[p,f]=t.useState(null),h=t.useCallback(async e=>{u(!0),f(null);try{const t=V(await s(e),{translateProperty:i,translatePropertyValue:l,formatDate:d,labels:o});x(t)}catch(t){f("Erro ao carregar detalhes da trilha de auditoria."),x([])}finally{u(!1)}},[s,i,l,d,o]);return t.useEffect(()=>{r&&h(r)},[r,h]),r?e.jsxs("div",{className:"flex flex-col h-full bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-muted/30",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Detalhes da Auditoria"}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:n,children:e.jsx(a.X,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:c?e.jsxs("div",{className:"flex items-center justify-center p-6",children:[e.jsx($,{size:"md"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando detalhes..."})]}):p?e.jsx("div",{className:"p-6 text-sm text-destructive",children:p}):e.jsx("table",{className:"w-full text-xs",children:e.jsx("tbody",{children:m.map((t,a)=>e.jsxs("tr",{className:a%2==0?"bg-background":"bg-muted/20",children:[e.jsx("td",{className:"px-4 py-2.5 font-semibold text-foreground whitespace-nowrap align-top w-[180px] border-b border-border/50",children:t.name}),e.jsx("td",{className:"px-4 py-2.5 text-muted-foreground break-words border-b border-border/50",children:e.jsx("span",{dangerouslySetInnerHTML:{__html:t.value.replace(/\n/g,"<br />")}})})]},a))})})})]}):null}exports.AuditTrailDetails=U,exports.AuditTrailFilter=E,exports.AuditTrailPage=function({title:r,softwares:s,softwareId:n,permissions:o={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},callbacks:i,limit:l=2e3,currentUserId:u,labels:m,formatDate:x,anonymousLabel:p=d.t("anonymous")}){const{t:h}=c.useTranslation();r??h("audit_trail");const[g,v]=t.useState(!0),[y,b]=t.useState([]),[w,j]=t.useState([]),[N,C]=t.useState([]),[k,S]=t.useState(null),[D,I]=t.useState(!1),R=t.useRef(null),T=new Date;T.setHours(0,0,0,0);const[z,A]=t.useState({software:s.find(e=>e.id===n)?.software||"",softwareId:n,event:"All",eventId:1,startDate:T,endDate:T,limit:l,softwares:s,userId:o.viewOnlyMyEvents&&!o.viewAllEvents?u:void 0});t.useEffect(()=>{(async()=>{v(!0);try{const[e,t]=await Promise.all([i.onFetchEvents(z.softwareId),i.onFetchUsers?.()??Promise.resolve([])]);j(e),C(t),await V(z,e)}catch(e){}finally{v(!1)}})()},[]);const V=t.useCallback(async(e,t)=>{try{const a=P((await i.onFetchTrails(e)).data,t||w,s,p);b(a)}catch(a){}},[i,w,s,p]),q=t.useCallback(async e=>{v(!0),A(e);try{await V(e)}finally{v(!1)}},[V]),F=t.useCallback(async e=>{try{const t=await i.onFetchEvents(e);j(t)}catch(t){}},[i]),L=t.useCallback(e=>{S(e.documentId),I(!0)},[]),B=t.useCallback(()=>{I(!1),S(null)},[]),M=t.useCallback(async()=>{const e={...z,startDate:T,endDate:T,eventId:1,userId:o.viewAllEvents?void 0:u};A(e),v(!0);try{await V(e)}finally{v(!1)}},[z,V]),O=t.useCallback(e=>{i.onExport?.(e,y)},[i,y]),_=t.useCallback(e=>{try{return new Date(e).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}},[]);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"p-3",children:e.jsx(E,{queryParams:z,events:w,softwares:s,users:N,permissions:o,isLoading:g,onFilter:q,onReset:M,onExport:o.download?O:void 0,onSoftwareChange:F})}),e.jsxs("div",{className:"flex flex-1 min-h-0 relative",children:[e.jsxs("div",{className:f("flex-1 overflow-auto transition-all duration-300",D?"mr-[400px]":""),children:[g?e.jsxs("div",{className:"flex items-center justify-center h-64",children:[e.jsx($,{size:"md"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando trilha de auditoria..."})]}):0===y.length?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground",children:[e.jsx(a.FileText,{className:"h-12 w-12 mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"Nenhum registro encontrado"}),e.jsx("p",{className:"text-xs mt-1",children:"Ajuste os filtros e tente novamente"})]}):e.jsxs("table",{className:"w-full text-xs border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"bg-muted/60 border-b border-border",children:[e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.Layers,{className:"h-3 w-3"}),"Módulo"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.Clock,{className:"h-3 w-3"}),"Data"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.User,{className:"h-3 w-3"}),"Usuário"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.FileText,{className:"h-3 w-3"}),"Evento"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:"Item"}),e.jsx("th",{className:"px-3 py-2 w-10"})]})}),e.jsx("tbody",{children:y.map((t,r)=>e.jsxs("tr",{onClick:()=>L(t),className:f("cursor-pointer border-b border-border/50 transition-colors","hover:bg-accent/50",k===t.documentId&&"bg-accent",r%2==0?"bg-background":"bg-muted/10"),children:[e.jsx("td",{className:"px-3 py-2 text-foreground",children:t.translatedSoftware}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground whitespace-nowrap",children:t.date?_(t.date.toISOString()):"—"}),e.jsx("td",{className:"px-3 py-2 text-foreground",children:t.user}),e.jsx("td",{className:"px-3 py-2 text-foreground",children:t.translatedEvent}),e.jsx("td",{className:"px-3 py-2 text-foreground truncate max-w-[200px]",title:t.entityName,children:t.entityName}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(a.Eye,{className:"h-3.5 w-3.5 text-muted-foreground"})})]},t.documentId||r))})]}),!g&&y.length>0&&e.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground border-t border-border bg-muted/20",children:[y.length," registro",1!==y.length?"s":""]})]}),e.jsx("div",{ref:R,className:f("fixed right-0 top-0 h-full w-[400px] border-l border-border bg-background shadow-lg z-30","transition-transform duration-300 ease-in-out",D?"translate-x-0":"translate-x-full"),children:D&&e.jsx(U,{documentId:k,onFetchDetails:i.onFetchDetails,onClose:B,labels:m,translateProperty:i.translateProperty,translatePropertyValue:i.translatePropertyValue,formatDate:x||_})})]})]})},exports.buildDetailRows=V,exports.camelToDash=M,exports.processTrails=P;
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react"),a=require("lucide-react"),s=require("forlogic-core"),r=require("i18next"),n=require("react-i18next");function l({queryParams:r,events:n,softwares:l,users:i=[],permissions:d={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},isLoading:c=!1,onFilter:u,onReset:m,onExport:x,onSoftwareChange:p}){const[f,h]=t.useState(r.softwareId),[g,v]=t.useState(r.eventId),[y,j]=t.useState(r.userId||"all"),[w,N]=t.useState(o(r.startDate)),[b,S]=t.useState(o(r.endDate)),C=t.useCallback(e=>{const t=parseInt(e);h(t),p?.(t)},[p]),D=t.useCallback(()=>{u({...r,softwareId:f,eventId:g,userId:"all"===y?void 0:y,startDate:new Date(w),endDate:new Date(b),software:l.find(e=>e.id===f)?.software||r.software,event:n.find(e=>e.id===g)?.name||r.event})},[r,f,g,y,w,b,l,n,u]),I=t.useCallback(()=>{const e=new Date;e.setHours(0,0,0,0),N(o(e)),S(o(e)),v(r.eventId),d.viewAllEvents&&j("all"),m?.()},[r.eventId,d.viewAllEvents,m]),E=d.viewOnlyMyEvents&&!d.viewAllEvents,T=f&&g&&w&&b;return e.jsxs("div",{className:"flex flex-wrap items-end gap-3 rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"flex flex-col gap-1 min-w-[180px]",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Módulo *"}),e.jsxs(s.Select,{value:String(f),onValueChange:C,disabled:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Selecione..."})}),e.jsx(s.SelectContent,{children:l.map(t=>e.jsx(s.SelectItem,{value:String(t.id),className:"text-xs",children:t.translation},t.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Evento *"}),e.jsxs(s.Select,{value:String(g),onValueChange:e=>v(parseInt(e)),disabled:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Selecione..."})}),e.jsx(s.SelectContent,{children:n.map(t=>e.jsx(s.SelectItem,{value:String(t.id),className:"text-xs",children:t.translation},t.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[200px]",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Usuário *"}),e.jsxs(s.Select,{value:y,onValueChange:j,disabled:c||E,children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Selecione..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"all",className:"text-xs",children:"Todos"}),i.map(t=>e.jsx(s.SelectItem,{value:t.id,className:"text-xs",children:t.name},t.id))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"De *"}),e.jsx(s.Input,{type:"date",value:w,onChange:e=>N(e.target.value),className:"h-8 text-xs",max:b,disabled:c})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[150px]",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Até *"}),e.jsx(s.Input,{type:"date",value:b,onChange:e=>S(e.target.value),className:"h-8 text-xs",min:w,disabled:c})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:I,disabled:c,children:[e.jsx(a.RotateCcw,{className:"h-3.5 w-3.5 mr-1"}),"Limpar"]}),d.download&&x&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>x("xlsx"),disabled:c,children:[e.jsx(a.Download,{className:"h-3.5 w-3.5 mr-1"}),"Exportar"]}),e.jsxs(s.Button,{size:"sm",onClick:D,disabled:c||!T,children:[e.jsx(a.Filter,{className:"h-3.5 w-3.5 mr-1"}),"Filtrar"]})]})]})}function o(e){return(e instanceof Date?e:new Date(e)).toISOString().split("T")[0]}function i(e,t,a,s="Anônimo"){return e.map(e=>({...e,translatedSoftware:c(e.software,a),user:e.userEmail||e.userName||s,translatedEvent:d(e.eventName,t),date:new Date(e.dateTime)})).sort((e,t)=>(t.date?.getTime()??0)-(e.date?.getTime()??0))}function d(e,t){const a=t.find(t=>t.name===e);return a?.translation||e}function c(e,t){const a=e.includes(".")?e.split(".").pop():e,s=t.find(e=>e.software===a);return s?.translation||a}function u(e,t){const a=[],s={...v,...t?.labels},r=e.eventName;a.push({name:s.event,value:r});const n=e.entities?.[0];if(n&&(a.push({name:s.entityName,value:m(n)}),n.description&&a.push({name:s.description,value:n.description}),n.justification&&a.push({name:s.justification,value:n.justification}),n.statusName&&a.push({name:s.status,value:n.statusName}),n.equipmentType&&a.push({name:s.type,value:n.equipmentType}),n.extra?.length)){[...new Set(n.extra.map(e=>e.property))].forEach(e=>{const t=n.extra.filter(t=>t.property===e).map(e=>e.value||"").join(", ");a.push({name:h(e),value:t})})}e.entities?.forEach(e=>{e.data?.forEach(e=>{if("Removed"===e.property)return;if(""===e.newValue&&!e.tagTranslate)return;const n=x(e,r,t?.translateProperty),l=p(e,null,r,s,t);l&&a.push({name:n,value:l})})}),e.entities?.forEach(e=>{if(e.association?.length){const t=e.association.filter(e=>""!==e.id).map(e=>{const t=m(e);return`(${e.softwareName||e.type}) ${t}`});t.length&&a.push({name:s.references,value:t.join(", ")})}}),n?.isElectronicSigned&&a.push({name:s.security,value:"🛡️ "+s.electronicSigned}),a.push({name:s.accomplishedBy,value:e.userName?`${e.userName} (${e.userEmail})`:e.userEmail});const l=t?.formatDate?t.formatDate(e.dateTime):g(e.dateTime);return a.push({name:s.accomplishedIn,value:l}),a}function m(e){return e.code&&e.name&&e.code!==e.name?`${e.code} ${e.name}`:e.name||e.code||""}function x(e,t,a){if(e.propertyCustomName)return e.propertyCustomName;const s=h(e.property);return a?a(t,s):s}function p(e,t,a,s,r){if(e.propertyResource||(e.propertyResource=t?`${t.propertyResource}.${e.property}`:e.property),e.children?.length){if(e.newValue){const t=x(e,a,r?.translateProperty),n=function(e,t){switch(e.state){case"Added":return t.stateAdded;case"Modified":return e.children?.some(e=>"Removed"===e.property)?t.stateRemoved:t.stateModified;default:return""}}(e,s);let l=`${t}: "${f(e,"newValue",s,r)}" ${n}`;const o=e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,p(t,e,a,s,r)));return o.some(Boolean)&&(l+="\n"+o.filter(Boolean).join("\n")),l}return e.children.map(t=>(t.propertyResource=`${e.propertyResource}.${t.property}`,p(t,e,a,s,r))).filter(Boolean).join("\n")}if("Removed"===e.property)return"";if("Modified"===e.state){const n=f(e,"oldValue",s,r),l=f(e,"newValue",s,r);return`${t?x(e,a,r?.translateProperty)+": ":""}${s.changedFrom} "${n}" ${s.changedTo} "${l}"`}const n=f(e,"newValue",s,r);return t?`${x(e,a,r?.translateProperty)}: ${n}`:n}function f(e,t,a,s){const r=e[t];return null==r||""===r?"Modified"===e.state||"Added"===e.state||"Unchanged"===e.state?a.uninformed:"":"string"==typeof r&&function(e){if("string"!=typeof e)return!1;if(!/^\d{4}[-/]\d{2}[-/]\d{2}/.test(e))return!1;const t=new Date(e);return!isNaN(t.getTime())}(r)?s?.formatDate?s.formatDate(r):g(r):String(r)}function h(e){return e.replace(/([A-Z])/g,(e,t,a)=>`${a>0?"-":""}${t.toLowerCase()}`)}function g(e){try{return new Date(e).toLocaleString()}catch{return e}}const v={event:"Evento",entityName:"Item",description:r.t("audit_description"),justification:"Justificativa",status:"Status",type:"Tipo",references:r.t("audit_references"),security:r.t("audit_security"),electronicSigned:r.t("audit_esign"),accomplishedBy:"Realizado por",accomplishedIn:"Realizado em",changedFrom:"de",changedTo:"para",uninformed:r.t("audit_not_informed"),stateAdded:"(adicionado)",stateModified:"(modificado)",stateRemoved:"(removido)"};function y({documentId:r,onFetchDetails:n,onClose:l,labels:o,translateProperty:i,translatePropertyValue:d,formatDate:c}){const[m,x]=t.useState(!1),[p,f]=t.useState([]),[h,g]=t.useState(null),v=t.useCallback(async e=>{x(!0),g(null);try{const t=u(await n(e),{translateProperty:i,translatePropertyValue:d,formatDate:c,labels:o});f(t)}catch(t){g("Erro ao carregar detalhes da trilha de auditoria."),f([])}finally{x(!1)}},[n,i,d,c,o]);return t.useEffect(()=>{r&&v(r)},[r,v]),r?e.jsxs("div",{className:"flex flex-col h-full bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-muted/30",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Detalhes da Auditoria"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:l,children:e.jsx(a.X,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:m?e.jsxs("div",{className:"flex items-center justify-center p-6",children:[e.jsx(s.Spinner,{size:"md"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando detalhes..."})]}):h?e.jsx("div",{className:"p-6 text-sm text-destructive",children:h}):e.jsx("table",{className:"w-full text-xs",children:e.jsx("tbody",{children:p.map((t,a)=>e.jsxs("tr",{className:a%2==0?"bg-background":"bg-muted/20",children:[e.jsx("td",{className:"px-4 py-2.5 font-semibold text-foreground whitespace-nowrap align-top w-[180px] border-b border-border/50",children:t.name}),e.jsx("td",{className:"px-4 py-2.5 text-muted-foreground break-words border-b border-border/50",children:e.jsx("span",{dangerouslySetInnerHTML:{__html:t.value.replace(/\n/g,"<br />")}})})]},a))})})})]}):null}exports.AuditTrailDetails=y,exports.AuditTrailFilter=l,exports.AuditTrailPage=function({title:o,softwares:d,softwareId:c,permissions:u={viewAllEvents:!0,viewOnlyMyEvents:!1,download:!1},callbacks:m,limit:x=2e3,currentUserId:p,labels:f,formatDate:h,anonymousLabel:g=r.t("anonymous")}){const{t:v}=n.useTranslation();o??v("audit_trail");const[j,w]=t.useState(!0),[N,b]=t.useState([]),[S,C]=t.useState([]),[D,I]=t.useState([]),[E,T]=t.useState(null),[k,$]=t.useState(!1),A=t.useRef(null),R=new Date;R.setHours(0,0,0,0);const[P,F]=t.useState({software:d.find(e=>e.id===c)?.software||"",softwareId:c,event:"All",eventId:1,startDate:R,endDate:R,limit:x,softwares:d,userId:u.viewOnlyMyEvents&&!u.viewAllEvents?p:void 0});t.useEffect(()=>{(async()=>{w(!0);try{const[e,t]=await Promise.all([m.onFetchEvents(P.softwareId),m.onFetchUsers?.()??Promise.resolve([])]);C(e),I(t),await V(P,e)}catch(e){}finally{w(!1)}})()},[]);const V=t.useCallback(async(e,t)=>{try{const a=i((await m.onFetchTrails(e)).data,t||S,d,g);b(a)}catch(a){}},[m,S,d,g]),L=t.useCallback(async e=>{w(!0),F(e);try{await V(e)}finally{w(!1)}},[V]),M=t.useCallback(async e=>{try{const t=await m.onFetchEvents(e);C(t)}catch(t){}},[m]),q=t.useCallback(e=>{T(e.documentId),$(!0)},[]),z=t.useCallback(()=>{$(!1),T(null)},[]),B=t.useCallback(async()=>{const e={...P,startDate:R,endDate:R,eventId:1,userId:u.viewAllEvents?void 0:p};F(e),w(!0);try{await V(e)}finally{w(!1)}},[P,V]),_=t.useCallback(e=>{m.onExport?.(e,N)},[m,N]),O=t.useCallback(e=>{try{return new Date(e).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}},[]);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"p-3",children:e.jsx(l,{queryParams:P,events:S,softwares:d,users:D,permissions:u,isLoading:j,onFilter:L,onReset:B,onExport:u.download?_:void 0,onSoftwareChange:M})}),e.jsxs("div",{className:"flex flex-1 min-h-0 relative",children:[e.jsxs("div",{className:s.cn("flex-1 overflow-auto transition-all duration-300",k?"mr-[400px]":""),children:[j?e.jsxs("div",{className:"flex items-center justify-center h-64",children:[e.jsx(s.Spinner,{size:"md"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Carregando trilha de auditoria..."})]}):0===N.length?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground",children:[e.jsx(a.FileText,{className:"h-12 w-12 mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"Nenhum registro encontrado"}),e.jsx("p",{className:"text-xs mt-1",children:"Ajuste os filtros e tente novamente"})]}):e.jsxs("table",{className:"w-full text-xs border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"bg-muted/60 border-b border-border",children:[e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.Layers,{className:"h-3 w-3"}),"Módulo"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.Clock,{className:"h-3 w-3"}),"Data"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.User,{className:"h-3 w-3"}),"Usuário"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(a.FileText,{className:"h-3 w-3"}),"Evento"]})}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:"Item"}),e.jsx("th",{className:"px-3 py-2 w-10"})]})}),e.jsx("tbody",{children:N.map((t,r)=>e.jsxs("tr",{onClick:()=>q(t),className:s.cn("cursor-pointer border-b border-border/50 transition-colors","hover:bg-accent/50",E===t.documentId&&"bg-accent",r%2==0?"bg-background":"bg-muted/10"),children:[e.jsx("td",{className:"px-3 py-2 text-foreground",children:t.translatedSoftware}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground whitespace-nowrap",children:t.date?O(t.date.toISOString()):"—"}),e.jsx("td",{className:"px-3 py-2 text-foreground",children:t.user}),e.jsx("td",{className:"px-3 py-2 text-foreground",children:t.translatedEvent}),e.jsx("td",{className:"px-3 py-2 text-foreground truncate max-w-[200px]",title:t.entityName,children:t.entityName}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(a.Eye,{className:"h-3.5 w-3.5 text-muted-foreground"})})]},t.documentId||r))})]}),!j&&N.length>0&&e.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground border-t border-border bg-muted/20",children:[N.length," registro",1!==N.length?"s":""]})]}),e.jsx("div",{ref:A,className:s.cn("fixed right-0 top-0 h-full w-[400px] border-l border-border bg-background shadow-lg z-30","transition-transform duration-300 ease-in-out",k?"translate-x-0":"translate-x-full"),children:k&&e.jsx(y,{documentId:E,onFetchDetails:m.onFetchDetails,onClose:z,labels:f,translateProperty:m.translateProperty,translatePropertyValue:m.translatePropertyValue,formatDate:h||O})})]})]})},exports.buildDetailRows=u,exports.camelToDash=h,exports.processTrails=i;
@@ -42,4 +42,23 @@ export declare class AuthService {
42
42
  * Extrai alias do access token (campo default)
43
43
  */
44
44
  private static extractAliasFromAccessToken;
45
+ /**
46
+ * Detecta o alias a partir do subdomínio da URL atual.
47
+ *
48
+ * Padrões reconhecidos:
49
+ * - `educacao.sabergestao.com.br` → "sabergestao"
50
+ * - `<modulo>.<alias>.<tld>` → alias
51
+ * - `<alias>.qualiex.com` → alias
52
+ * - localhost / *.lovable.app / *.lovable.dev → null
53
+ */
54
+ private static getSubdomainAlias;
55
+ /**
56
+ * Resolve o alias ativo seguindo prioridade:
57
+ * 1. Subdomínio da URL (se válido contra companies)
58
+ * 2. Alias do Supabase token (se válido)
59
+ * 3. Alias armazenado (se válido)
60
+ * 4. `default` do access token (se válido)
61
+ * 5. Primeira company
62
+ */
63
+ private static resolveAliasFromContext;
45
64
  }