forlogic-core 2.3.0 → 2.3.2

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/.note/memory/patterns/dynamic-supabase-config.md +2 -2
  2. package/.note/memory/patterns/environment-detection-logic.md +21 -15
  3. package/README.md +1 -1
  4. package/dist/action-plans/config/environments.d.ts +18 -3
  5. package/dist/action-plans/config/index.d.ts +3 -3
  6. package/dist/action-plans/index.d.ts +1 -1
  7. package/dist/action-plans/index.esm.js +1 -1
  8. package/dist/action-plans/index.js +1 -1
  9. package/dist/audit-trail/config/environments.d.ts +18 -3
  10. package/dist/audit-trail/config/index.d.ts +3 -3
  11. package/dist/audit-trail/index.d.ts +1 -1
  12. package/dist/audit-trail/index.esm.js +1 -1
  13. package/dist/audit-trail/index.js +1 -1
  14. package/dist/config/environments.d.ts +18 -3
  15. package/dist/config/index.d.ts +3 -3
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.esm.js +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/leadership/config/environments.d.ts +18 -3
  20. package/dist/leadership/config/index.d.ts +3 -3
  21. package/dist/leadership/index.d.ts +1 -1
  22. package/dist/leadership/index.esm.js +1 -1
  23. package/dist/leadership/index.js +1 -1
  24. package/dist/places/config/environments.d.ts +18 -3
  25. package/dist/places/config/index.d.ts +3 -3
  26. package/dist/places/index.d.ts +1 -1
  27. package/dist/places/index.esm.js +1 -1
  28. package/dist/places/index.js +1 -1
  29. package/dist/sign/config/environments.d.ts +18 -3
  30. package/dist/sign/config/index.d.ts +3 -3
  31. package/dist/sign/index.d.ts +1 -1
  32. package/dist/sign/index.esm.js +1 -1
  33. package/dist/sign/index.js +1 -1
  34. package/dist/vite/index.esm.js +24 -1
  35. package/dist/vite/index.js +24 -0
  36. package/docs/WORKSPACE_KNOWLEDGE.md +1 -1
  37. package/docs/design-system/patterns/core-providers.md +11 -2
  38. package/docs/design-system/patterns/feature-flags.md +53 -21
  39. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
1
  # Memory: patterns/dynamic-supabase-config
2
- Updated: 2026-03-24
2
+ Updated: 2026-05-25
3
3
 
4
- As credenciais do Supabase vêm exclusivamente do `.env` (auto-populado pelo Lovable ao trocar banco). O Vite injeta automaticamente variáveis `VITE_*` em `import.meta.env` não bloco `define` manual nem extração de `client.ts`. O `vite.config.ts` usa `loadEnv()` apenas para ler o project ID no contexto Node (CSP headers). O `SupabaseSingleton` `import.meta.env.VITE_SUPABASE_URL` e `VITE_SUPABASE_PUBLISHABLE_KEY` em runtime no browser.
4
+ O `vite.config.ts` chama `resolveSupabaseEnv(mode)` (de `forlogic-core/vite`), que lê tanto `VITE_SUPABASE_*` quanto `SUPABASE_*` (formato novo Lovable Cloud), prioriza `VITE_*` e injeta valores consolidados via `define`: `import.meta.env.VITE_SUPABASE_URL`, `VITE_SUPABASE_PUBLISHABLE_KEY`, `VITE_SUPABASE_PROJECT_ID`, `VITE_SUPABASE_PK_OVERRIDE`. O `.env` precisa apenas de UMA versão (`SUPABASE_URL` + `SUPABASE_PUBLISHABLE_KEY`). `VITE_SUPABASE_PK_OVERRIDE` continua obrigatório por causa do bug do Lovable sobrescrever a publishable key com a legacy JWT. `projectId` é derivado da URL quando ausente.
@@ -1,35 +1,41 @@
1
1
  # Memory: patterns/environment-detection-logic
2
- Updated: 2026-03-24
2
+ Updated: 2026-05-25
3
3
 
4
4
  O sistema separa duas preocupações independentes de ambiente:
5
5
 
6
6
  ## 1. Método de autenticação (`shouldUseDevTokens()` / `isLovablePreview()`)
7
7
  Detecta se o app roda em contexto de desenvolvimento (preview Lovable via iframe, `*.lovable.dev`, localhost ou `import.meta.env.DEV`). Quando true, usa a edge function `dev-tokens` do Supabase conectado para autenticar. Quando false (app publicado), usa OAuth padrão do Qualiex.
8
8
 
9
- ## 2. Qual API usar (`getEnvironmentConfig()` / `isDevSupabaseProject()`)
10
- Compara o project ID do Supabase conectado com `PROD_PROJECT_ID` (`ccjfvpnndclajkleyqkc`). Se igual → config PROD (API prod, OAuth prod). Se diferente → config DEV (API dev, OAuth dev).
9
+ ## 2. Qual API usar (`getEnvironmentConfig()` / `isDevEnv()`)
10
+ Fonte de verdade **única e explícita**: env var `VITE_APP_ENV`.
11
11
 
12
- ## Fonte de verdade do Project ID
13
- O project ID vem do `.env` (auto-populado pelo Lovable ao trocar banco), que o Vite injeta automaticamente em `import.meta.env.VITE_SUPABASE_PROJECT_ID`. **Não** é extraído de `src/integrations/supabase/client.ts`. O `vite.config.ts` usa `loadEnv()` apenas no contexto Node para configurar CSP headers.
12
+ | `VITE_APP_ENV` | Resultado |
13
+ |---------------------------------|-----------------------|
14
+ | `"PROD"` | PROD (API/OAuth prod) |
15
+ | `"DEV"` | DEV (API/OAuth dev) |
16
+ | ausente / qualquer outro valor | **PROD (failsafe)** |
17
+
18
+ Não há fallback derivado do Supabase. Apps que querem apontar para dev precisam declarar `VITE_APP_ENV="DEV"` no `.env`. Apps prod simplesmente omitem (ou setam `"PROD"`).
14
19
 
15
20
  ## Tabela de regras
16
21
 
17
- | Cenário | API | Auth |
18
- |------------------------------|------|------------|
19
- | Preview + Prod Supabase | Prod | dev-tokens |
20
- | Preview + Dev Supabase | Dev | dev-tokens |
21
- | Publicado + Prod Supabase | Prod | OAuth |
22
- | Publicado + Dev Supabase | Dev | OAuth |
22
+ | Cenário | API | Auth |
23
+ |---------------------------------|------|------------|
24
+ | Preview + `VITE_APP_ENV=PROD` | Prod | dev-tokens |
25
+ | Preview + `VITE_APP_ENV=DEV` | Dev | dev-tokens |
26
+ | Publicado + `VITE_APP_ENV=PROD` | Prod | OAuth |
27
+ | Publicado + `VITE_APP_ENV=DEV` | Dev | OAuth |
23
28
 
24
29
  ## Guard de troca de projeto (`TokenManager.checkProjectMismatch()`)
25
- Ao inicializar (`AuthService.initialize()`), o sistema compara `import.meta.env.VITE_SUPABASE_PROJECT_ID` com o valor armazenado em `localStorage('supabase_project_id')`. Se diferente, limpa todos os tokens stale automaticamente antes de qualquer chamada a `validate-token`, evitando 401 desnecessários. Após a limpeza, armazena o novo project ID. Isso garante transição limpa ao trocar de banco Supabase sem erros ou blank screen.
30
+ Independente de `VITE_APP_ENV`. Ao inicializar (`AuthService.initialize()`), compara `import.meta.env.VITE_SUPABASE_PROJECT_ID` (consolidado por `resolveSupabaseEnv()` no `vite.config.ts`) com o valor armazenado em `localStorage('supabase_project_id')`. Se diferente, limpa tokens stale antes de qualquer chamada a `validate-token`. Sem efeito em apps `backend="dotnet"`.
26
31
 
27
32
  ## Funções (lib/config/index.ts)
28
33
  - `isLovablePreview()` — detecta contexto de preview/localhost
29
- - `shouldUseDevTokens()` — wrapper semântico sobre `isLovablePreview()`
34
+ - `shouldUseDevTokens()` — wrapper semântico sobre `isLovablePreview()` (apenas modo Supabase)
30
35
  - `isDevEnvironment` — alias deprecated, mantido para compatibilidade
31
- - `getEnvironmentConfig()` — retorna config PROD ou DEV baseado no project ID
32
- - `isDevSupabaseProject()` — true se project ID PROD_PROJECT_ID
36
+ - `getAppEnv()` — retorna `'PROD' | 'DEV'` lendo `VITE_APP_ENV` (default `'PROD'`)
37
+ - `getEnvironmentConfig()` — retorna config PROD ou DEV baseado em `getAppEnv()`
38
+ - `isDevEnv()` — true se `getAppEnv() === 'DEV'`
33
39
 
34
40
  ## Funções (lib/auth/services/TokenManager.ts)
35
41
  - `checkProjectMismatch()` — detecta troca de projeto Supabase e limpa tokens stale
package/README.md CHANGED
@@ -49,7 +49,7 @@ function App() {
49
49
 
50
50
  A partir da versão com `CoreProviders backend="..."`, o Supabase deixou de ser obrigatório:
51
51
 
52
- - `backend="supabase"` (default, retrocompat) — exige `VITE_SUPABASE_URL` + `VITE_SUPABASE_PUBLISHABLE_KEY`.
52
+ - `backend="supabase"` (default, retrocompat) — exige `SUPABASE_URL` + `SUPABASE_PUBLISHABLE_KEY` (ou `VITE_SUPABASE_*` legadas; o `vite.config.ts` consolida ambos).
53
53
  - `backend="dotnet"` — autentica apenas com tokens OAuth do Qualiex; **não** lê envs do Supabase.
54
54
 
55
55
  **Breaking change:** os módulos `sign`, `audit-trail`, `action-plans`, `leadership` e `places` foram **removidos do barrel principal** e só podem ser importados via subpath (ex.: `import { DocumentSigner } from 'forlogic-core/sign'`). Eles continuam exigindo Supabase em runtime mesmo quando o app usa `backend="dotnet"`.
@@ -1,12 +1,27 @@
1
- declare const PROD_PROJECT_ID = "ccjfvpnndclajkleyqkc";
1
+ /**
2
+ * Detecção de ambiente prod/dev.
3
+ *
4
+ * Fonte de verdade ÚNICA: `VITE_APP_ENV` (`"PROD"` | `"DEV"`).
5
+ * - `"DEV"` → API/OAuth/Supabase de dev.
6
+ * - `"PROD"` ou ausente / qualquer outro valor → PROD (failsafe).
7
+ *
8
+ * Não há fallback baseado em env vars Supabase: apps sem Supabase precisam
9
+ * configurar `VITE_APP_ENV="DEV"` explicitamente quando quiserem apontar para dev.
10
+ *
11
+ * **Storage de assets (logos/favicon) é sempre prod** — bucket público fixo.
12
+ */
13
+ export type AppEnv = 'PROD' | 'DEV';
2
14
  export interface EnvironmentConfig {
3
15
  storageProjectId: string;
16
+ supabaseProjectId: string;
17
+ supabaseUrl: string;
18
+ supabasePublishableKey: string;
4
19
  oauth: {
5
20
  authUrl: string;
6
21
  clientId: string;
7
22
  };
8
23
  qualiexApiUrl: string;
9
24
  }
25
+ export declare function getAppEnv(): AppEnv;
10
26
  export declare function getEnvironmentConfig(): EnvironmentConfig;
11
- export declare function isDevSupabaseProject(): boolean;
12
- export { PROD_PROJECT_ID };
27
+ export declare function isDevEnv(): boolean;
@@ -22,13 +22,13 @@ export declare const SEARCH_CONFIG: {
22
22
  export declare const isLovablePreview: () => boolean;
23
23
  /**
24
24
  * Determines auth method: true → use dev-tokens edge function, false → use OAuth.
25
- * This is independent of which API environment (prod/dev) is used that's decided
26
- * by getEnvironmentConfig() based on the Supabase project ID.
25
+ * Requer modo Supabase: em modo dotnet, dev-tokens não existe e devemos sempre
26
+ * cair no OAuth real (loginProd), mesmo em localhost/preview.
27
27
  */
28
28
  export declare const shouldUseDevTokens: () => boolean;
29
29
  /** @deprecated Use `isLovablePreview()` or `shouldUseDevTokens()` instead */
30
30
  export declare const isDevEnvironment: () => boolean;
31
- export { isDevSupabaseProject } from './environments';
31
+ export { isDevEnv, getAppEnv, type AppEnv } from './environments';
32
32
  export declare const getQualiexApiUrl: () => string;
33
33
  export declare const QUERY_KEYS: {
34
34
  readonly crud: (entity: string) => readonly [string];
@@ -90,7 +90,7 @@ export { loadForlogicFonts } from './utils/load-fonts';
90
90
  export * from './types';
91
91
  export * from './types/sidebar';
92
92
  export * from './config';
93
- export { getEnvironmentConfig, PROD_PROJECT_ID, isDevSupabaseProject } from './config/environments';
93
+ export { getEnvironmentConfig, isDevEnv, getAppEnv, type AppEnv } from './config/environments';
94
94
  export type { EnvironmentConfig } from './config/environments';
95
95
  export { setBackendMode, getBackendMode, isSupabaseBackend } from './config/backend';
96
96
  export type { BackendMode } from './config/backend';
@@ -1 +1 @@
1
- import{jsx as e,jsxs as a,Fragment as t}from"react/jsx-runtime";import*as r from"react";import n,{useState as i,useEffect as s,useCallback as o,useRef as d}from"react";import*as l from"@radix-ui/react-tabs";import{clsx as c}from"clsx";import{twMerge as m}from"tailwind-merge";import{format as u}from"date-fns";import"sonner";import{Slot as p}from"@radix-ui/react-slot";import{cva as h}from"class-variance-authority";import*as f from"@radix-ui/react-dropdown-menu";import{ChevronRight as g,Check as v,Circle as b,Loader2 as x,X as y,Pause as N,CheckCircle2 as w,ShieldCheck as C,Play as k,Clock as D,ChevronDown as _,ChevronUp as S,ChevronLeft as P,Calendar as R,EllipsisVertical as z,Plus as j,MessageSquare as I,Smartphone as A,Paperclip as T,ArrowLeft as W,MoreVertical as M}from"lucide-react";import F from"i18next";import*as E from"@radix-ui/react-label";import*as L from"@radix-ui/react-select";import{DayPicker as B}from"react-day-picker";import{useTranslation as V}from"react-i18next";import*as H from"@radix-ui/react-popover";import*as O from"@radix-ui/react-progress";import*as $ from"@radix-ui/react-dialog";import*as q from"@radix-ui/react-separator";import*as U from"@radix-ui/react-alert-dialog";function X(e){return(a={})=>{const t=a.width?String(a.width):e.defaultWidth;return e.formats[t]||e.formats[e.defaultWidth]}}function K(e){return(a,t)=>{let r;if("formatting"===(t?.context?String(t.context):"standalone")&&e.formattingValues){const a=e.defaultFormattingWidth||e.defaultWidth,n=t?.width?String(t.width):a;r=e.formattingValues[n]||e.formattingValues[a]}else{const a=e.defaultWidth,n=t?.width?String(t.width):e.defaultWidth;r=e.values[n]||e.values[a]}return r[e.argumentCallback?e.argumentCallback(a):a]}}function Y(e){return(a,t={})=>{const r=t.width,n=r&&e.matchPatterns[r]||e.matchPatterns[e.defaultMatchWidth],i=a.match(n);if(!i)return null;const s=i[0],o=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],d=Array.isArray(o)?function(e,a){for(let t=0;t<e.length;t++)if(a(e[t]))return t;return}(o,e=>e.test(s)):function(e,a){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&a(e[t]))return t;return}(o,e=>e.test(s));let l;l=e.valueCallback?e.valueCallback(d):d,l=t.valueCallback?t.valueCallback(l):l;return{value:l,rest:a.slice(s.length)}}}const G={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"}},Q={date:X({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:X({formats:{full:"HH:mm:ss zzzz",long:"HH:mm:ss z",medium:"HH:mm:ss",short:"HH:mm"},defaultWidth:"full"}),dateTime:X({formats:{full:"{{date}} 'às' {{time}}",long:"{{date}} 'às' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},J={lastWeek:e=>{const a=e.getDay();return"'"+(0===a||6===a?"último":"última")+"' eeee 'às' p"},yesterday:"'ontem às' p",today:"'hoje às' p",tomorrow:"'amanhã às' p",nextWeek:"eeee 'às' p",other:"P"};var Z;const ee={code:"pt-BR",formatDistance:(e,a,t)=>{let r;const n=G[e];return r="string"==typeof n?n:1===a?n.one:n.other.replace("{{count}}",String(a)),t?.addSuffix?t.comparison&&t.comparison>0?"em "+r:"há "+r:r},formatLong:Q,formatRelative:(e,a,t,r)=>{const n=J[e];return"function"==typeof n?n(a):n},localize:{ordinalNumber:(e,a)=>{const t=Number(e);return"week"===a?.unit?t+"ª":t+"º"},era:K({values:{narrow:["AC","DC"],abbreviated:["AC","DC"],wide:["antes de cristo","depois de cristo"]},defaultWidth:"wide"}),quarter:K({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:K({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:K({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:K({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:(Z={matchPattern:/^(\d+)[ºªo]?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)},(e,a={})=>{const t=e.match(Z.matchPattern);if(!t)return null;const r=t[0],n=e.match(Z.parsePattern);if(!n)return null;let i=Z.valueCallback?Z.valueCallback(n[0]):n[0];return i=a.valueCallback?a.valueCallback(i):i,{value:i,rest:e.slice(r.length)}}),era:Y({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:Y({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:Y({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:Y({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:Y({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 ae(e,a=.1){const{r:t,g:r,b:n}=function(e){const a=e.replace("#",""),t=3===a.length?a.split("").map(e=>e+e).join(""):a;return{r:parseInt(t.substring(0,2),16),g:parseInt(t.substring(2,4),16),b:parseInt(t.substring(4,6),16)}}(e);return`rgba(${t}, ${r}, ${n}, ${a})`}function te(...e){return m(c(e))}const re=l.Root,ne=r.forwardRef(({className:a,...t},r)=>e(l.List,{ref:r,className:te("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",a),...t}));ne.displayName=l.List.displayName;const ie=r.forwardRef(({className:a,...t},r)=>e(l.Trigger,{ref:r,className:te("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",a),...t}));ie.displayName=l.Trigger.displayName;const se=r.forwardRef(({className:a,...t},r)=>e(l.Content,{ref:r,className:te("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",a),...t}));se.displayName=l.Content.displayName;const oe=h("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"}}),de=r.forwardRef(({className:a,variant:t,size:r,asChild:n=!1,...i},s)=>e(n?p:"button",{className:te(oe({variant:t,size:r,className:a})),ref:s,...i}));de.displayName="Button";const le=f.Root,ce=f.Trigger;r.forwardRef(({className:t,inset:r,children:n,...i},s)=>a(f.SubTrigger,{ref:s,className:te("flex cursor-default select-none items-center px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",r&&"pl-8",t),...i,children:[n,e(g,{className:"ml-auto h-4 w-4"})]})).displayName=f.SubTrigger.displayName;r.forwardRef(({className:a,...t},r)=>e(f.SubContent,{ref:r,className:te("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",a),...t})).displayName=f.SubContent.displayName;const me=r.forwardRef(({className:a,sideOffset:t=4,...r},n)=>e(f.Portal,{children:e(f.Content,{ref:n,sideOffset:t,className:te("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",a),...r})}));me.displayName=f.Content.displayName;const ue=r.forwardRef(({className:a,inset:t,...r},n)=>e(f.Item,{ref:n,className:te("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",t&&"pl-8",a),...r}));ue.displayName=f.Item.displayName;r.forwardRef(({className:t,children:r,checked:n,...i},s)=>a(f.CheckboxItem,{ref:s,className:te("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:n,...i,children:[e("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e(f.ItemIndicator,{children:e(v,{className:"h-4 w-4"})})}),r]})).displayName=f.CheckboxItem.displayName;r.forwardRef(({className:t,children:r,...n},i)=>a(f.RadioItem,{ref:i,className:te("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),...n,children:[e("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e(f.ItemIndicator,{children:e(b,{className:"h-2 w-2 fill-current"})})}),r]})).displayName=f.RadioItem.displayName;r.forwardRef(({className:a,inset:t,...r},n)=>e(f.Label,{ref:n,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",a),...r})).displayName=f.Label.displayName;const pe=r.forwardRef(({className:a,...t},r)=>e(f.Separator,{ref:r,className:te("-mx-1 my-1 h-px bg-muted",a),...t}));pe.displayName=f.Separator.displayName;const he={sm:"h-4 w-4",md:"h-6 w-6",lg:"h-8 w-8"};function fe({size:a="md",className:t}){return e(x,{className:te("animate-spin text-muted-foreground",he[a],t)})}function ge({isLoading:r,children:n,className:i,type:s="spinner",size:o="md"}){return r?"overlay"===s?a("div",{className:te("relative",i),children:[n,e("div",{className:"absolute inset-0 bg-background/50 backdrop-blur-sm flex items-center justify-center z-10",children:e(fe,{size:o})})]}):e("div","skeleton"===s?{className:te("animate-pulse",i),children:e("div",{className:"bg-muted rounded-md h-full w-full"})}:{className:te("flex items-center justify-center py-8",i),children:e(fe,{size:o})}):e(t,{children:n})}var ve,be,xe,ye,Ne,we,Ce,ke,De,_e;(be=ve||(ve={}))[be.waitingStart=1]="waitingStart",be[be.running=2]="running",be[be.effectivenessCheck=3]="effectivenessCheck",be[be.done=4]="done",be[be.suspended=5]="suspended",be[be.canceled=6]="canceled",(ye=xe||(xe={}))[ye.low=0]="low",ye[ye.medium=1]="medium",ye[ye.high=2]="high",(we=Ne||(Ne={}))[we.plan=2]="plan",we[we.occurrence=3]="occurrence",we[we.risk=4]="risk",we[we.decisions=5]="decisions",we[we.audit=6]="audit",we[we.strategyExtension=7]="strategyExtension",we[we.standardization=8]="standardization",we[we.supplier=9]="supplier",we[we.auditItems=10]="auditItems",(ke=Ce||(Ce={}))[ke.currentProgress=1]="currentProgress",ke[ke.cumulativeProgress=2]="cumulativeProgress",(_e=De||(De={})).uploading="uploading",_e.waiting="waiting",_e.done="done",_e.error="error",_e.canceled="canceled",_e.duplicateItem="duplicateItem";const Se={[ve.waitingStart]:"#D6D6D6",[ve.running]:"#DAE9F4",[ve.effectivenessCheck]:"#1B75BB29",[ve.done]:"#DDEECA",[ve.suspended]:"#FFF2D6",[ve.canceled]:"#F4433629"},Pe={[ve.waitingStart]:"#666666",[ve.running]:"#1B75BB",[ve.effectivenessCheck]:"#1B75BB",[ve.done]:"#4CAF50",[ve.suspended]:"#FF9800",[ve.canceled]:"#F44336"},Re={[ve.waitingStart]:"waiting-start",[ve.running]:"running",[ve.effectivenessCheck]:"effectiveness-check",[ve.done]:"done",[ve.suspended]:"suspended",[ve.canceled]:"canceled"};function ze(){return{[ve.waitingStart]:F.t("ap_status_waiting_start"),[ve.running]:F.t("ap_status_running"),[ve.effectivenessCheck]:F.t("ap_status_effectiveness_check"),[ve.done]:F.t("ap_status_done"),[ve.suspended]:F.t("ap_status_suspended"),[ve.canceled]:F.t("ap_status_canceled")}}const je=new Proxy({},{get:(e,a)=>{if("symbol"==typeof a)return;return ze()[a]}});function Ie(){return[{id:"immediate",label:F.t("ap_type_immediate")},{id:"corrective",label:F.t("ap_type_corrective")},{id:"preventive",label:F.t("ap_type_preventive")},{id:"improvement",label:F.t("ap_type_improvement")},{id:"standardization",label:F.t("ap_type_standardization")}]}const Ae=[{id:"immediate",label:"Imediata"},{id:"corrective",label:"Corretiva"},{id:"preventive",label:"Preventiva"},{id:"improvement",label:"Oportunidade de Melhoria"},{id:"standardization",label:"Padronização"}];function Te(){return[{id:xe.low,label:F.t("ap_priority_low"),color:"#4CAF50"},{id:xe.medium,label:F.t("ap_priority_medium"),color:"#FF9800"},{id:xe.high,label:F.t("ap_priority_high"),color:"#F44336"}]}const We=[{id:xe.low,label:"Baixa",color:"#4CAF50"},{id:xe.medium,label:"Média",color:"#FF9800"},{id:xe.high,label:"Alta",color:"#F44336"}],Me=[ve.done,ve.canceled],Fe=[ve.waitingStart,ve.running,ve.effectivenessCheck,ve.suspended];function Ee(e){const{actionPlan:a,isNew:t=!1,config:r,onSave:n,onCancel:d,onDelete:l,onChangeStatus:c}=e,[m,u]=i({formData:a||{},isLoading:e.isLoading||!1,isSaving:!1,activeTab:"general",isFormDisabled:!1});s(()=>{a&&u(e=>({...e,formData:a,isFormDisabled:r?.disableFields||Me.includes(a.statusId)}))},[a,r?.disableFields]),s(()=>{u(a=>({...a,isLoading:e.isLoading||!1}))},[e.isLoading]);const p=o((e,a)=>{u(t=>({...t,formData:{...t.formData,[e]:a}}))},[]),h=o(e=>{u(a=>({...a,activeTab:e}))},[]),f=o(async()=>{if(n){u(e=>({...e,isSaving:!0}));try{await n(m.formData)}finally{u(e=>({...e,isSaving:!1}))}}},[n,m.formData]),g=o(async e=>{if(c&&m.formData.id){u(e=>({...e,isLoading:!0}));try{await c(m.formData.id,e)}finally{u(e=>({...e,isLoading:!1}))}}},[c,m.formData.id]),v=o(async()=>{if(l&&m.formData.id){u(e=>({...e,isLoading:!0}));try{await l(m.formData.id)}finally{u(e=>({...e,isLoading:!1}))}}},[l,m.formData.id]);return{formData:m.formData,isLoading:m.isLoading,isSaving:m.isSaving,activeTab:m.activeTab,isFormDisabled:m.isFormDisabled,updateField:p,setActiveTab:h,save:f,changeStatus:g,remove:v,cancel:d}}const Le={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 Be({label:t,color:r,icon:n,showIcon:i,size:s="md",variant:o="filled",backgroundColor:d,className:l}){const c=Le[s],m=i??!!n;return a("span",{className:te("inline-flex items-center rounded-md font-medium whitespace-nowrap","outline"===o&&"border",c.badge,l),style:(()=>{switch(o){case"outline":return{color:r,borderColor:ae(r,.3),backgroundColor:"transparent"};case"ghost":return{color:r,backgroundColor:"transparent"};default:return{color:r,backgroundColor:d||ae(r,.1)}}})(),children:[m&&n&&e(n,{size:c.icon,strokeWidth:2}),t]})}const Ve={[ve.waitingStart]:{label:"",color:"#8B7355",icon:D},[ve.running]:{label:"",color:"#2E7D5B",icon:k},[ve.effectivenessCheck]:{label:"",color:"#4A6FA5",icon:C},[ve.done]:{label:"",color:"#3D7A40",icon:w},[ve.suspended]:{label:"",color:"#6B7280",icon:N},[ve.canceled]:{label:"",color:"#B44A4A",icon:y}};function He({status:a,labels:t,className:r,size:n,showIcon:i,variant:s}){const o=ze(),d=Ve[a];if(!d)return null;const l=t?.[a]||o[a]||"";return e(Be,{label:l,color:d.color,icon:d.icon,size:n,showIcon:i,variant:s,className:r})}const Oe=r.forwardRef(({className:t,type:n,showCharCount:i,maxLength:s,onChange:o,...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 a("div",{className:"w-full",children:[e("input",{type:n,className:te("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:l,maxLength:s,onChange:e=>{m(e.target.value.length),o?.(e)},...d}),i&&s&&a("div",{className:"text-right text-xs text-muted-foreground mt-1",children:[c," / ",s]})]})});Oe.displayName="Input";const $e=r.forwardRef(({className:t,showCharCount:n,maxLength:i,onChange:s,...o},d)=>{const[l,c]=r.useState(0);r.useEffect(()=>{"string"==typeof o.value?c(o.value.length):"string"==typeof o.defaultValue&&c(o.defaultValue.length)},[o.value,o.defaultValue]);return a("div",{className:"w-full",children:[e("textarea",{className:te("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:d,maxLength:i,onChange:e=>{c(e.target.value.length),s?.(e)},...o}),n&&i&&a("div",{className:"text-right text-xs text-muted-foreground mt-1",children:[l," / ",i]})]})});$e.displayName="Textarea";const qe=h("text-xs font-medium leading-none text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ue=r.forwardRef(({className:a,...t},r)=>e(E.Root,{ref:r,className:te(qe(),a),...t}));Ue.displayName=E.Root.displayName;const Xe=r.createContext({showCheck:!1}),Ke=({showCheck:a=!1,...t})=>e(Xe.Provider,{value:{showCheck:a},children:e(L.Root,{...t})}),Ye=L.Value,Ge=r.forwardRef(({className:t,children:r,...n},i)=>a(L.Trigger,{ref:i,className:te("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),...n,children:[r,e(L.Icon,{asChild:!0,children:e(_,{className:"h-4 w-4 opacity-50"})})]}));Ge.displayName=L.Trigger.displayName;const Qe=r.forwardRef(({className:a,...t},r)=>e(L.ScrollUpButton,{ref:r,className:te("flex cursor-default items-center justify-center py-1",a),...t,children:e(S,{className:"h-4 w-4"})}));Qe.displayName=L.ScrollUpButton.displayName;const Je=r.forwardRef(({className:a,...t},r)=>e(L.ScrollDownButton,{ref:r,className:te("flex cursor-default items-center justify-center py-1",a),...t,children:e(_,{className:"h-4 w-4"})}));Je.displayName=L.ScrollDownButton.displayName;const Ze=r.forwardRef(({className:t,children:r,position:n="popper",container:i,collisionBoundary:s,...o},d)=>e(L.Portal,{container:i,children:a(L.Content,{ref:d,className:te("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",t),position:n,collisionBoundary:s,...o,children:[e(Qe,{}),e(L.Viewport,{className:te("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:r}),e(Je,{})]})}));Ze.displayName=L.Content.displayName;r.forwardRef(({className:a,...t},r)=>e(L.Label,{ref:r,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",a),...t})).displayName=L.Label.displayName;const ea=r.forwardRef(({className:t,children:n,...i},s)=>{const{showCheck:o}=r.useContext(Xe);return a(L.Item,{ref:s,className:te("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),...i,children:[o&&e("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e(L.ItemIndicator,{children:e(v,{className:"h-4 w-4"})})}),e(L.ItemText,{children:n})]})});ea.displayName=L.Item.displayName;function aa({className:a,classNames:t,showOutsideDays:r=!0,...n}){return e(B,{showOutsideDays:r,className:te("p-3 pointer-events-auto",a),locale:ee,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:te(oe({variant:"outline"}),"z-10 h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),button_next:te(oe({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:te(oe({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",...t},components:{Chevron:({orientation:a})=>e("left"===a?P:g,{className:"h-4 w-4"})},...n})}r.forwardRef(({className:a,...t},r)=>e(L.Separator,{ref:r,className:te("-mx-1 my-1 h-px bg-muted",a),...t})).displayName=L.Separator.displayName,aa.displayName="Calendar";const ta=H.Root,ra=H.Trigger,na=r.forwardRef(({className:a,align:t="center",sideOffset:r=4,container:n,...i},s)=>e(H.Portal,{container:n,children:e(H.Content,{ref:s,align:t,sideOffset:r,className:te("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",a),...i})}));function ia({date:t,onDateChange:r,placeholder:n,disabled:i=!1,className:s,disabledDates:o}){const{t:d}=V(),l=n??d("select_date");return a(ta,{children:[e(ra,{asChild:!0,children:a(de,{variant:"outline",disabled:i,className:te("w-full justify-start text-left font-normal",!t&&"text-muted-foreground",s),children:[e(R,{className:"mr-2 h-4 w-4"}),t?u(t,"d 'de' MMMM 'de' yyyy",{locale:ee}):e("span",{children:l})]})}),e(na,{className:"w-auto p-0",align:"start",children:e(aa,{mode:"single",selected:t,onSelect:r,disabled:o,initialFocus:!0,className:"pointer-events-auto"})})]})}function sa({formData:t,updateField:r,disabled:i=!1,users:s=[],places:o=[],actionTypes:d,causes:l=[],parentActions:c=[],config:m}){const{t:u}=V(),p=m?.requiredFields,h=d||Ae,f=e=>{if(m?.hiddenFields?.includes(e))return!1;if(m?.visibleFields&&m.visibleFields.length>0)return m.visibleFields.includes(e);const a=`${e}Visible`;return!p||!(a in p)||!1!==p[a]},g=e=>p?!!p[e]:"name"===e,v=n.useMemo(()=>{if(t.startDate&&t.endDate){const e=new Date(t.startDate),a=new Date(t.endDate).getTime()-e.getTime();return Math.max(0,Math.ceil(a/864e5))}return t.duration||0},[t.startDate,t.endDate,t.duration]);return a("div",{className:"space-y-6 p-1",children:[a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("name")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Nome"}),e(Oe,{value:t.name||"",onChange:e=>r("name",e.target.value),maxLength:500,disabled:i,placeholder:u("ap_plan_name_placeholder")})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("responsibleWho")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("responsibleWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Responsável"}),a(Ke,{value:t.responsibleId||"",onValueChange:e=>r("responsibleId",e),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_responsible")})}),e(Ze,{children:s.map(a=>e(ea,{value:a.id,children:a.name},a.id))})]})]}),f("checkerWho")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("checkerWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Verificador"}),a(Ke,{value:t.checkerId||"",onValueChange:e=>r("checkerId",e),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_checker")})}),e(Ze,{children:s.map(a=>e(ea,{value:a.id,children:a.name},a.id))})]})]})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("place")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("place")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Local"}),a(Ke,{value:t.placeId||"",onValueChange:e=>r("placeId",e),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_place")})}),e(Ze,{children:oa(o).map(a=>e(ea,{value:a.id,children:a.name},a.id))})]})]}),f("planType")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("planType")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Tipo de Ação"}),a(Ke,{value:t.typeId||"",onValueChange:e=>r("typeId",e),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_type")})}),e(Ze,{children:h.map(a=>e(ea,{value:a.id,children:a.label},a.id))})]})]})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[f("priority")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("priority")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Prioridade"}),a(Ke,{value:t.priorityType?.toString()||"",onValueChange:e=>r("priorityType",Number(e)),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_priority")})}),e(Ze,{children:We.map(t=>e(ea,{value:t.id.toString(),children:a("span",{className:"flex items-center gap-2",children:[e("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:t.color}}),t.label]})},t.id))})]})]}),c.length>0&&a("div",{className:"space-y-2",children:[e(Ue,{children:u("ap_belongs_to")}),a(Ke,{value:t.parentId||"",onValueChange:e=>r("parentId",e),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_parent")})}),e(Ze,{children:c.map(a=>e(ea,{value:a.id,children:a.label},a.id))})]})]})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[f("startDate")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("startDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Início"}),e(ia,{date:t.startDate?new Date(t.startDate):void 0,onDateChange:e=>r("startDate",e||null),disabled:i,placeholder:u("ap_select_date")})]}),f("endDate")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("endDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Término"}),e(ia,{date:t.endDate?new Date(t.endDate):void 0,onDateChange:e=>r("endDate",e||null),disabled:i,placeholder:u("ap_select_date"),disabledDates:t.startDate?e=>e<new Date(t.startDate):void 0})]}),a("div",{className:"space-y-2",children:[e(Ue,{children:u("ap_duration_days")}),e(Oe,{type:"number",value:v,disabled:!0,className:"bg-muted"})]})]}),f("estimatedCost")&&a("div",{className:"space-y-2 max-w-xs",children:[e(Ue,{className:te(g("estimatedCost")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Custo Estimado"}),a("div",{className:"relative",children:[e("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"R$"}),e(Oe,{type:"number",min:0,step:.01,value:t.estimatedCost||"",onChange:e=>r("estimatedCost",Number(e.target.value)),disabled:i,className:"pl-9",placeholder:"0,00"})]})]}),f("cause")&&l.length>0&&a("div",{className:"space-y-2",children:[e(Ue,{children:"Causa"}),a(Ke,{value:t.causeId||"",onValueChange:e=>r("causeId",e),disabled:i,children:[e(Ge,{children:e(Ye,{placeholder:u("ap_select_cause")})}),e(Ze,{children:l.map(a=>e(ea,{value:a.id,children:a.label},a.id))})]})]}),f("description")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("description")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Descrição"}),e($e,{value:t.description||"",onChange:e=>r("description",e.target.value),maxLength:4e3,disabled:i,rows:4,placeholder:u("ap_description_placeholder")})]}),f("justification")&&a("div",{className:"space-y-2",children:[e(Ue,{className:te(g("justification")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Justificativa"}),e($e,{value:t.justification||"",onChange:e=>r("justification",e.target.value),maxLength:4e3,disabled:i,rows:4,placeholder:u("ap_justification_placeholder")})]})]})}function oa(e,a=0){const t=[];for(const r of e)t.push({...r,depth:a}),r.children?.length&&t.push(...oa(r.children,a+1));return t}na.displayName=H.Content.displayName;const da=r.forwardRef(({className:a,value:t,...r},n)=>e(O.Root,{ref:n,className:te("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",a),...r,children:e(O.Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})}));da.displayName=O.Root.displayName;const la=n.forwardRef(({className:a,children:t,variant:r="action",...n},i)=>e(de,{ref:i,variant:r,size:"icon",className:te("h-8 w-8",a),...n,children:t||e(z,{size:16})}));function ca(e){const{progress:a,onReportProgress:t,onEditProgress:r,onDeleteProgress:n}=e,[s,d]=i(!1),[l,c]=i(null),m=!!a&&Fe.includes(a.status),u=o(async e=>{if(t&&a){d(!0);try{const r=100===e.percentProgress;await t({id:a.id,...e,conclude:r})}finally{d(!1)}}},[t,a]),p=o(async e=>{if(r){d(!0);try{await r(e)}finally{d(!1),c(null)}}},[r]),h=o(async e=>{if(n){d(!0);try{await n(e)}finally{d(!1)}}},[n]);return{progress:a,canReportProgress:m,isSubmitting:s,editingReport:l,setEditingReport:c,reportProgress:u,editProgress:p,deleteProgress:h}}la.displayName="ActionButton";const ma=r.forwardRef(({className:a,orientation:t="horizontal",decorative:r=!0,...n},i)=>e(q.Root,{ref:i,decorative:r,orientation:t,className:te("shrink-0 bg-border","horizontal"===t?"h-[1px] w-full":"h-full w-[1px]",a),...n}));ma.displayName=q.Root.displayName;const ua=U.Root,pa=U.Portal,ha=r.forwardRef(({className:a,...t},r)=>e(U.Overlay,{className:te("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",a),...t,ref:r}));ha.displayName=U.Overlay.displayName;const fa=r.forwardRef(({className:t,...r},n)=>a(pa,{children:[e(ha,{}),e(U.Content,{ref:n,className:te("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),...r})]}));fa.displayName=U.Content.displayName;const ga=({className:a,...t})=>e("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",a),...t});ga.displayName="AlertDialogHeader";const va=({className:a,...t})=>e("div",{className:te("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...t});va.displayName="AlertDialogFooter";const ba=r.forwardRef(({className:a,...t},r)=>e(U.Title,{ref:r,className:te("text-lg font-semibold",a),...t}));ba.displayName=U.Title.displayName;const xa=r.forwardRef(({className:a,...t},r)=>e(U.Description,{ref:r,className:te("text-sm text-muted-foreground",a),...t}));xa.displayName=U.Description.displayName;const ya=r.forwardRef(({className:a,...t},r)=>e(U.Action,{ref:r,className:te(oe(),a),...t}));ya.displayName=U.Action.displayName;const Na=r.forwardRef(({className:a,...t},r)=>e(U.Cancel,{ref:r,className:te(oe({variant:"outline"}),"mt-2 sm:mt-0",a),...t}));Na.displayName=U.Cancel.displayName;const wa=$.Root,Ca=$.Portal,ka=r.forwardRef(({className:a,...t},r)=>e($.Overlay,{ref:r,className:te("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",a),...t}));ka.displayName=$.Overlay.displayName;const Da={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"}},_a=r.forwardRef(({className:t,children:n,size:i,variant:s="informative",isDirty:o,customWidth:d,customMinWidth:l,customMaxWidth:c,customHeight:m,customMinHeight:u,customMaxHeight:p,unsavedChangesTitle:h=F.t("unsaved_changes"),unsavedChangesDescription:f=F.t("unsaved_changes_description"),cancelText:g=F.t("cancel"),leaveWithoutSavingText:v=F.t("leave_without_saving"),style:b,onInteractOutside:x,onEscapeKeyDown:N,...w},C)=>{const[k,D]=r.useState(!1),_=r.useRef(null),S=r.useRef(!1),P=i??(d||l||c||m||u||p?void 0:"md"),R=P?Da[P]:{},z={...d??R.width?{width:d??R.width}:{},...l??R.minWidth?{minWidth:l??R.minWidth}:{},...c??R.maxWidth?{maxWidth:c??R.maxWidth}:{},...m??R.height?{height:m??R.height}:{},...u??R.minHeight?{minHeight:u??R.minHeight}:{},...p??R.maxHeight?{maxHeight:p??R.maxHeight}:{},...b},j=r.useCallback(e=>{"form"===s&&o?(_.current=e,D(!0)):e()},[s,o]),I=r.useRef(null),A="destructive"!==s;if("development"===process.env.NODE_ENV&&n){const e=r.Children.toArray(n);e.some(e=>r.isValidElement(e)&&"DialogFooter"===e.type?.displayName),e.some(e=>r.isValidElement(e)&&"DialogBody"===e.type?.displayName)}return a(Ca,{children:[e(ka,{}),a($.Content,{ref:C,className:te("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:z,onInteractOutside:e=>{"form"!==s&&"destructive"!==s?x?.(e):e.preventDefault()},onEscapeKeyDown:e=>{if("destructive"!==s)return"form"===s&&o?(e.preventDefault(),void j(()=>{S.current=!0,I.current?.click()})):void N?.(e);e.preventDefault()},...w,children:[n,A&&a($.Close,{ref:I,onClick:e=>{S.current?S.current=!1:"form"===s&&o&&(e.preventDefault(),j(()=>{S.current=!0,I.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(y,{className:"h-4 w-4"}),e("span",{className:"sr-only",children:"Close"})]})]}),e(ua,{open:k,onOpenChange:D,children:a(fa,{children:[a(ga,{children:[e(ba,{children:h}),e(xa,{children:f})]}),a(va,{children:[e(Na,{onClick:()=>{D(!1),_.current=null},children:g}),e(ya,{onClick:()=>{D(!1),_.current?.(),_.current=null},children:v})]})]})})]})});_a.displayName=$.Content.displayName;const Sa=({className:t,showSeparator:r=!1,children:n,...i})=>a("div",{className:te("flex flex-col flex-shrink-0",t),...i,children:[e("div",{className:"flex flex-col text-left",children:n}),r&&e(ma,{className:"mt-2"})]});Sa.displayName="DialogHeader";const Pa=({className:t,children:r,...n})=>a("div",{className:"flex-shrink-0 pt-4",children:[e(ma,{className:"mb-4"}),e("div",{className:te("flex flex-row justify-end gap-2",t),...n,children:r})]});Pa.displayName="DialogFooter";const Ra=r.forwardRef(({className:a,...t},r)=>e($.Title,{ref:r,className:te("text-xl font-semibold leading-none tracking-tight",a),...t}));Ra.displayName=$.Title.displayName;function za(e){if(!e)return"";let a=(e||"").trim();if(!a)return"00:00";if(a.includes(":")){const e=a.split(":");if(e.length>=2){const a=e[0].replace(/\D/g,""),t=e[1].replace(/\D/g,"");let r=parseInt(a)||0,n=parseInt(t)||0;return r+=Math.floor(n/60),n%=60,`${r.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}}if(a=a.replace(/\D/g,""),!a)return"00:00";let t=0,r=0;return 4===a.length?(t=parseInt(a.substring(0,2))||0,r=parseInt(a.substring(2,4))||0,t+=Math.floor(r/60),r%=60):(t=parseInt(a)||0,r=0),`${t.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}function ja(e){if(null==e)return"00:00";const a=String(e).replace(/\D/g,"");if(a.length<3){let e=parseInt(a)||0;const t=Math.floor(e/60);return e%=60,`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}{const e=a.slice(-2),t=a.slice(0,-2);let r=parseInt(t)||0,n=parseInt(e)||0;return r+=Math.floor(n/60),n%=60,`${r.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}}function Ia(e){return 100===e?"#84c148":e>0?"#1b75bb":""}function Aa({open:t,onOpenChange:r,report:s,onSave:o,isSubmitting:d=!1}){const{t:l}=V(),[c,m]=i(s?.percentProgress||0),[u,p]=i(s?.timeProgress||""),[h,f]=i(s?.comments||""),g=c!==(s?.percentProgress??0)||u!==(s?.timeProgress??"")||h!==(s?.comments??"");n.useEffect(()=>{s&&(m(s.percentProgress),p(s.timeProgress||""),f(s.comments||""))},[s]);return e(wa,{open:t,onOpenChange:r,children:a(_a,{className:"sm:max-w-md",variant:"form",isDirty:g,children:[e(Sa,{children:e(Ra,{children:l("ap_edit_progress")})}),a("div",{className:"space-y-4 py-4",children:[a("div",{className:"space-y-2",children:[e(Ue,{children:l("ap_progress_percent")}),e(Oe,{type:"number",min:0,max:100,value:c,onChange:e=>m(Number(e.target.value))})]}),a("div",{className:"space-y-2",children:[e(Ue,{children:l("ap_time_spent")}),e(Oe,{value:u,onChange:e=>p(e.target.value),onBlur:()=>p(za(u)||""),placeholder:"00:00"})]}),a("div",{className:"space-y-2",children:[e(Ue,{children:l("ap_comments")}),e($e,{value:h,onChange:e=>f(e.target.value),rows:3,maxLength:4e3})]})]}),a(Pa,{children:[e(de,{variant:"outline",onClick:()=>r(!1),disabled:d,children:"Cancelar"}),e(de,{onClick:()=>{s&&o({...s,percentProgress:c,timeProgress:za(u)||"00:00",comments:h})},disabled:d,children:d?"Salvando...":"Salvar"})]})]})})}function Ta(t){const{t:r}=V(),{progress:n,canReportProgress:s,isSubmitting:o,editingReport:d,setEditingReport:l,reportProgress:c,editProgress:m,deleteProgress:u}=ca(t),[p,h]=i(""),[f,g]=i(""),[v,b]=i("");if(!n)return e("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Sem dados de progresso disponíveis"});const x=Ia(n.percentProgress),y=!p,N=!p&&!f&&!v;return a("div",{className:"space-y-6 p-1",children:[a("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[a("div",{className:"flex items-center justify-between text-sm",children:[e("span",{className:"font-medium",children:r("ap_overall_progress")}),a("span",{className:"font-semibold",style:{color:x||void 0},children:[n.percentProgress,"%"]})]}),e(da,{value:n.percentProgress,className:"h-3"}),n.timeProgress&&a("div",{className:"text-xs text-muted-foreground",children:["Tempo total: ",ja(n.timeProgress)]})]}),s&&a("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[e("h4",{className:"text-sm font-medium",children:r("ap_report_progress")}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a("div",{className:"space-y-2",children:[e(Ue,{children:r("ap_progress_percent")}),e(Oe,{type:"number",min:0,max:100,value:p,onChange:e=>h(e.target.value),placeholder:"0"})]}),a("div",{className:"space-y-2",children:[e(Ue,{children:r("ap_time_spent")}),e(Oe,{value:f,onChange:e=>g(e.target.value),onBlur:()=>g(za(f)||""),placeholder:"00:00"})]})]}),a("div",{className:"space-y-2",children:[e(Ue,{children:r("ap_comments")}),e($e,{value:v,onChange:e=>b(e.target.value),rows:3,maxLength:4e3,placeholder:r("ap_progress_comment_placeholder")})]}),a("div",{className:"flex gap-2 justify-end",children:[e(de,{variant:"outline",size:"sm",onClick:()=>{h(""),g(""),b("")},disabled:N||o,children:"Limpar"}),e(de,{size:"sm",onClick:async()=>{const e=Number(p);(e||0===e)&&(await c({percentProgress:e,timeProgress:za(f)||"00:00",comments:v}),h(""),g(""),b(""))},disabled:y||o,children:o?"Reportando...":"Reportar"})]})]}),n.reports.length>0&&a("div",{className:"space-y-3",children:[e("h4",{className:"text-sm font-medium",children:r("ap_reports_history")}),e("div",{className:"space-y-2",children:n.reports.map(a=>e(Wa,{report:a,onEdit:()=>l(a),onDelete:()=>u(a.id),disabled:!s},a.id))})]}),e(Aa,{open:!!d,onOpenChange:e=>!e&&l(null),report:d,onSave:m,isSubmitting:o})]})}function Wa({report:t,onEdit:r,onDelete:n,disabled:i}){const s=t.date?new Date(t.date):null,o=Ia(t.percentProgress);return a("div",{className:"flex items-start gap-3 rounded-lg border bg-card p-3",children:[e("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()||"?"}),a("div",{className:"flex-1 min-w-0 space-y-1",children:[a("div",{className:"flex items-center gap-2 text-sm",children:[e("span",{className:"font-medium truncate",children:t.userName}),s&&e("span",{className:"text-xs text-muted-foreground",children:s.toLocaleDateString("pt-BR")})]}),a("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[a("span",{style:{color:o||void 0},className:"font-semibold",children:[t.percentProgress,"%"]}),t.timeProgress&&a("span",{children:["Tempo: ",ja(t.timeProgress)]})]}),t.comments&&e("p",{className:"text-xs text-muted-foreground mt-1",children:t.comments})]}),!i&&a(le,{children:[e(ce,{asChild:!0,children:e(la,{})}),a(me,{align:"end",children:[e(ue,{onClick:r,children:F.t("edit")}),e(ue,{className:"text-destructive",onClick:n,children:F.t("ap_delete")})]})]})]})}function Ma({predecessors:t=[],availablePredecessors:r=[],onAdd:i,onRemove:s,disabled:o=!1}){const{t:d}=V(),[l,c]=n.useState(""),m=r.filter(e=>!t.some(a=>a.predecessorId===e.id));return a("div",{className:"space-y-6 p-1",children:[!o&&m.length>0&&a("div",{className:"flex items-end gap-3",children:[a("div",{className:"flex-1 space-y-2",children:[e(Ue,{children:d("ap_add_predecessor")}),a(Ke,{value:l,onValueChange:c,children:[e(Ge,{children:e(Ye,{placeholder:d("ap_select_action")})}),e(Ze,{children:m.map(a=>e(ea,{value:a.id,children:a.label},a.id))})]})]}),a(de,{size:"sm",onClick:()=>{l&&i&&(i(l),c(""))},disabled:!l,children:[e(j,{className:"h-4 w-4 mr-1"}),"Adicionar"]})]}),t.length>0?e("div",{className:"space-y-2",children:t.map(t=>a("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[a("div",{className:"flex items-center gap-3",children:[t.predecessorCode&&e("span",{className:"text-xs text-muted-foreground font-mono",children:t.predecessorCode}),e("span",{className:"text-sm font-medium",children:t.predecessorName}),null!=t.predecessorStatus&&e(He,{status:t.predecessorStatus})]}),!o&&s&&a(le,{children:[e(ce,{asChild:!0,children:e(la,{})}),e(me,{align:"end",children:e(ue,{className:"text-destructive",onClick:()=>s(t.predecessorId),children:"Remover"})})]})]},t.id))}):e("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum predecessor adicionado"})]})}function Fa({costs:t=[],onAdd:r,onEdit:n,onDelete:s,disabled:o=!1}){const{t:d}=V(),[l,c]=i(""),[m,u]=i(""),p=t.reduce((e,a)=>e+(a.value||0),0);return a("div",{className:"space-y-6 p-1",children:[a("div",{className:"rounded-lg border bg-card p-4 flex items-center justify-between",children:[e("span",{className:"text-sm font-medium",children:d("ap_total_cost")}),a("span",{className:"text-lg font-semibold text-foreground",children:["R$ ",p.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),!o&&r&&a("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[e("h4",{className:"text-sm font-medium",children:d("ap_add_cost")}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a("div",{className:"space-y-2",children:[e(Ue,{children:"Descrição"}),e(Oe,{value:l,onChange:e=>c(e.target.value),placeholder:d("ap_cost_description")})]}),a("div",{className:"space-y-2",children:[e(Ue,{children:"Valor (R$)"}),e(Oe,{type:"number",min:0,step:.01,value:m,onChange:e=>u(e.target.value),placeholder:"0,00"})]})]}),e("div",{className:"flex justify-end",children:a(de,{size:"sm",onClick:()=>{l&&m&&r&&(r({description:l,value:Number(m),date:(new Date).toISOString()}),c(""),u(""))},disabled:!l||!m,children:[e(j,{className:"h-4 w-4 mr-1"}),"Adicionar"]})})]}),t.length>0?e("div",{className:"space-y-2",children:t.map(t=>a("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[a("div",{className:"flex-1 min-w-0",children:[e("p",{className:"text-sm font-medium truncate",children:t.description}),t.date&&e("p",{className:"text-xs text-muted-foreground",children:new Date(t.date).toLocaleDateString("pt-BR")})]}),a("div",{className:"flex items-center gap-3",children:[a("span",{className:"text-sm font-semibold whitespace-nowrap",children:["R$ ",t.value.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]}),!o&&(n||s)&&a(le,{children:[e(ce,{asChild:!0,children:e(la,{})}),a(me,{align:"end",children:[n&&e(ue,{onClick:()=>n(t),children:d("edit")}),s&&e(ue,{className:"text-destructive",onClick:()=>s(t.id),children:d("ap_delete")})]})]})]})]},t.id))}):e("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum custo registrado"})]})}r.forwardRef(({className:a,...t},r)=>e($.Description,{ref:r,className:te("text-sm text-muted-foreground",a),...t})).displayName=$.Description.displayName;const Ea=h("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"}}),La=r.forwardRef(({className:a,variant:t,...r},n)=>e("div",{ref:n,className:te(Ea({variant:t}),a),...r}));function Ba({comments:t=[],currentUserId:r,onAdd:n,onEdit:s,onDelete:o,disabled:d=!1,maxLength:l=4e3}){const{t:c}=V(),[m,u]=i(""),[p,h]=i(!1),[f,g]=i(null),[v,b]=i(""),x=()=>{g(null),b("")};return a("div",{className:"space-y-6 p-1",children:[!d&&n&&a("div",{className:"space-y-3",children:[e($e,{value:m,onChange:e=>u(e.target.value),placeholder:c("ap_add_comment_placeholder"),maxLength:l,rows:3}),a("div",{className:"flex items-center justify-between",children:[l&&a("span",{className:"text-xs text-muted-foreground",children:[m.length,"/",l]}),a("div",{className:"flex gap-2 ml-auto",children:[e(de,{variant:"outline",size:"sm",onClick:()=>u(""),disabled:!m||p,children:"Limpar"}),e(de,{size:"sm",onClick:async()=>{if(m.trim()&&n){h(!0);try{await n(m),u("")}finally{h(!1)}}},disabled:!m.trim()||p,children:p?"Enviando...":"Comentar"})]})]})]}),a("div",{className:"space-y-1",children:[t.length>0?a("div",{className:"flex items-center gap-2 mb-3",children:[e("span",{className:"text-sm font-medium",children:c("ap_comments")}),e(La,{variant:"info",className:"text-[10px] px-1.5 py-0",children:t.length})]}):a("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e(I,{className:"h-8 w-8 mb-2 opacity-50"}),e("p",{className:"text-sm",children:"Nenhum comentário adicionado"})]}),t.map(t=>a("div",{className:"flex gap-3 rounded-lg border bg-card p-3",children:[e("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("img",{src:t.userPhotoUrl,alt:t.userName,className:"h-full w-full object-cover"}):t.userName?.charAt(0)?.toUpperCase()||"?"}),a("div",{className:"flex-1 min-w-0 space-y-1",children:[a("div",{className:"flex items-center gap-2 text-sm",children:[e("span",{className:"font-medium truncate",children:t.userName}),t.userEmail&&e("span",{className:"text-xs text-muted-foreground truncate",children:t.userEmail}),e("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:Va(t.dateEdited||t.dateCreation)}),t.dateEdited&&e("span",{className:"text-xs text-muted-foreground italic",children:"editado"})]}),f===t.id?a("div",{className:"space-y-2",children:[e($e,{value:v,onChange:e=>b(e.target.value),maxLength:l,rows:3}),a("div",{className:"flex gap-2 justify-end",children:[e(de,{variant:"outline",size:"sm",onClick:x,disabled:p,children:"Cancelar"}),e(de,{size:"sm",onClick:()=>(async e=>{if(v.trim()&&s){h(!0);try{await s({...e,text:v,stringText:v}),g(null),b("")}finally{h(!1)}}})(t),disabled:!v.trim()||p,children:p?"Salvando...":"Salvar"})]})]}):e("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.stringText||t.text})]}),!d&&r===t.userId&&f!==t.id&&a(le,{children:[e(ce,{asChild:!0,children:e(la,{})}),a(me,{align:"end",children:[s&&e(ue,{onClick:()=>(e=>{g(e.id),b(e.stringText||e.text)})(t),children:c("edit")}),o&&e(ue,{className:"text-destructive",onClick:()=>(async e=>{if(o){h(!0);try{await o(e)}finally{h(!1)}}})(t.id),children:"Excluir"})]})]})]},t.id))]})]})}function Va(e){const{t:a}=V();if(!e)return"";const t=new Date(e);return`${t.toLocaleDateString("pt-BR")} ${t.toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}`}function Ha({history:t=[],isLoading:r=!1}){const{t:n}=V();return r?e("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Carregando histórico..."}):0===t.length?a("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e(D,{className:"h-8 w-8 mb-2 opacity-50"}),e("p",{className:"text-sm",children:n("ap_no_history")})]}):e("div",{className:"p-1",children:a("div",{className:"relative",children:[e("div",{className:"absolute left-4 top-0 bottom-0 w-px bg-border"}),e("div",{className:"space-y-0",children:t.map((t,r)=>a("div",{className:"relative flex gap-4 pb-6 last:pb-0",children:[e("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("span",{className:"text-xs text-primary",children:t.icon}):e("div",{className:"h-2 w-2 rounded-full bg-primary"})}),a("div",{className:"flex-1 min-w-0 rounded-lg border bg-card p-3 space-y-2",children:[a("div",{children:[e("h4",{className:"text-sm font-medium",children:t.translateEvent||t.eventName}),t.eventDescription&&e("p",{className:"text-xs text-muted-foreground",children:t.eventDescription})]}),a("div",{className:"flex items-center gap-2",children:[e("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("img",{src:t.userPhotoUrl,alt:t.userName,className:"h-full w-full object-cover"}):t.userName?.charAt(0)?.toUpperCase()||"?"}),a("div",{className:"min-w-0",children:[e("span",{className:"text-xs font-medium truncate block",children:t.userName}),t.userEmail&&e("span",{className:"text-[10px] text-muted-foreground truncate block",children:t.userEmail})]})]}),a("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[a("div",{className:"flex items-center gap-1",children:[e(R,{className:"h-3 w-3"}),e("span",{children:Oa(t.date)})]}),a("div",{className:"flex items-center gap-1",children:[e(D,{className:"h-3 w-3"}),e("span",{children:$a(t.date)})]}),t.isMobileRequest&&a("div",{className:"flex items-center gap-1",children:[e(A,{className:"h-3 w-3"}),e("span",{children:n("ap_via_app")})]})]})]})]},t.id))})]})})}function Oa(e){const{t:a}=V();return new Date(e).toLocaleDateString("pt-BR")}function $a(e){const{t:a}=V();return new Date(e).toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}function qa({attachments:r=[],onUpload:n,onDelete:s,onRename:o,onDownload:l,onView:c,disabled:m=!1}){const{t:u}=V(),p=d(null),[h,f]=i(null),[g,v]=i(""),b=async e=>{g.trim()&&o&&(await o(e.id,g),f(null),v(""))},x=()=>{f(null),v("")};return a("div",{className:"space-y-4 p-1",children:[!m&&n&&a(t,{children:[e("input",{ref:p,type:"file",multiple:!0,className:"hidden",onChange:e=>{const a=e.target.files;if(a&&n){for(let e=0;e<a.length;e++){const t=a.item(e);t&&n(t)}p.current&&(p.current.value="")}}}),a(de,{size:"sm",onClick:()=>p.current?.click(),children:[e(j,{className:"h-4 w-4 mr-1"}),"Adicionar anexo"]})]}),r.length>0?e("div",{className:"space-y-2",children:r.map(r=>a("div",{className:te("flex items-center gap-3 rounded-lg border bg-card p-3",r.status===De.error&&"border-destructive/50 bg-destructive/5",r.status===De.canceled&&"opacity-50"),children:[e("div",{className:"flex-shrink-0 h-9 w-9 rounded bg-muted flex items-center justify-center",children:e("span",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:r.extension.replace(".","").substring(0,4)})}),a("div",{className:"flex-1 min-w-0 space-y-1",children:[h===r.id?a("div",{className:"flex items-center gap-2",children:[e("input",{className:"flex-1 text-sm border rounded px-2 py-1 bg-background",value:g,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&b(r),"Escape"===e.key&&x()},autoFocus:!0}),e(de,{size:"sm",variant:"outline",onClick:x,children:u("cancel")}),e(de,{size:"sm",onClick:()=>b(r),children:u("save")})]}):e("button",{type:"button",className:"text-sm font-medium truncate block text-left hover:underline cursor-pointer",onClick:()=>c?.(r.id),children:r.name}),(r.status===De.uploading||r.status===De.waiting)&&e(da,{value:r.progress||0,className:"h-1.5"}),r.status===De.error&&e("p",{className:"text-xs text-destructive",children:"Erro ao enviar arquivo"}),r.status===De.duplicateItem&&e("p",{className:"text-xs text-warning",children:"Arquivo duplicado"}),r.status===De.canceled&&e("p",{className:"text-xs text-muted-foreground",children:"Upload cancelado"})]}),a("div",{className:"flex items-center gap-2",children:[r.status===De.done&&a(t,{children:[e("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:Ua(r.size)}),a(le,{children:[e(ce,{asChild:!0,children:e(la,{})}),a(me,{align:"end",children:[o&&!m&&e(ue,{onClick:()=>(e=>{const a=e.name.replace(e.extension,"");f(e.id),v(a)})(r),children:"Renomear"}),c&&e(ue,{onClick:()=>c(r.id),children:"Visualizar"}),l&&e(ue,{onClick:()=>l(r.id),children:"Download"}),s&&!m&&a(t,{children:[e(pe,{}),e(ue,{className:"text-destructive",onClick:()=>s(r.id),children:"Excluir"})]})]})]})]}),r.status===De.uploading&&e(de,{variant:"outline",size:"sm",onClick:()=>s?.(r.id),children:"Cancelar"})]})]},r.id))}):a("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e(T,{className:"h-8 w-8 mb-2 opacity-50"}),e("p",{className:"text-sm",children:"Nenhum anexo adicionado"})]})]})}function Ua(e){const{t:a}=V();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]}`}function Xa(t){const{formData:r,isLoading:n,isSaving:i,activeTab:s,isFormDisabled:o,updateField:d,setActiveTab:l,save:c,changeStatus:m,remove:u,cancel:p}=Ee(t),{t:h}=V(),{isNew:f=!1,config:g,users:v,places:b,actionTypes:x,causes:y,parentActions:N,progress:w,predecessors:C,availablePredecessors:k,costs:D,comments:_,history:S,attachments:P,attachmentsSlot:R,commentsSlot:z,historySlot:j,onAddPredecessor:I,onRemovePredecessor:A,onAddCost:T,onEditCost:F,onDeleteCost:E,onAddComment:L,onEditComment:B,onDeleteComment:H,onUploadAttachment:O,onDeleteAttachment:$,onRenameAttachment:q,onDownloadAttachment:U,onViewAttachment:X}=t;if(n&&!r.id)return e(ge,{isLoading:!0,children:e("div",{})});const K=function(e){const{t:a}=V();if(!e)return[];return{[ve.waitingStart]:[ve.running,ve.suspended,ve.canceled],[ve.running]:[ve.effectivenessCheck,ve.done,ve.suspended,ve.canceled],[ve.effectivenessCheck]:[ve.running,ve.done,ve.suspended,ve.canceled],[ve.done]:[ve.running],[ve.suspended]:[ve.running,ve.canceled],[ve.canceled]:[ve.waitingStart]}[e]||[]}(r.statusId);return a("div",{className:"flex flex-col h-full",children:[a("div",{className:"flex items-center justify-between border-b bg-card px-6 py-4",children:[a("div",{className:"flex items-center gap-4",children:[p&&e(de,{variant:"ghost",size:"icon",onClick:p,children:e(W,{className:"h-4 w-4"})}),a("div",{className:"space-y-1",children:[a("div",{className:"flex items-center gap-3",children:[e("h1",{className:"text-lg font-semibold",children:f?h("ap_new_action"):r.name||h("ap_action_plan")}),!f&&r.statusId&&e(He,{status:r.statusId})]}),r.code&&e("p",{className:"text-xs text-muted-foreground font-mono",children:r.code})]})]}),a("div",{className:"flex items-center gap-2",children:[!f&&K.length>0&&!o&&a(le,{children:[e(ce,{asChild:!0,children:e(de,{variant:"outline",size:"sm",children:"Alterar Status"})}),e(me,{align:"end",children:K.map(a=>e(ue,{onClick:()=>m(a),children:je[a]},a))})]}),!f&&t.onDelete&&a(le,{children:[e(ce,{asChild:!0,children:e(de,{variant:"ghost",size:"icon",children:e(M,{className:"h-4 w-4"})})}),e(me,{align:"end",children:e(ue,{className:"text-destructive",onClick:u,children:"Excluir"})})]})]})]}),e("div",{className:"flex-1 min-h-0 overflow-y-auto",children:e("div",{className:"max-w-4xl mx-auto px-6 py-6",children:a(re,{value:s,onValueChange:l,children:[a(ne,{className:"mb-6",children:[e(ie,{value:"general",children:"Geral"}),!f&&e(ie,{value:"progress",children:"Progresso"}),!f&&g?.enablePredecessors&&e(ie,{value:"predecessors",children:h("ap_predecessors")}),!f&&g?.enableCosts&&e(ie,{value:"costs",children:"Custos"}),!f&&g?.enableAttachments&&e(ie,{value:"attachments",children:h("ap_attachments")}),!f&&g?.enableComments&&e(ie,{value:"comments",children:h("ap_comments")}),!f&&g?.enableHistory&&e(ie,{value:"history",children:"Histórico"})]}),e(se,{value:"general",children:e(sa,{formData:r,updateField:d,disabled:o,users:v,places:b,actionTypes:x,causes:y,parentActions:N,config:g})}),!f&&e(se,{value:"progress",children:e(Ta,{...t})}),!f&&g?.enablePredecessors&&e(se,{value:"predecessors",children:e(Ma,{predecessors:C,availablePredecessors:k,onAdd:I,onRemove:A,disabled:o})}),!f&&g?.enableCosts&&e(se,{value:"costs",children:e(Fa,{costs:D,onAdd:T,onEdit:F,onDelete:E,disabled:o})}),!f&&g?.enableAttachments&&e(se,{value:"attachments",children:R||e(qa,{attachments:P,onUpload:O,onDelete:$,onRename:q,onDownload:U,onView:X,disabled:o})}),!f&&g?.enableComments&&e(se,{value:"comments",children:z||e(Ba,{comments:_,onAdd:L,onEdit:B,onDelete:H,disabled:o})}),!f&&g?.enableHistory&&e(se,{value:"history",children:j||e(Ha,{history:S})})]})})}),a("div",{className:"flex items-center justify-end gap-3 border-t bg-card px-6 py-4",children:[p&&e(de,{variant:"outline",onClick:p,disabled:i,children:"Cancelar"}),e(de,{onClick:c,disabled:i||o,children:i?"Salvando...":"Salvar"})]})]})}La.displayName="Badge";export{qa as ActionPlanAttachmentsTab,Ba as ActionPlanCommentsTab,Fa as ActionPlanCostTab,sa as ActionPlanGeneralTab,Ha as ActionPlanHistoryTab,Xa as ActionPlanPage,Ma as ActionPlanPredecessorsTab,Aa as ActionPlanProgressDialog,Ta as ActionPlanProgressTab,He as ActionPlanStatusBadge,Me as CLOSED_STATUSES,Ae as DEFAULT_ACTION_TYPES,De as EAttachmentItemStatus,Ne as ETaskPlanAssociationType,xe as ETaskPlanPriority,ve as ETaskPlanStatus,Ce as ETaskPlanTypeProgress,We as PRIORITIES,Fe as PROGRESS_ALLOWED_STATUSES,Se as STATUS_COLORS,je as STATUS_LABELS,Re as STATUS_MAP,Pe as STATUS_TEXT_COLORS,ja as formatTime,za as formatTimeProgress,Ie as getActionTypes,Te as getPriorities,Ia as getProgressColor,ze as getStatusLabels,Ee as useActionPlan,ca as useActionPlanProgress};
1
+ import{jsx as e,jsxs as a,Fragment as t}from"react/jsx-runtime";import{StatusBadge as n,Label as i,cn as s,Input as r,Select as l,SelectTrigger as c,SelectValue as d,SelectContent as o,SelectItem as m,DatePicker as u,Textarea as p,Dialog as h,DialogContent as g,DialogHeader as f,DialogTitle as v,DialogFooter as x,Button as N,Progress as b,DropdownMenu as y,DropdownMenuTrigger as C,ActionButton as w,DropdownMenuContent as _,DropdownMenuItem as D,Badge as S,DropdownMenuSeparator as k,LoadingState as P,Tabs as A,TabsList as F,TabsTrigger as I,TabsContent as E}from"forlogic-core";import{X as L,Pause as R,CheckCircle2 as j,ShieldCheck as B,Play as z,Clock as T,Plus as $,MessageSquare as V,Calendar as M,Smartphone as U,Paperclip as O,ArrowLeft as q,MoreVertical as W}from"lucide-react";import H from"i18next";import G,{useState as K,useEffect as J,useCallback as Q,useRef as X}from"react";import{useTranslation as Y}from"react-i18next";var Z,ee,ae,te,ne,ie,se,re,le,ce;(ee=Z||(Z={}))[ee.waitingStart=1]="waitingStart",ee[ee.running=2]="running",ee[ee.effectivenessCheck=3]="effectivenessCheck",ee[ee.done=4]="done",ee[ee.suspended=5]="suspended",ee[ee.canceled=6]="canceled",(te=ae||(ae={}))[te.low=0]="low",te[te.medium=1]="medium",te[te.high=2]="high",(ie=ne||(ne={}))[ie.plan=2]="plan",ie[ie.occurrence=3]="occurrence",ie[ie.risk=4]="risk",ie[ie.decisions=5]="decisions",ie[ie.audit=6]="audit",ie[ie.strategyExtension=7]="strategyExtension",ie[ie.standardization=8]="standardization",ie[ie.supplier=9]="supplier",ie[ie.auditItems=10]="auditItems",(re=se||(se={}))[re.currentProgress=1]="currentProgress",re[re.cumulativeProgress=2]="cumulativeProgress",(ce=le||(le={})).uploading="uploading",ce.waiting="waiting",ce.done="done",ce.error="error",ce.canceled="canceled",ce.duplicateItem="duplicateItem";const de={[Z.waitingStart]:"#D6D6D6",[Z.running]:"#DAE9F4",[Z.effectivenessCheck]:"#1B75BB29",[Z.done]:"#DDEECA",[Z.suspended]:"#FFF2D6",[Z.canceled]:"#F4433629"},oe={[Z.waitingStart]:"#666666",[Z.running]:"#1B75BB",[Z.effectivenessCheck]:"#1B75BB",[Z.done]:"#4CAF50",[Z.suspended]:"#FF9800",[Z.canceled]:"#F44336"},me={[Z.waitingStart]:"waiting-start",[Z.running]:"running",[Z.effectivenessCheck]:"effectiveness-check",[Z.done]:"done",[Z.suspended]:"suspended",[Z.canceled]:"canceled"};function ue(){return{[Z.waitingStart]:H.t("ap_status_waiting_start"),[Z.running]:H.t("ap_status_running"),[Z.effectivenessCheck]:H.t("ap_status_effectiveness_check"),[Z.done]:H.t("ap_status_done"),[Z.suspended]:H.t("ap_status_suspended"),[Z.canceled]:H.t("ap_status_canceled")}}const pe=new Proxy({},{get:(e,a)=>{if("symbol"==typeof a)return;return ue()[a]}});function he(){return[{id:"immediate",label:H.t("ap_type_immediate")},{id:"corrective",label:H.t("ap_type_corrective")},{id:"preventive",label:H.t("ap_type_preventive")},{id:"improvement",label:H.t("ap_type_improvement")},{id:"standardization",label:H.t("ap_type_standardization")}]}const ge=[{id:"immediate",label:"Imediata"},{id:"corrective",label:"Corretiva"},{id:"preventive",label:"Preventiva"},{id:"improvement",label:"Oportunidade de Melhoria"},{id:"standardization",label:"Padronização"}];function fe(){return[{id:ae.low,label:H.t("ap_priority_low"),color:"#4CAF50"},{id:ae.medium,label:H.t("ap_priority_medium"),color:"#FF9800"},{id:ae.high,label:H.t("ap_priority_high"),color:"#F44336"}]}const ve=[{id:ae.low,label:"Baixa",color:"#4CAF50"},{id:ae.medium,label:"Média",color:"#FF9800"},{id:ae.high,label:"Alta",color:"#F44336"}],xe=[Z.done,Z.canceled],Ne=[Z.waitingStart,Z.running,Z.effectivenessCheck,Z.suspended];function be(e){const{actionPlan:a,isNew:t=!1,config:n,onSave:i,onCancel:s,onDelete:r,onChangeStatus:l}=e,[c,d]=K({formData:a||{},isLoading:e.isLoading||!1,isSaving:!1,activeTab:"general",isFormDisabled:!1});J(()=>{a&&d(e=>({...e,formData:a,isFormDisabled:n?.disableFields||xe.includes(a.statusId)}))},[a,n?.disableFields]),J(()=>{d(a=>({...a,isLoading:e.isLoading||!1}))},[e.isLoading]);const o=Q((e,a)=>{d(t=>({...t,formData:{...t.formData,[e]:a}}))},[]),m=Q(e=>{d(a=>({...a,activeTab:e}))},[]),u=Q(async()=>{if(i){d(e=>({...e,isSaving:!0}));try{await i(c.formData)}finally{d(e=>({...e,isSaving:!1}))}}},[i,c.formData]),p=Q(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=Q(async()=>{if(r&&c.formData.id){d(e=>({...e,isLoading:!0}));try{await r(c.formData.id)}finally{d(e=>({...e,isLoading:!1}))}}},[r,c.formData.id]);return{formData:c.formData,isLoading:c.isLoading,isSaving:c.isSaving,activeTab:c.activeTab,isFormDisabled:c.isFormDisabled,updateField:o,setActiveTab:m,save:u,changeStatus:p,remove:h,cancel:s}}const ye={[Z.waitingStart]:{label:"",color:"#8B7355",icon:T},[Z.running]:{label:"",color:"#2E7D5B",icon:z},[Z.effectivenessCheck]:{label:"",color:"#4A6FA5",icon:B},[Z.done]:{label:"",color:"#3D7A40",icon:j},[Z.suspended]:{label:"",color:"#6B7280",icon:R},[Z.canceled]:{label:"",color:"#B44A4A",icon:L}};function Ce({status:a,labels:t,className:i,size:s,showIcon:r,variant:l}){const c=ue(),d=ye[a];if(!d)return null;const o=t?.[a]||c[a]||"";return e(n,{label:o,color:d.color,icon:d.icon,size:s,showIcon:r,variant:l,className:i})}function we({formData:t,updateField:n,disabled:h=!1,users:g=[],places:f=[],actionTypes:v,causes:x=[],parentActions:N=[],config:b}){const{t:y}=Y(),C=b?.requiredFields,w=v||ge,_=e=>{if(b?.hiddenFields?.includes(e))return!1;if(b?.visibleFields&&b.visibleFields.length>0)return b.visibleFields.includes(e);const a=`${e}Visible`;return!C||!(a in C)||!1!==C[a]},D=e=>C?!!C[e]:"name"===e,S=G.useMemo(()=>{if(t.startDate&&t.endDate){const e=new Date(t.startDate),a=new Date(t.endDate).getTime()-e.getTime();return Math.max(0,Math.ceil(a/864e5))}return t.duration||0},[t.startDate,t.endDate,t.duration]);return a("div",{className:"space-y-6 p-1",children:[a("div",{className:"space-y-2",children:[e(i,{className:s(D("name")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Nome"}),e(r,{value:t.name||"",onChange:e=>n("name",e.target.value),maxLength:500,disabled:h,placeholder:y("ap_plan_name_placeholder")})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[_("responsibleWho")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("responsibleWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Responsável"}),a(l,{value:t.responsibleId||"",onValueChange:e=>n("responsibleId",e),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_responsible")})}),e(o,{children:g.map(a=>e(m,{value:a.id,children:a.name},a.id))})]})]}),_("checkerWho")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("checkerWho")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Verificador"}),a(l,{value:t.checkerId||"",onValueChange:e=>n("checkerId",e),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_checker")})}),e(o,{children:g.map(a=>e(m,{value:a.id,children:a.name},a.id))})]})]})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[_("place")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("place")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Local"}),a(l,{value:t.placeId||"",onValueChange:e=>n("placeId",e),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_place")})}),e(o,{children:_e(f).map(a=>e(m,{value:a.id,children:a.name},a.id))})]})]}),_("planType")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("planType")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Tipo de Ação"}),a(l,{value:t.typeId||"",onValueChange:e=>n("typeId",e),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_type")})}),e(o,{children:w.map(a=>e(m,{value:a.id,children:a.label},a.id))})]})]})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[_("priority")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("priority")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Prioridade"}),a(l,{value:t.priorityType?.toString()||"",onValueChange:e=>n("priorityType",Number(e)),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_priority")})}),e(o,{children:ve.map(t=>e(m,{value:t.id.toString(),children:a("span",{className:"flex items-center gap-2",children:[e("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:t.color}}),t.label]})},t.id))})]})]}),N.length>0&&a("div",{className:"space-y-2",children:[e(i,{children:y("ap_belongs_to")}),a(l,{value:t.parentId||"",onValueChange:e=>n("parentId",e),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_parent")})}),e(o,{children:N.map(a=>e(m,{value:a.id,children:a.label},a.id))})]})]})]}),a("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[_("startDate")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("startDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Início"}),e(u,{date:t.startDate?new Date(t.startDate):void 0,onDateChange:e=>n("startDate",e||null),disabled:h,placeholder:y("ap_select_date")})]}),_("endDate")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("endDate")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Data de Término"}),e(u,{date:t.endDate?new Date(t.endDate):void 0,onDateChange:e=>n("endDate",e||null),disabled:h,placeholder:y("ap_select_date"),disabledDates:t.startDate?e=>e<new Date(t.startDate):void 0})]}),a("div",{className:"space-y-2",children:[e(i,{children:y("ap_duration_days")}),e(r,{type:"number",value:S,disabled:!0,className:"bg-muted"})]})]}),_("estimatedCost")&&a("div",{className:"space-y-2 max-w-xs",children:[e(i,{className:s(D("estimatedCost")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Custo Estimado"}),a("div",{className:"relative",children:[e("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"R$"}),e(r,{type:"number",min:0,step:.01,value:t.estimatedCost||"",onChange:e=>n("estimatedCost",Number(e.target.value)),disabled:h,className:"pl-9",placeholder:"0,00"})]})]}),_("cause")&&x.length>0&&a("div",{className:"space-y-2",children:[e(i,{children:"Causa"}),a(l,{value:t.causeId||"",onValueChange:e=>n("causeId",e),disabled:h,children:[e(c,{children:e(d,{placeholder:y("ap_select_cause")})}),e(o,{children:x.map(a=>e(m,{value:a.id,children:a.label},a.id))})]})]}),_("description")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("description")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Descrição"}),e(p,{value:t.description||"",onChange:e=>n("description",e.target.value),maxLength:4e3,disabled:h,rows:4,placeholder:y("ap_description_placeholder")})]}),_("justification")&&a("div",{className:"space-y-2",children:[e(i,{className:s(D("justification")&&"after:content-['*'] after:ml-0.5 after:text-destructive"),children:"Justificativa"}),e(p,{value:t.justification||"",onChange:e=>n("justification",e.target.value),maxLength:4e3,disabled:h,rows:4,placeholder:y("ap_justification_placeholder")})]})]})}function _e(e,a=0){const t=[];for(const n of e)t.push({...n,depth:a}),n.children?.length&&t.push(..._e(n.children,a+1));return t}function De(e){const{progress:a,onReportProgress:t,onEditProgress:n,onDeleteProgress:i}=e,[s,r]=K(!1),[l,c]=K(null),d=!!a&&Ne.includes(a.status),o=Q(async e=>{if(t&&a){r(!0);try{const n=100===e.percentProgress;await t({id:a.id,...e,conclude:n})}finally{r(!1)}}},[t,a]),m=Q(async e=>{if(n){r(!0);try{await n(e)}finally{r(!1),c(null)}}},[n]),u=Q(async e=>{if(i){r(!0);try{await i(e)}finally{r(!1)}}},[i]);return{progress:a,canReportProgress:d,isSubmitting:s,editingReport:l,setEditingReport:c,reportProgress:o,editProgress:m,deleteProgress:u}}function Se(e){if(!e)return"";let a=(e||"").trim();if(!a)return"00:00";if(a.includes(":")){const e=a.split(":");if(e.length>=2){const a=e[0].replace(/\D/g,""),t=e[1].replace(/\D/g,"");let n=parseInt(a)||0,i=parseInt(t)||0;return n+=Math.floor(i/60),i%=60,`${n.toString().padStart(2,"0")}:${i.toString().padStart(2,"0")}`}}if(a=a.replace(/\D/g,""),!a)return"00:00";let t=0,n=0;return 4===a.length?(t=parseInt(a.substring(0,2))||0,n=parseInt(a.substring(2,4))||0,t+=Math.floor(n/60),n%=60):(t=parseInt(a)||0,n=0),`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}function ke(e){if(null==e)return"00:00";const a=String(e).replace(/\D/g,"");if(a.length<3){let e=parseInt(a)||0;const t=Math.floor(e/60);return e%=60,`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}{const e=a.slice(-2),t=a.slice(0,-2);let n=parseInt(t)||0,i=parseInt(e)||0;return n+=Math.floor(i/60),i%=60,`${n.toString().padStart(2,"0")}:${i.toString().padStart(2,"0")}`}}function Pe(e){return 100===e?"#84c148":e>0?"#1b75bb":""}function Ae({open:t,onOpenChange:n,report:s,onSave:l,isSubmitting:c=!1}){const{t:d}=Y(),[o,m]=K(s?.percentProgress||0),[u,b]=K(s?.timeProgress||""),[y,C]=K(s?.comments||""),w=o!==(s?.percentProgress??0)||u!==(s?.timeProgress??"")||y!==(s?.comments??"");G.useEffect(()=>{s&&(m(s.percentProgress),b(s.timeProgress||""),C(s.comments||""))},[s]);return e(h,{open:t,onOpenChange:n,children:a(g,{className:"sm:max-w-md",variant:"form",isDirty:w,children:[e(f,{children:e(v,{children:d("ap_edit_progress")})}),a("div",{className:"space-y-4 py-4",children:[a("div",{className:"space-y-2",children:[e(i,{children:d("ap_progress_percent")}),e(r,{type:"number",min:0,max:100,value:o,onChange:e=>m(Number(e.target.value))})]}),a("div",{className:"space-y-2",children:[e(i,{children:d("ap_time_spent")}),e(r,{value:u,onChange:e=>b(e.target.value),onBlur:()=>b(Se(u)||""),placeholder:"00:00"})]}),a("div",{className:"space-y-2",children:[e(i,{children:d("ap_comments")}),e(p,{value:y,onChange:e=>C(e.target.value),rows:3,maxLength:4e3})]})]}),a(x,{children:[e(N,{variant:"outline",onClick:()=>n(!1),disabled:c,children:"Cancelar"}),e(N,{onClick:()=>{s&&l({...s,percentProgress:o,timeProgress:Se(u)||"00:00",comments:y})},disabled:c,children:c?"Salvando...":"Salvar"})]})]})})}function Fe(t){const{t:n}=Y(),{progress:s,canReportProgress:l,isSubmitting:c,editingReport:d,setEditingReport:o,reportProgress:m,editProgress:u,deleteProgress:h}=De(t),[g,f]=K(""),[v,x]=K(""),[y,C]=K("");if(!s)return e("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Sem dados de progresso disponíveis"});const w=Pe(s.percentProgress),_=!g,D=!g&&!v&&!y;return a("div",{className:"space-y-6 p-1",children:[a("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[a("div",{className:"flex items-center justify-between text-sm",children:[e("span",{className:"font-medium",children:n("ap_overall_progress")}),a("span",{className:"font-semibold",style:{color:w||void 0},children:[s.percentProgress,"%"]})]}),e(b,{value:s.percentProgress,className:"h-3"}),s.timeProgress&&a("div",{className:"text-xs text-muted-foreground",children:["Tempo total: ",ke(s.timeProgress)]})]}),l&&a("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[e("h4",{className:"text-sm font-medium",children:n("ap_report_progress")}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a("div",{className:"space-y-2",children:[e(i,{children:n("ap_progress_percent")}),e(r,{type:"number",min:0,max:100,value:g,onChange:e=>f(e.target.value),placeholder:"0"})]}),a("div",{className:"space-y-2",children:[e(i,{children:n("ap_time_spent")}),e(r,{value:v,onChange:e=>x(e.target.value),onBlur:()=>x(Se(v)||""),placeholder:"00:00"})]})]}),a("div",{className:"space-y-2",children:[e(i,{children:n("ap_comments")}),e(p,{value:y,onChange:e=>C(e.target.value),rows:3,maxLength:4e3,placeholder:n("ap_progress_comment_placeholder")})]}),a("div",{className:"flex gap-2 justify-end",children:[e(N,{variant:"outline",size:"sm",onClick:()=>{f(""),x(""),C("")},disabled:D||c,children:"Limpar"}),e(N,{size:"sm",onClick:async()=>{const e=Number(g);(e||0===e)&&(await m({percentProgress:e,timeProgress:Se(v)||"00:00",comments:y}),f(""),x(""),C(""))},disabled:_||c,children:c?"Reportando...":"Reportar"})]})]}),s.reports.length>0&&a("div",{className:"space-y-3",children:[e("h4",{className:"text-sm font-medium",children:n("ap_reports_history")}),e("div",{className:"space-y-2",children:s.reports.map(a=>e(Ie,{report:a,onEdit:()=>o(a),onDelete:()=>h(a.id),disabled:!l},a.id))})]}),e(Ae,{open:!!d,onOpenChange:e=>!e&&o(null),report:d,onSave:u,isSubmitting:c})]})}function Ie({report:t,onEdit:n,onDelete:i,disabled:s}){const r=t.date?new Date(t.date):null,l=Pe(t.percentProgress);return a("div",{className:"flex items-start gap-3 rounded-lg border bg-card p-3",children:[e("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()||"?"}),a("div",{className:"flex-1 min-w-0 space-y-1",children:[a("div",{className:"flex items-center gap-2 text-sm",children:[e("span",{className:"font-medium truncate",children:t.userName}),r&&e("span",{className:"text-xs text-muted-foreground",children:r.toLocaleDateString("pt-BR")})]}),a("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[a("span",{style:{color:l||void 0},className:"font-semibold",children:[t.percentProgress,"%"]}),t.timeProgress&&a("span",{children:["Tempo: ",ke(t.timeProgress)]})]}),t.comments&&e("p",{className:"text-xs text-muted-foreground mt-1",children:t.comments})]}),!s&&a(y,{children:[e(C,{asChild:!0,children:e(w,{})}),a(_,{align:"end",children:[e(D,{onClick:n,children:H.t("edit")}),e(D,{className:"text-destructive",onClick:i,children:H.t("ap_delete")})]})]})]})}function Ee({predecessors:t=[],availablePredecessors:n=[],onAdd:s,onRemove:r,disabled:u=!1}){const{t:p}=Y(),[h,g]=G.useState(""),f=n.filter(e=>!t.some(a=>a.predecessorId===e.id));return a("div",{className:"space-y-6 p-1",children:[!u&&f.length>0&&a("div",{className:"flex items-end gap-3",children:[a("div",{className:"flex-1 space-y-2",children:[e(i,{children:p("ap_add_predecessor")}),a(l,{value:h,onValueChange:g,children:[e(c,{children:e(d,{placeholder:p("ap_select_action")})}),e(o,{children:f.map(a=>e(m,{value:a.id,children:a.label},a.id))})]})]}),a(N,{size:"sm",onClick:()=>{h&&s&&(s(h),g(""))},disabled:!h,children:[e($,{className:"h-4 w-4 mr-1"}),"Adicionar"]})]}),t.length>0?e("div",{className:"space-y-2",children:t.map(t=>a("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[a("div",{className:"flex items-center gap-3",children:[t.predecessorCode&&e("span",{className:"text-xs text-muted-foreground font-mono",children:t.predecessorCode}),e("span",{className:"text-sm font-medium",children:t.predecessorName}),null!=t.predecessorStatus&&e(Ce,{status:t.predecessorStatus})]}),!u&&r&&a(y,{children:[e(C,{asChild:!0,children:e(w,{})}),e(_,{align:"end",children:e(D,{className:"text-destructive",onClick:()=>r(t.predecessorId),children:"Remover"})})]})]},t.id))}):e("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum predecessor adicionado"})]})}function Le({costs:t=[],onAdd:n,onEdit:s,onDelete:l,disabled:c=!1}){const{t:d}=Y(),[o,m]=K(""),[u,p]=K(""),h=t.reduce((e,a)=>e+(a.value||0),0);return a("div",{className:"space-y-6 p-1",children:[a("div",{className:"rounded-lg border bg-card p-4 flex items-center justify-between",children:[e("span",{className:"text-sm font-medium",children:d("ap_total_cost")}),a("span",{className:"text-lg font-semibold text-foreground",children:["R$ ",h.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),!c&&n&&a("div",{className:"rounded-lg border bg-card p-4 space-y-4",children:[e("h4",{className:"text-sm font-medium",children:d("ap_add_cost")}),a("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a("div",{className:"space-y-2",children:[e(i,{children:"Descrição"}),e(r,{value:o,onChange:e=>m(e.target.value),placeholder:d("ap_cost_description")})]}),a("div",{className:"space-y-2",children:[e(i,{children:"Valor (R$)"}),e(r,{type:"number",min:0,step:.01,value:u,onChange:e=>p(e.target.value),placeholder:"0,00"})]})]}),e("div",{className:"flex justify-end",children:a(N,{size:"sm",onClick:()=>{o&&u&&n&&(n({description:o,value:Number(u),date:(new Date).toISOString()}),m(""),p(""))},disabled:!o||!u,children:[e($,{className:"h-4 w-4 mr-1"}),"Adicionar"]})})]}),t.length>0?e("div",{className:"space-y-2",children:t.map(t=>a("div",{className:"flex items-center justify-between rounded-lg border bg-card p-3",children:[a("div",{className:"flex-1 min-w-0",children:[e("p",{className:"text-sm font-medium truncate",children:t.description}),t.date&&e("p",{className:"text-xs text-muted-foreground",children:new Date(t.date).toLocaleDateString("pt-BR")})]}),a("div",{className:"flex items-center gap-3",children:[a("span",{className:"text-sm font-semibold whitespace-nowrap",children:["R$ ",t.value.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2})]}),!c&&(s||l)&&a(y,{children:[e(C,{asChild:!0,children:e(w,{})}),a(_,{align:"end",children:[s&&e(D,{onClick:()=>s(t),children:d("edit")}),l&&e(D,{className:"text-destructive",onClick:()=>l(t.id),children:d("ap_delete")})]})]})]})]},t.id))}):e("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"Nenhum custo registrado"})]})}function Re({comments:t=[],currentUserId:n,onAdd:i,onEdit:s,onDelete:r,disabled:l=!1,maxLength:c=4e3}){const{t:d}=Y(),[o,m]=K(""),[u,h]=K(!1),[g,f]=K(null),[v,x]=K(""),b=()=>{f(null),x("")};return a("div",{className:"space-y-6 p-1",children:[!l&&i&&a("div",{className:"space-y-3",children:[e(p,{value:o,onChange:e=>m(e.target.value),placeholder:d("ap_add_comment_placeholder"),maxLength:c,rows:3}),a("div",{className:"flex items-center justify-between",children:[c&&a("span",{className:"text-xs text-muted-foreground",children:[o.length,"/",c]}),a("div",{className:"flex gap-2 ml-auto",children:[e(N,{variant:"outline",size:"sm",onClick:()=>m(""),disabled:!o||u,children:"Limpar"}),e(N,{size:"sm",onClick:async()=>{if(o.trim()&&i){h(!0);try{await i(o),m("")}finally{h(!1)}}},disabled:!o.trim()||u,children:u?"Enviando...":"Comentar"})]})]})]}),a("div",{className:"space-y-1",children:[t.length>0?a("div",{className:"flex items-center gap-2 mb-3",children:[e("span",{className:"text-sm font-medium",children:d("ap_comments")}),e(S,{variant:"info",className:"text-[10px] px-1.5 py-0",children:t.length})]}):a("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e(V,{className:"h-8 w-8 mb-2 opacity-50"}),e("p",{className:"text-sm",children:"Nenhum comentário adicionado"})]}),t.map(t=>a("div",{className:"flex gap-3 rounded-lg border bg-card p-3",children:[e("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("img",{src:t.userPhotoUrl,alt:t.userName,className:"h-full w-full object-cover"}):t.userName?.charAt(0)?.toUpperCase()||"?"}),a("div",{className:"flex-1 min-w-0 space-y-1",children:[a("div",{className:"flex items-center gap-2 text-sm",children:[e("span",{className:"font-medium truncate",children:t.userName}),t.userEmail&&e("span",{className:"text-xs text-muted-foreground truncate",children:t.userEmail}),e("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:je(t.dateEdited||t.dateCreation)}),t.dateEdited&&e("span",{className:"text-xs text-muted-foreground italic",children:"editado"})]}),g===t.id?a("div",{className:"space-y-2",children:[e(p,{value:v,onChange:e=>x(e.target.value),maxLength:c,rows:3}),a("div",{className:"flex gap-2 justify-end",children:[e(N,{variant:"outline",size:"sm",onClick:b,disabled:u,children:"Cancelar"}),e(N,{size:"sm",onClick:()=>(async e=>{if(v.trim()&&s){h(!0);try{await s({...e,text:v,stringText:v}),f(null),x("")}finally{h(!1)}}})(t),disabled:!v.trim()||u,children:u?"Salvando...":"Salvar"})]})]}):e("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.stringText||t.text})]}),!l&&n===t.userId&&g!==t.id&&a(y,{children:[e(C,{asChild:!0,children:e(w,{})}),a(_,{align:"end",children:[s&&e(D,{onClick:()=>(e=>{f(e.id),x(e.stringText||e.text)})(t),children:d("edit")}),r&&e(D,{className:"text-destructive",onClick:()=>(async e=>{if(r){h(!0);try{await r(e)}finally{h(!1)}}})(t.id),children:"Excluir"})]})]})]},t.id))]})]})}function je(e){const{t:a}=Y();if(!e)return"";const t=new Date(e);return`${t.toLocaleDateString("pt-BR")} ${t.toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}`}function Be({history:t=[],isLoading:n=!1}){const{t:i}=Y();return n?e("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Carregando histórico..."}):0===t.length?a("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e(T,{className:"h-8 w-8 mb-2 opacity-50"}),e("p",{className:"text-sm",children:i("ap_no_history")})]}):e("div",{className:"p-1",children:a("div",{className:"relative",children:[e("div",{className:"absolute left-4 top-0 bottom-0 w-px bg-border"}),e("div",{className:"space-y-0",children:t.map((t,n)=>a("div",{className:"relative flex gap-4 pb-6 last:pb-0",children:[e("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("span",{className:"text-xs text-primary",children:t.icon}):e("div",{className:"h-2 w-2 rounded-full bg-primary"})}),a("div",{className:"flex-1 min-w-0 rounded-lg border bg-card p-3 space-y-2",children:[a("div",{children:[e("h4",{className:"text-sm font-medium",children:t.translateEvent||t.eventName}),t.eventDescription&&e("p",{className:"text-xs text-muted-foreground",children:t.eventDescription})]}),a("div",{className:"flex items-center gap-2",children:[e("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("img",{src:t.userPhotoUrl,alt:t.userName,className:"h-full w-full object-cover"}):t.userName?.charAt(0)?.toUpperCase()||"?"}),a("div",{className:"min-w-0",children:[e("span",{className:"text-xs font-medium truncate block",children:t.userName}),t.userEmail&&e("span",{className:"text-[10px] text-muted-foreground truncate block",children:t.userEmail})]})]}),a("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[a("div",{className:"flex items-center gap-1",children:[e(M,{className:"h-3 w-3"}),e("span",{children:ze(t.date)})]}),a("div",{className:"flex items-center gap-1",children:[e(T,{className:"h-3 w-3"}),e("span",{children:Te(t.date)})]}),t.isMobileRequest&&a("div",{className:"flex items-center gap-1",children:[e(U,{className:"h-3 w-3"}),e("span",{children:i("ap_via_app")})]})]})]})]},t.id))})]})})}function ze(e){const{t:a}=Y();return new Date(e).toLocaleDateString("pt-BR")}function Te(e){const{t:a}=Y();return new Date(e).toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}function $e({attachments:n=[],onUpload:i,onDelete:r,onRename:l,onDownload:c,onView:d,disabled:o=!1}){const{t:m}=Y(),u=X(null),[p,h]=K(null),[g,f]=K(""),v=async e=>{g.trim()&&l&&(await l(e.id,g),h(null),f(""))},x=()=>{h(null),f("")};return a("div",{className:"space-y-4 p-1",children:[!o&&i&&a(t,{children:[e("input",{ref:u,type:"file",multiple:!0,className:"hidden",onChange:e=>{const a=e.target.files;if(a&&i){for(let e=0;e<a.length;e++){const t=a.item(e);t&&i(t)}u.current&&(u.current.value="")}}}),a(N,{size:"sm",onClick:()=>u.current?.click(),children:[e($,{className:"h-4 w-4 mr-1"}),"Adicionar anexo"]})]}),n.length>0?e("div",{className:"space-y-2",children:n.map(n=>a("div",{className:s("flex items-center gap-3 rounded-lg border bg-card p-3",n.status===le.error&&"border-destructive/50 bg-destructive/5",n.status===le.canceled&&"opacity-50"),children:[e("div",{className:"flex-shrink-0 h-9 w-9 rounded bg-muted flex items-center justify-center",children:e("span",{className:"text-[10px] font-bold uppercase text-muted-foreground",children:n.extension.replace(".","").substring(0,4)})}),a("div",{className:"flex-1 min-w-0 space-y-1",children:[p===n.id?a("div",{className:"flex items-center gap-2",children:[e("input",{className:"flex-1 text-sm border rounded px-2 py-1 bg-background",value:g,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&v(n),"Escape"===e.key&&x()},autoFocus:!0}),e(N,{size:"sm",variant:"outline",onClick:x,children:m("cancel")}),e(N,{size:"sm",onClick:()=>v(n),children:m("save")})]}):e("button",{type:"button",className:"text-sm font-medium truncate block text-left hover:underline cursor-pointer",onClick:()=>d?.(n.id),children:n.name}),(n.status===le.uploading||n.status===le.waiting)&&e(b,{value:n.progress||0,className:"h-1.5"}),n.status===le.error&&e("p",{className:"text-xs text-destructive",children:"Erro ao enviar arquivo"}),n.status===le.duplicateItem&&e("p",{className:"text-xs text-warning",children:"Arquivo duplicado"}),n.status===le.canceled&&e("p",{className:"text-xs text-muted-foreground",children:"Upload cancelado"})]}),a("div",{className:"flex items-center gap-2",children:[n.status===le.done&&a(t,{children:[e("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:Ve(n.size)}),a(y,{children:[e(C,{asChild:!0,children:e(w,{})}),a(_,{align:"end",children:[l&&!o&&e(D,{onClick:()=>(e=>{const a=e.name.replace(e.extension,"");h(e.id),f(a)})(n),children:"Renomear"}),d&&e(D,{onClick:()=>d(n.id),children:"Visualizar"}),c&&e(D,{onClick:()=>c(n.id),children:"Download"}),r&&!o&&a(t,{children:[e(k,{}),e(D,{className:"text-destructive",onClick:()=>r(n.id),children:"Excluir"})]})]})]})]}),n.status===le.uploading&&e(N,{variant:"outline",size:"sm",onClick:()=>r?.(n.id),children:"Cancelar"})]})]},n.id))}):a("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e(O,{className:"h-8 w-8 mb-2 opacity-50"}),e("p",{className:"text-sm",children:"Nenhum anexo adicionado"})]})]})}function Ve(e){const{t:a}=Y();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]}`}function Me(t){const{formData:n,isLoading:i,isSaving:s,activeTab:r,isFormDisabled:l,updateField:c,setActiveTab:d,save:o,changeStatus:m,remove:u,cancel:p}=be(t),{t:h}=Y(),{isNew:g=!1,config:f,users:v,places:x,actionTypes:b,causes:w,parentActions:S,progress:k,predecessors:L,availablePredecessors:R,costs:j,comments:B,history:z,attachments:T,attachmentsSlot:$,commentsSlot:V,historySlot:M,onAddPredecessor:U,onRemovePredecessor:O,onAddCost:H,onEditCost:G,onDeleteCost:K,onAddComment:J,onEditComment:Q,onDeleteComment:X,onUploadAttachment:ee,onDeleteAttachment:ae,onRenameAttachment:te,onDownloadAttachment:ne,onViewAttachment:ie}=t;if(i&&!n.id)return e(P,{isLoading:!0,children:e("div",{})});const se=function(e){const{t:a}=Y();if(!e)return[];return{[Z.waitingStart]:[Z.running,Z.suspended,Z.canceled],[Z.running]:[Z.effectivenessCheck,Z.done,Z.suspended,Z.canceled],[Z.effectivenessCheck]:[Z.running,Z.done,Z.suspended,Z.canceled],[Z.done]:[Z.running],[Z.suspended]:[Z.running,Z.canceled],[Z.canceled]:[Z.waitingStart]}[e]||[]}(n.statusId);return a("div",{className:"flex flex-col h-full",children:[a("div",{className:"flex items-center justify-between border-b bg-card px-6 py-4",children:[a("div",{className:"flex items-center gap-4",children:[p&&e(N,{variant:"ghost",size:"icon",onClick:p,children:e(q,{className:"h-4 w-4"})}),a("div",{className:"space-y-1",children:[a("div",{className:"flex items-center gap-3",children:[e("h1",{className:"text-lg font-semibold",children:g?h("ap_new_action"):n.name||h("ap_action_plan")}),!g&&n.statusId&&e(Ce,{status:n.statusId})]}),n.code&&e("p",{className:"text-xs text-muted-foreground font-mono",children:n.code})]})]}),a("div",{className:"flex items-center gap-2",children:[!g&&se.length>0&&!l&&a(y,{children:[e(C,{asChild:!0,children:e(N,{variant:"outline",size:"sm",children:"Alterar Status"})}),e(_,{align:"end",children:se.map(a=>e(D,{onClick:()=>m(a),children:pe[a]},a))})]}),!g&&t.onDelete&&a(y,{children:[e(C,{asChild:!0,children:e(N,{variant:"ghost",size:"icon",children:e(W,{className:"h-4 w-4"})})}),e(_,{align:"end",children:e(D,{className:"text-destructive",onClick:u,children:"Excluir"})})]})]})]}),e("div",{className:"flex-1 min-h-0 overflow-y-auto",children:e("div",{className:"max-w-4xl mx-auto px-6 py-6",children:a(A,{value:r,onValueChange:d,children:[a(F,{className:"mb-6",children:[e(I,{value:"general",children:"Geral"}),!g&&e(I,{value:"progress",children:"Progresso"}),!g&&f?.enablePredecessors&&e(I,{value:"predecessors",children:h("ap_predecessors")}),!g&&f?.enableCosts&&e(I,{value:"costs",children:"Custos"}),!g&&f?.enableAttachments&&e(I,{value:"attachments",children:h("ap_attachments")}),!g&&f?.enableComments&&e(I,{value:"comments",children:h("ap_comments")}),!g&&f?.enableHistory&&e(I,{value:"history",children:"Histórico"})]}),e(E,{value:"general",children:e(we,{formData:n,updateField:c,disabled:l,users:v,places:x,actionTypes:b,causes:w,parentActions:S,config:f})}),!g&&e(E,{value:"progress",children:e(Fe,{...t})}),!g&&f?.enablePredecessors&&e(E,{value:"predecessors",children:e(Ee,{predecessors:L,availablePredecessors:R,onAdd:U,onRemove:O,disabled:l})}),!g&&f?.enableCosts&&e(E,{value:"costs",children:e(Le,{costs:j,onAdd:H,onEdit:G,onDelete:K,disabled:l})}),!g&&f?.enableAttachments&&e(E,{value:"attachments",children:$||e($e,{attachments:T,onUpload:ee,onDelete:ae,onRename:te,onDownload:ne,onView:ie,disabled:l})}),!g&&f?.enableComments&&e(E,{value:"comments",children:V||e(Re,{comments:B,onAdd:J,onEdit:Q,onDelete:X,disabled:l})}),!g&&f?.enableHistory&&e(E,{value:"history",children:M||e(Be,{history:z})})]})})}),a("div",{className:"flex items-center justify-end gap-3 border-t bg-card px-6 py-4",children:[p&&e(N,{variant:"outline",onClick:p,disabled:s,children:"Cancelar"}),e(N,{onClick:o,disabled:s||l,children:s?"Salvando...":"Salvar"})]})]})}export{$e as ActionPlanAttachmentsTab,Re as ActionPlanCommentsTab,Le as ActionPlanCostTab,we as ActionPlanGeneralTab,Be as ActionPlanHistoryTab,Me as ActionPlanPage,Ee as ActionPlanPredecessorsTab,Ae as ActionPlanProgressDialog,Fe as ActionPlanProgressTab,Ce as ActionPlanStatusBadge,xe as CLOSED_STATUSES,ge as DEFAULT_ACTION_TYPES,le as EAttachmentItemStatus,ne as ETaskPlanAssociationType,ae as ETaskPlanPriority,Z as ETaskPlanStatus,se as ETaskPlanTypeProgress,ve as PRIORITIES,Ne as PROGRESS_ALLOWED_STATUSES,de as STATUS_COLORS,pe as STATUS_LABELS,me as STATUS_MAP,oe as STATUS_TEXT_COLORS,ke as formatTime,Se as formatTimeProgress,he as getActionTypes,fe as getPriorities,Pe as getProgressColor,ue as getStatusLabels,be as useActionPlan,De as useActionPlanProgress};