@qumra/fanar 0.0.11 → 0.0.13

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.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # `@qumra/fanar`
2
2
 
3
3
  Qumra's component library and design tokens — **Arabic-first**, Tailwind 4,
4
- RSC-safe.
4
+ RSC-safe, and **one package for both React DOM and React Native**.
5
5
 
6
6
  Every component works in both `dir="rtl"` and `dir="ltr"` with no
7
7
  direction-specific code: logical properties only, and the library reads its
8
- own language from `<html lang>`.
8
+ own language from `<html lang>` (from the device locale on native).
9
9
 
10
10
  ```bash
11
11
  pnpm add @qumra/fanar
@@ -27,8 +27,8 @@ system — each heavy group is behind its own path.
27
27
  | `@qumra/fanar/orb` | Animated voice orb | needs `three`, `@react-three/fiber`, `@react-three/drei` |
28
28
  | `@qumra/fanar/editor` | Rich-text editor | bundles TipTap |
29
29
 
30
- Plus two stylesheets: `@qumra/fanar/tokens.css` and
31
- `@qumra/fanar/editor.css`.
30
+ Plus two stylesheets: `@qumra/fanar/tokens.css` and `@qumra/fanar/editor.css`.
31
+ Native needs neither — it reads the same tokens as values, not as CSS.
32
32
 
33
33
  ## Setup
34
34
 
@@ -48,6 +48,111 @@ import { TOKENS } from '@qumra/fanar/tokens'
48
48
  </Button>
49
49
  ```
50
50
 
51
+ ## React Native
52
+
53
+ The same package serves native. There is no `@qumra/fanar-native` — a second
54
+ package would mean a second copy of every token, variant, size and prop
55
+ contract, and copies drift.
56
+
57
+ What makes one package work is that the parts that change often are shared
58
+ outright. `buttonClasses('primary', 'md')` returns the **same class string**
59
+ on both platforms; only the final element differs (`<button>` vs
60
+ `<Pressable>`). Change a token, a variant, or a size once, and both platforms
61
+ move together.
62
+
63
+ Resolution is automatic: Metro picks `Button.native.tsx` over `Button.tsx`,
64
+ and the published package routes the `react-native` export condition to a
65
+ native build.
66
+
67
+ ### Requirements
68
+
69
+ React Native **0.80+** and [twrnc](https://github.com/jaredh159/tailwind-react-native-classnames).
70
+
71
+ ```bash
72
+ pnpm add @qumra/fanar twrnc lucide-react-native react-native-svg
73
+ ```
74
+
75
+ That is the whole native setup. There is **no Metro transformer, no Babel
76
+ preset, no CSS file, and no Tailwind install** — twrnc resolves class strings
77
+ at runtime, and the library builds its Tailwind config from the very same
78
+ `tokens.json` the web `@theme` block is generated from.
79
+
80
+ The earlier NativeWind route needed `metro.config.js` and `babel.config.js`
81
+ changes plus `tailwindcss@4`, `react-native-css` and RN 0.81; the app this
82
+ library targets runs RN 0.80 with a stock Metro config, so that cost was
83
+ real and the runtime route is what ships.
84
+
85
+ ### Setup
86
+
87
+ None. Import and render:
88
+
89
+ ```tsx
90
+ import { Button, Card, Input } from '@qumra/fanar'
91
+ ;<Card>
92
+ <Input label="رقم الهاتف" numeric />
93
+ <Button variant="primary" onPress={save}>
94
+ احفظ
95
+ </Button>
96
+ </Card>
97
+ ```
98
+
99
+ `onClick` works too — the prop contract is the web one, so a screen written
100
+ once runs on both.
101
+
102
+ ### Layout
103
+
104
+ One folder per component, holding both platforms and what they share:
105
+
106
+ ```
107
+ src/Button/
108
+ index.tsx web
109
+ index.native.tsx native
110
+ index.test.tsx
111
+ index.native.test.tsx
112
+ src/Form/
113
+ index.tsx
114
+ index.native.tsx
115
+ variants.ts the styles both platforms import
116
+
117
+ ```
118
+
119
+ `variants.ts` is the point of the whole arrangement: the class strings,
120
+ scales and pure calculations live there, and the two `index` files import
121
+ them. Change a size once and both platforms move. A native file is not
122
+ allowed to define styles of its own — the tests compare what it renders
123
+ against those constants, so drift fails the build.
124
+
125
+ Metro picks `index.native.tsx` over `index.tsx` automatically; TypeScript and
126
+ web bundlers see `index.tsx`.
127
+
128
+ ### What is available on native
129
+
130
+ **19 of 23 component modules**, ~105 exports: `Button`, `Form` (8 fields),
131
+ `Display` (9), `Nav`, `Overlay`, `Feedback`, `Menu`, `Money`, `Phone`,
132
+ `Chart` (5), `Commerce` (4), `Choice`, `Disclosure`, `Provider`, `Rating`,
133
+ `NumberStepper`, `DateRange`, `Technical`, `Upload` — plus every pure helper
134
+ and all tokens.
135
+
136
+ Still web-only, each with a reason in `PROGRESS.md`: `Carousel`/`Gallery`/
137
+ `Lightbox`, `DataTable`, `Sortable`, `media` (video/audio players), `coach`,
138
+ `Product3DViewer`, `BrowserFrame`.
139
+
140
+ `src/native/parity.test.ts` fails the build if a new web export is added
141
+ without either porting it or recording why not, so that list cannot grow
142
+ quietly. The `/editor`, `/orb`, `/notifications` and `/ai` entry points
143
+ resolve to stubs that throw a readable message rather than a stray
144
+ `document is not defined`.
145
+
146
+ ### Three differences worth knowing
147
+
148
+ 1. **React Native does not inherit text styles.** A class string is split
149
+ across the container and the text node automatically
150
+ (`splitTypography`) — you pass one `className` as usual.
151
+ 2. **There is no `currentColor`.** Icons take their colour as a prop,
152
+ resolved from the same tokens (`useTextColor`).
153
+ 3. **`aria-*` becomes `accessibility*`.** You still write `aria-label`; the
154
+ native components translate it.
155
+
51
156
  ## The six rules
52
157
 
53
158
  Every component in this library follows them, and two are enforced by lint:
@@ -64,10 +169,12 @@ Every component in this library follows them, and two are enforced by lint:
64
169
 
65
170
  ## Peer dependencies
66
171
 
67
- `react` and `react-dom` are required. `tailwindcss`, `three`,
68
- `@react-three/fiber`, `@react-three/drei`, `@google/model-viewer`, and
69
- `@qumra/jawab-ai` are **optional** — you only install the ones whose entry
70
- point you actually import.
172
+ `react` is required; `react-dom` for web. `tailwindcss`, `three`,
173
+ `@react-three/fiber`, `@react-three/drei`, `@google/model-viewer`,
174
+ `@qumra/jawab-ai`, `react-native`, `twrnc`,
175
+ `lucide-react-native` and `react-native-svg` are **optional** — you only
176
+ install the ones whose entry point and platform you actually use. A web-only
177
+ consumer installs nothing from the native list.
71
178
 
72
179
  This is not a formality. `@react-three/drei` pulls in `camera-controls`,
73
180
  which requires Node 22; as a hard dependency it broke `yarn install` on a
package/dist/ai.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{BarChart,ChoiceCards,DataTable,Money,TrendChart,isCurrency}from"./chunk-77ZZDWR4.js";import{Button,Input,Textarea}from"./chunk-VAMRF7HE.js";import{Badge,Card,StatCard,formatTime}from"./chunk-GMIBQMMR.js";import{Alert,Modal,cn,useUIText}from"./chunk-ZE4S6DBP.js";import{useEffect,useRef,useState}from"react";import{Bot,Check,Copy,ExternalLink,RotateCcw,ThumbsDown,ThumbsUp,TriangleAlert}from"lucide-react";import{Fragment,jsx,jsxs}from"react/jsx-runtime";function AiAvatar({state="idle",level,size="md",icon:Icon=Bot}){const ring=useRef(null);useEffect(()=>{if(state!=="speaking"||!level)return;let raf=0;const loop=()=>{const v=level.current??0;if(ring.current){ring.current.style.transform=`scale(${1+v**1.6*.9})`;ring.current.style.opacity=String(Math.min(.45,v))}raf=requestAnimationFrame(loop)};raf=requestAnimationFrame(loop);const el=ring.current;return()=>{cancelAnimationFrame(raf);if(el)el.style.opacity="0"}},[state,level]);const box={sm:"size-8",md:"size-9",lg:"size-12"}[size];const px={sm:16,md:18,lg:24}[size];return jsxs("span",{className:"relative inline-flex shrink-0",children:[jsx("span",{ref:ring,"aria-hidden":"true",className:cn("absolute inset-0 rounded-sm bg-brand opacity-0",box),style:{transition:"transform 90ms linear, opacity 90ms linear"}}),jsx("span",{"aria-hidden":"true",className:cn("relative rounded-sm bg-soft border border-soft2 flex items-center justify-center",box,state==="thinking"&&"animate-pulse"),children:jsx(Icon,{size:px,strokeWidth:2,className:"text-brand"})})]})}function AiThinking({label}){const ui=useUIText();return jsxs("span",{role:"status","aria-live":"polite",className:"flex items-center gap-2.5",children:[jsx(AiAvatar,{size:"sm",state:"thinking"}),jsxs("span",{className:"flex items-center gap-2 py-2.5 px-3.5 rounded-card bg-bg border border-line",children:[jsx("span",{"aria-hidden":"true",className:"flex items-center gap-1",children:[0,1,2].map(i=>jsx("span",{className:"size-1.5 rounded-full bg-muted2 animate-bounce",style:{animationDelay:`${i*140}ms`,animationDuration:"900ms"}},i))}),jsx("span",{className:"text-caption text-muted",children:label??ui.shehabThinking})]})]})}function AiToolCall({icon:Icon,title,detail,state="done",onUndo,undoLabel}){const ui=useUIText();const tone={running:"bg-bg border-line text-muted",done:"bg-green-bg2 border-green-line text-green",failed:"bg-red-bg border-red-line text-red",reverted:"bg-bg border-line text-muted2"}[state];const off=state==="reverted";return jsxs("div",{className:cn("flex items-start gap-2.5 p-3 rounded-card border",tone),children:[jsx("span",{"aria-hidden":"true",className:"shrink-0 mt-0.5",children:state==="failed"?jsx(TriangleAlert,{size:15}):off?jsx(RotateCcw,{size:15}):state==="done"?jsx(Check,{size:15}):Icon?jsx(Icon,{size:15}):jsx("span",{className:"block size-3.5 rounded-full border-2 border-current border-t-transparent animate-spin"})}),jsxs("span",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[jsx("span",{className:cn("text-ui font-bold",off?"text-muted":"text-ink"),children:title}),detail&&jsx("span",{className:cn("text-caption leading-[1.7]",off?"text-muted2 line-through":"text-ink2"),children:detail})]}),onUndo&&state==="done"&&jsx("button",{type:"button",onClick:onUndo,className:"shrink-0 text-caption font-bold text-brand-ink cursor-pointer hover:underline underline-offset-4",children:undoLabel??ui.undo})]})}function AiSources({sources,label}){const ui=useUIText();if(sources.length===0)return null;return jsxs("span",{className:"flex items-center gap-1.5 flex-wrap",children:[jsx("span",{className:"text-micro text-muted2",children:label??ui.from}),sources.map(s=>{const inner=jsxs(Fragment,{children:[s.label,jsx(ExternalLink,{size:10,"aria-hidden":"true"})]});const cls="inline-flex items-center gap-1 h-6 px-2 rounded-full bg-soft text-brand-ink text-micro font-bold no-underline cursor-pointer transition-colors hover:bg-soft2";return s.href?jsx("a",{href:s.href,className:cls,children:inner},s.id):jsx("button",{type:"button",onClick:s.onOpen,className:cls,children:inner},s.id)})]})}function AiMessage({role,children,streaming,sources,copyText,onRetry,onFeedback,tools,fill}){const ui=useUIText();const[copied,setCopied]=useState(false);const[vote,setVote]=useState(null);const user=role==="user";const actionable=!user&&!streaming&&(copyText||onRetry||onFeedback);return jsxs("div",{className:cn("flex gap-2.5",fill?"w-full":"max-w-[88%]",user?"self-end":"self-start"),children:[!user&&jsx(AiAvatar,{size:"sm"}),jsxs("div",{className:cn("flex flex-col gap-2 min-w-0",fill&&"flex-1"),children:[jsxs("div",{dir:"auto",className:cn("py-2.5 px-3.5 rounded-card text-ui leading-[1.85] whitespace-pre-line",user?"bg-brand text-white":"bg-bg text-ink border border-line"),children:[children,streaming&&jsx("span",{"aria-hidden":"true",className:"inline-block w-[2px] h-[1em] align-[-2px] ms-0.5 bg-brand animate-pulse"})]}),tools,sources&&sources.length>0&&!streaming&&jsx(AiSources,{sources}),actionable&&jsxs("div",{className:"flex items-center gap-0.5",children:[copyText&&jsx(ActionBtn,{label:copied?"\u0627\u062A\u0646\u0633\u062E":"\u0646\u0633\u062E",onClick:()=>{navigator.clipboard?.writeText(copyText);setCopied(true);setTimeout(()=>setCopied(false),1400)},children:copied?jsx(Check,{size:13,className:"text-green"}):jsx(Copy,{size:13})}),onRetry&&jsx(ActionBtn,{label:ui.tryAnotherReply,onClick:onRetry,children:jsx(RotateCcw,{size:13})}),onFeedback&&jsxs(Fragment,{children:[jsx(ActionBtn,{label:ui.helpfulReply,active:vote==="up",onClick:()=>{setVote("up");onFeedback("up")},children:jsx(ThumbsUp,{size:13})}),jsx(ActionBtn,{label:ui.unhelpfulReply,active:vote==="down",onClick:()=>{setVote("down");onFeedback("down")},children:jsx(ThumbsDown,{size:13})})]})]})]})]})}function ActionBtn({onClick,label,active,children}){return jsx("button",{type:"button",onClick,"aria-label":label,title:label,"aria-pressed":active,className:cn("size-7 rounded-xs inline-flex items-center justify-center cursor-pointer transition-colors",active?"bg-soft text-brand-ink":"text-muted2 hover:bg-hover hover:text-ink"),children})}function AiDisclaimer({children}){const ui=useUIText();return jsx("span",{className:"block text-center text-micro leading-[1.7] text-muted2 [text-wrap:pretty]",children:children??ui.aiDisclaimer})}import{useEffect as useEffect3,useRef as useRef3}from"react";import{ArrowUp,Mic,Paperclip,Square,Trash2}from"lucide-react";import{useCallback,useEffect as useEffect2,useRef as useRef2,useState as useState2}from"react";function useStreamingText({speed=18}={}){const[shown,setShown]=useState2("");const[streaming,setStreaming]=useState2(false);const full=useRef2("");const timer=useRef2(void 0);const stopTimer=useCallback(()=>{clearInterval(timer.current);timer.current=void 0},[]);useEffect2(()=>stopTimer,[stopTimer]);const run=useCallback(()=>{if(timer.current)return;timer.current=setInterval(()=>{setShown(s=>{if(s.length>=full.current.length){stopTimer();setStreaming(false);return s}return full.current.slice(0,s.length+1)})},speed)},[speed,stopTimer]);const start=useCallback(text=>{stopTimer();full.current=text;setShown("");setStreaming(true);run()},[run,stopTimer]);const push=useCallback(chunk=>{full.current+=chunk;setStreaming(true);run()},[run]);const stop=useCallback(()=>{stopTimer();full.current=shown;setStreaming(false)},[shown,stopTimer]);const finish=useCallback(()=>{stopTimer();setShown(full.current);setStreaming(false)},[stopTimer]);const reset=useCallback(()=>{stopTimer();full.current="";setShown("");setStreaming(false)},[stopTimer]);return{text:shown,streaming,start,push,stop,finish,reset}}function useMicLevel(){const level=useRef2(0);const[recording,setRecording]=useState2(false);const[seconds,setSeconds]=useState2(0);const[denied,setDenied]=useState2(false);const stream=useRef2(null);const ctx=useRef2(null);const raf=useRef2(0);const tick=useRef2(void 0);const stop=useCallback(()=>{cancelAnimationFrame(raf.current);clearInterval(tick.current);stream.current?.getTracks().forEach(t=>t.stop());void ctx.current?.close();stream.current=null;ctx.current=null;level.current=0;setRecording(false);setSeconds(0)},[]);useEffect2(()=>stop,[stop]);const start=useCallback(async()=>{if(recording)return;try{const media=await navigator.mediaDevices.getUserMedia({audio:true});const Ctx=window.AudioContext??window.webkitAudioContext;if(!Ctx)throw new Error("\u0645\u0627\u0641\u064A\u0634 Web Audio");const c=new Ctx;const src=c.createMediaStreamSource(media);const analyser=c.createAnalyser();analyser.fftSize=512;analyser.smoothingTimeConstant=.7;src.connect(analyser);stream.current=media;ctx.current=c;setDenied(false);setRecording(true);setSeconds(0);const data=new Uint8Array(analyser.frequencyBinCount);const loop=()=>{analyser.getByteTimeDomainData(data);let sum=0;for(let i=0;i<data.length;i++){const v=(data[i]-128)/128;sum+=v*v}level.current=Math.min(1,Math.sqrt(sum/data.length)*3);raf.current=requestAnimationFrame(loop)};raf.current=requestAnimationFrame(loop);tick.current=setInterval(()=>setSeconds(s=>s+1),1e3)}catch{setDenied(true);setRecording(false)}},[recording]);return{level,recording,seconds,start,stop,denied}}import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function AiPromptChips({prompts,onPick}){if(prompts.length===0)return null;return jsx2("div",{className:"flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:prompts.map(p=>jsx2("button",{type:"button",dir:"auto",onClick:()=>onPick(p),className:"shrink-0 h-8 px-3 rounded-full border border-border bg-surface text-caption font-bold text-ink2 whitespace-nowrap cursor-pointer transition-colors hover:border-brand hover:text-brand-ink",children:p},p))})}function LiveBars({level,count=28}){const bars=useRef3([]);const history=useRef3(Array.from({length:count},()=>0));useEffect3(()=>{let raf=0;let last=0;const loop=t=>{if(t-last>60){last=t;history.current=[...history.current.slice(1),level.current??0];for(let i=0;i<bars.current.length;i++){const el=bars.current[i];if(el)el.style.height=`${Math.max(10,(history.current[i]??0)*100)}%`}}raf=requestAnimationFrame(loop)};raf=requestAnimationFrame(loop);return()=>cancelAnimationFrame(raf)},[level]);return jsx2("span",{dir:"ltr","aria-hidden":"true",className:"flex-1 min-w-0 h-7 flex items-center gap-0.5",children:Array.from({length:count},(_,i)=>jsx2("span",{ref:el=>{bars.current[i]=el},className:"flex-1 rounded-full bg-brand",style:{height:"10%",transition:"height 70ms linear"}},i))})}function AiComposer({value,onChange,onSend,placeholder,busy,onStop,onVoice,onAttach,disabled,className}){const ui=useUIText();const mic=useMicLevel();const area=useRef3(null);useEffect3(()=>{const el=area.current;if(!el)return;el.style.height="auto";el.style.height=`${Math.min(el.scrollHeight,120)}px`},[value]);function submit(){const text=value.trim();if(!text||busy)return;onSend(text)}if(mic.recording){return jsxs2("div",{className:cn("flex items-center gap-3 h-14 px-3 rounded-lg bg-surface border border-brand",className),children:[jsx2("button",{type:"button",onClick:mic.stop,"aria-label":ui.cancelRecording,className:"size-9 rounded-sm shrink-0 flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-red-bg hover:text-red",children:jsx2(Trash2,{size:17,"aria-hidden":"true"})}),jsx2(LiveBars,{level:mic.level}),jsx2("span",{"data-num":true,className:"text-ui font-bold text-ink2 shrink-0 tabular-nums",children:formatTime(mic.seconds)}),jsx2("button",{type:"button",onClick:()=>{const s=mic.seconds;mic.stop();onVoice?.(s)},"aria-label":ui.sendRecording,className:"size-9 rounded-sm shrink-0 flex items-center justify-center bg-brand text-white cursor-pointer transition-colors hover:bg-brand-hover",children:jsx2(ArrowUp,{size:17,strokeWidth:2.4,"aria-hidden":"true"})})]})}const canSend=value.trim().length>0;return jsxs2("div",{className:cn("flex flex-col gap-1.5",className),children:[jsxs2("div",{className:cn("flex items-end gap-2 p-2 ps-3.5 rounded-lg bg-surface border border-border","focus-within:border-brand transition-colors",disabled&&"opacity-60 pointer-events-none"),children:[jsx2("label",{htmlFor:"ai-composer",className:"sr-only",children:placeholder??ui.askShehab}),jsx2("textarea",{id:"ai-composer",ref:area,rows:1,value,disabled,placeholder:placeholder??ui.askShehab,onChange:e=>onChange(e.target.value),onKeyDown:e=>{if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();submit()}},className:"flex-1 min-w-0 py-2 bg-transparent border-none outline-none resize-none text-body text-ink placeholder:text-muted2"}),jsxs2("span",{className:"flex items-center gap-0.5 shrink-0",children:[onAttach&&jsx2("button",{type:"button",onClick:onAttach,"aria-label":ui.attachFile,className:"size-9 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx2(Paperclip,{size:17,"aria-hidden":"true"})}),onVoice&&!canSend&&!busy&&jsx2("button",{type:"button",onClick:()=>void mic.start(),"aria-label":ui.recordVoice,className:"size-9 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx2(Mic,{size:17,"aria-hidden":"true"})}),jsx2("button",{type:"button",onClick:busy?onStop:submit,disabled:!busy&&!canSend,"aria-label":busy?"\u0623\u0648\u0642\u0641 \u0627\u0644\u062A\u0648\u0644\u064A\u062F":"\u0625\u0631\u0633\u0627\u0644",className:cn("size-9 rounded-sm flex items-center justify-center shrink-0 transition-colors",busy?"bg-ink2 text-surface cursor-pointer hover:bg-ink":canSend?"bg-brand text-white cursor-pointer hover:bg-brand-hover":"bg-soft text-brand-ink/40 cursor-not-allowed"),children:busy?jsx2(Square,{size:13,fill:"currentColor","aria-hidden":"true"}):jsx2(ArrowUp,{size:17,strokeWidth:2.4,"aria-hidden":"true"})})]})]}),mic.denied&&jsx2("span",{className:"text-caption text-red",children:"\u0627\u0644\u0645\u064A\u0643\u0631\u0648\u0641\u0648\u0646 \u0645\u0631\u0641\u0648\u0636 \u2014 \u0627\u0633\u0645\u062D \u0644\u0644\u0645\u0648\u0642\u0639 \u0628\u0627\u0644\u0648\u0635\u0648\u0644 \u0644\u0644\u0645\u064A\u0643\u0631\u0648\u0641\u0648\u0646 \u0645\u0646 \u0625\u0639\u062F\u0627\u062F\u0627\u062A \u0627\u0644\u0645\u062A\u0635\u0641\u0651\u062D."})]})}import{useState as useState5}from"react";import{useState as useState3}from"react";import{ArrowRight,Check as Check2,MessageSquarePlus}from"lucide-react";import{OTHER_PREFIX}from"@qumra/jawab-ai";import{jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";function AskCard({block,onAnswer,live=true}){const[at,setAt]=useState3(0);const[picked,setPicked]=useState3({});const[other,setOther]=useState3({});const[notes,setNotes]=useState3({});const[noting,setNoting]=useState3({});const[sent,setSent]=useState3(null);const answerable=live&&Boolean(onAnswer)&&!sent;const total=block.questions.length;const q=block.questions[at];const last=at===total-1;function toggle(question,value){setPicked(prev=>{const cur=prev[question.key]??[];if(!question.multi)return{...prev,[question.key]:[value]};return{...prev,[question.key]:cur.includes(value)?cur.filter(v=>v!==value):[...cur,value]}})}function valuesFor(question){const base=picked[question.key]??[];const typed=other[question.key]?.trim();return typed?[...base,OTHER_PREFIX+typed]:base}function labelsFor(question){return valuesFor(question).map(v=>v.startsWith(OTHER_PREFIX)?v.slice(OTHER_PREFIX.length):question.options.find(o=>o.value===v)?.label??v)}const answered=valuesFor(q).length>0;const canGo=q.required===false||answered;function submit(){const result={answers:{},values:{}};const notesOut={};for(const question of block.questions){const values=valuesFor(question);if(values.length===0)continue;result.values[question.key]=values;result.answers[question.label]=labelsFor(question).join("\u060C ");const note=notes[question.key]?.trim();if(note)notesOut[question.label]={notes:note}}if(Object.keys(notesOut).length)result.annotations=notesOut;setSent(result);onAnswer?.(block.id,result)}if(sent){return jsxs3("div",{className:"flex flex-col gap-3 p-4 rounded-card border border-line bg-bg",children:[block.questions.map(question=>jsxs3("div",{className:"flex flex-col gap-1.5",children:[jsx3("span",{className:"text-caption text-muted [text-wrap:pretty]",children:question.label}),jsx3(Picked,{labels:(sent.answers[question.label]??"").split("\u060C ").filter(Boolean),note:sent.annotations?.[question.label]?.notes})]},question.key)),jsxs3("span",{className:"flex items-center gap-1.5 text-caption font-bold text-green",children:[jsx3(Check2,{size:13,strokeWidth:2.6,"aria-hidden":"true"}),"\u0627\u062A\u0628\u0639\u062A"]})]})}return jsxs3("div",{className:"flex flex-col gap-3.5 p-4 rounded-card border border-soft2 bg-tint",children:[jsxs3("span",{className:"flex items-center justify-between gap-3",children:[q.header?jsx3("span",{className:"px-2 h-5 rounded-mark bg-soft text-brand-ink text-micro font-extrabold flex items-center",children:q.header}):jsx3("span",{}),total>1&&jsxs3("span",{className:"flex items-center gap-2 shrink-0",children:[jsx3("span",{"aria-hidden":"true",className:"flex items-center gap-1",children:block.questions.map((qq,i)=>jsx3("span",{className:cn("size-1.5 rounded-full transition-colors",i===at?"bg-brand":i<at?"bg-brand/40":"bg-border/40")},qq.key))}),jsxs3("span",{"data-num":true,className:"text-micro font-bold text-muted whitespace-nowrap",children:[at+1," \u0645\u0646 ",total]})]})]}),jsxs3("div",{className:"flex flex-col gap-2",children:[jsx3("span",{className:"text-ui font-extrabold text-ink [text-wrap:pretty]",children:q.label}),q.hint&&jsx3("span",{className:"text-caption leading-[1.7] text-muted",children:q.hint}),jsx3(ChoiceCards,{name:`${block.id}-${q.key}`,multiple:q.multi,disabled:!answerable,value:q.multi?picked[q.key]??[]:picked[q.key]?.[0]??null,onChange:v=>toggle(q,v),options:q.options.map(o=>({value:o.value,label:o.label,meta:o.description}))}),q.other!==false&&jsx3(Input,{size:"sm",value:other[q.key]??"",onChange:e=>setOther(p=>({...p,[q.key]:e.target.value})),disabled:!answerable,placeholder:q.other?.placeholder??"\u0623\u0648 \u0627\u0643\u062A\u0628 \u0625\u062C\u0627\u0628\u062A\u0643\u2026","aria-label":`\u0625\u062C\u0627\u0628\u0629 \u0623\u062E\u0631\u0649 \u0639\u0644\u0649: ${q.label}`}),noting[q.key]?jsx3(Textarea,{rows:2,value:notes[q.key]??"",onChange:e=>setNotes(p=>({...p,[q.key]:e.target.value})),disabled:!answerable,placeholder:"\u062D\u0627\u062C\u0629 \u062A\u062D\u0628\u0651 \u062A\u0642\u0648\u0644\u0647\u0627 \u0645\u0639 \u0627\u062E\u062A\u064A\u0627\u0631\u0643\u2026","aria-label":`\u0645\u0644\u0627\u062D\u0638\u0629 \u0639\u0644\u0649: ${q.label}`}):answerable&&jsxs3("button",{type:"button",onClick:()=>setNoting(p=>({...p,[q.key]:true})),className:"self-start inline-flex items-center gap-1.5 text-micro font-bold text-muted hover:text-brand cursor-pointer transition-colors",children:[jsx3(MessageSquarePlus,{size:13,"aria-hidden":"true"}),"\u0636\u064A\u0641 \u0645\u0644\u0627\u062D\u0638\u0629"]})]}),answerable&&jsxs3("span",{className:"flex items-center gap-2.5",children:[at>0&&jsx3(Button,{size:"sm",variant:"ghost",onClick:()=>setAt(i=>i-1),children:"\u0631\u062C\u0648\u0639"}),last?jsx3(Button,{size:"sm",onClick:submit,disabled:!canGo,children:block.submitLabel??"\u0627\u0628\u0639\u062A"}):jsx3(Button,{size:"sm",onClick:()=>setAt(i=>i+1),disabled:!canGo,iconEnd:jsx3(ArrowRight,{size:13,className:"rtl:rotate-180","aria-hidden":"true"}),children:"\u0627\u0644\u062A\u0627\u0644\u064A"}),!canGo&&jsx3("span",{className:"text-micro text-muted2",children:"\u0627\u062E\u062A\u0627\u0631 \u0625\u062C\u0627\u0628\u0629 \u0627\u0644\u0623\u0648\u0644"})]})]})}function Picked({labels,note}){if(labels.length===0)return jsx3("span",{className:"text-caption text-muted2",children:"\u0627\u062A\u062E\u0637\u0651\u0649"});return jsxs3("span",{className:"flex flex-col gap-1.5",children:[jsx3("span",{className:"flex flex-wrap gap-1.5",children:labels.map((l,i)=>jsxs3("span",{className:"inline-flex items-center gap-1 h-6 px-2 rounded-mark bg-soft text-brand-ink text-caption font-bold",children:[jsx3(Check2,{size:11,strokeWidth:3,"aria-hidden":"true"}),l]},i))}),note&&jsx3("span",{className:"text-micro leading-[1.7] text-muted border-s-2 border-line ps-2",children:note})]})}import{useEffect as useEffect4,useState as useState4}from"react";import{Check as Check3,Copy as Copy2,RotateCcw as RotateCcw2,Sparkles,X}from"lucide-react";import{Fragment as Fragment2,jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";function DraftPanel({draft:source,basis,label,onInsert,onClose,insertLabel="\u0623\u062F\u0631\u0650\u062C",className}){const[attempt,setAttempt]=useState4(0);const[done,setDone]=useState4(false);const{text,streaming,start,finish}=useStreamingText({speed:12});const dynamic=typeof source==="function";useEffect4(()=>{start(dynamic?source(attempt):source)},[attempt,source]);return jsxs4("div",{className:cn("flex flex-col gap-2.5 p-3.5 rounded-card bg-bg border border-line","basis-full order-last w-full",className),children:[jsxs4("span",{className:"flex items-start justify-between gap-3",children:[jsxs4("span",{className:"flex flex-col gap-0.5 min-w-0",children:[jsxs4("span",{className:"flex items-center gap-1.5 text-caption font-extrabold text-ink",children:[jsx4(Sparkles,{size:13,className:"text-brand shrink-0","aria-hidden":"true"}),label]}),jsx4("span",{className:"text-micro leading-[1.65] text-muted",children:basis})]}),onClose&&jsx4("button",{type:"button",onClick:onClose,"aria-label":"\u0625\u063A\u0644\u0627\u0642",className:"shrink-0 size-6 rounded-mark flex items-center justify-center text-muted2 hover:bg-hover hover:text-ink cursor-pointer transition-colors",children:jsx4(X,{size:14,"aria-hidden":"true"})})]}),text===""&&streaming?jsx4(AiThinking,{label:"\u0628\u064A\u0643\u062A\u0628\u2026"}):jsxs4("span",{className:"block text-caption leading-[1.9] text-ink whitespace-pre-wrap [text-wrap:pretty]","aria-live":"polite",children:[text,streaming&&jsx4("span",{"aria-hidden":"true",className:"inline-block w-[2px] h-[1em] align-[-0.15em] ms-0.5 bg-brand animate-pulse"})]}),jsx4("span",{className:"flex items-center gap-2 flex-wrap",children:streaming?jsx4(Button,{size:"sm",variant:"outline",onClick:finish,children:"\u0627\u0639\u0631\u0636\u0647\u0627 \u0643\u0644\u0647\u0627"}):jsxs4(Fragment2,{children:[onInsert&&jsx4(Button,{size:"sm",onClick:()=>{onInsert(text);setDone(true);onClose?.()},icon:jsx4(Check3,{size:13,"aria-hidden":"true"}),children:insertLabel}),jsx4(Button,{size:"sm",variant:"outline",onClick:()=>navigator.clipboard?.writeText(text),icon:jsx4(Copy2,{size:13,"aria-hidden":"true"}),children:"\u0627\u0646\u0633\u062E"}),dynamic&&jsx4(Button,{size:"sm",variant:"ghost",onClick:()=>setAttempt(a=>a+1),icon:jsx4(RotateCcw2,{size:13,"aria-hidden":"true"}),children:"\u0627\u0643\u062A\u0628 \u063A\u064A\u0631\u0647\u0627"})]})}),!streaming&&!done&&jsx4(AiDisclaimer,{children:"\u0645\u0645\u0643\u0646 \u064A\u063A\u0644\u0637 \u2014 \u0627\u0642\u0631\u0627\u0647\u0627 \u0642\u0628\u0644 \u0645\u0627 \u062A\u0646\u0634\u0631\u0647\u0627."})]})}function AiDraft({size="sm",...panel}){const[open,setOpen]=useState4(false);if(!open){return jsx4(Button,{variant:"outline",size,onClick:()=>setOpen(true),icon:jsx4(Sparkles,{size:size==="sm"?13:15,"aria-hidden":"true"}),className:panel.className,children:panel.label})}return jsx4(DraftPanel,{...panel,onClose:()=>setOpen(false)})}import{Fragment as Fragment3,jsx as jsx5}from"react/jsx-runtime";function Markdown({md}){const chunks=md.split(/\n{2,}/);return jsx5(Fragment3,{children:chunks.map((chunk,i)=>{const lines=chunk.split("\n");const bullets=lines.every(l=>/^\s*[-•]\s+/.test(l));const numbers=lines.every(l=>/^\s*\d+[.)]\s+/.test(l));if(bullets||numbers){const items=lines.map(l=>l.replace(/^\s*(?:[-•]|\d+[.)])\s+/,""));const List=numbers?"ol":"ul";return jsx5(List,{className:numbers?"my-2 ps-5 list-decimal marker:text-muted2 flex flex-col gap-1":"my-2 ps-5 list-disc marker:text-muted2 flex flex-col gap-1",children:items.map((it,j)=>jsx5("li",{children:inline(it)},j))},i)}return jsx5("p",{className:"my-2 first:mt-0 last:mb-0 [text-wrap:pretty]",children:inline(chunk)},i)})})}var TOKEN=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\n]+\*)/g;function inline(src){const out=[];let last=0;let m;TOKEN.lastIndex=0;while((m=TOKEN.exec(src))!==null){if(m.index>last)out.push(src.slice(last,m.index));const[full]=m;const key=`${m.index}`;if(full.startsWith("`")){out.push(jsx5("code",{dir:"ltr",className:"px-1 py-px rounded-mark bg-hover text-[0.9em] font-mono text-brand-ink",children:full.slice(1,-1)},key))}else if(full.startsWith("**")){out.push(jsx5("strong",{className:"font-extrabold text-ink",children:full.slice(2,-2)},key))}else{out.push(jsx5("em",{className:"not-italic font-bold",children:full.slice(1,-1)},key))}last=m.index+full.length}if(last<src.length)out.push(src.slice(last));return out}import{Fragment as Fragment4,jsx as jsx6,jsxs as jsxs5}from"react/jsx-runtime";var TONE={good:"green",warn:"amber",bad:"red",plain:"neutral"};var NOTICE_TONE={info:"brand",warn:"amber",danger:"red"};function major(a){return a.minor/10**(a.decimals??2)}function TextBlockView({block}){if(!block.md)return null;return jsx6("div",{className:"text-body leading-[1.95] text-ink2",children:jsx6(Markdown,{md:block.md})})}function MetricBlockView({block}){return jsx6("div",{className:"grid gap-2.5 grid-cols-[repeat(auto-fit,minmax(9.5rem,1fr))]",children:block.items.map((m,i)=>jsx6(StatCard,{tone:TONE[m.tone??"plain"]??"neutral",label:m.label,value:m.amount?jsx6(Money,{value:major(m.amount),currency:isCurrency(m.amount.currency)?m.amount.currency:void 0,compact:true,trimZeros:true}):m.value,hint:m.delta!==void 0?deltaHint(m.delta,m.deltaBasis):void 0},i))})}function deltaHint(delta,basis){const up=delta>0;const flat=delta===0;return jsxs5("span",{className:cn("font-bold",flat?"text-muted2":up?"text-green":"text-red"),children:[flat?"=":up?"\u25B2":"\u25BC"," ",Math.abs(delta),"\u066A",basis?` ${basis}`:""]})}function TableBlockView({block}){const rows=block.rows.map((cells,i)=>{const row={__key:String(i)};block.cols.forEach((c,j)=>{row[c.key]=cells[j]??null});return row});const columns=block.cols.map(c=>({key:c.key,header:c.label,end:c.align==="end",cell:row=>renderCell(row[c.key],c)}));return jsxs5("span",{className:"flex flex-col gap-1.5",children:[block.caption&&jsx6("span",{className:"text-micro text-muted2",children:block.caption}),jsx6(DataTable,{columns,rows,rowKey:r=>r.__key,grid:block.cols.map(c=>c.align==="end"?"1fr":"1.6fr").join("_"),minWidth:block.cols.length*120,mobileCard:row=>jsx6("span",{className:"flex flex-col gap-1",children:block.cols.map(c=>jsxs5("span",{className:"flex items-baseline justify-between gap-3",children:[jsx6("span",{className:"text-micro text-muted2",children:c.label}),jsx6("span",{className:"text-caption text-ink",children:renderCell(row[c.key],c)})]},c.key))})})]})}function renderCell(v,col){if(v===null||v==="")return jsx6("span",{className:"text-muted2",children:"\u2014"});switch(col.format){case"money":return typeof v==="number"?jsx6(Money,{value:v,trimZeros:true}):v;case"badge":return jsx6(Badge,{size:"sm",children:v});case"number":return jsx6("span",{"data-num":true,children:v});default:return v}}function CardsBlockView({block,intents}){return jsx6("div",{className:"grid gap-2.5 grid-cols-[repeat(auto-fill,minmax(13rem,1fr))]",children:block.items.map(c=>jsx6(Card,{children:jsxs5("span",{className:"flex gap-3 items-start",children:[c.img&&jsx6("img",{src:c.img,alt:"",className:"size-12 rounded-sm object-cover bg-hover shrink-0"}),jsxs5("span",{className:"flex flex-col gap-1 min-w-0",children:[jsx6("span",{className:"text-ui font-bold text-ink truncate",children:c.title}),c.subtitle&&jsx6("span",{className:"text-micro text-muted",children:c.subtitle}),c.badge&&jsx6("span",{children:jsx6(Badge,{size:"sm",tone:"brand",children:c.badge})}),c.action&&jsx6(ActionButton,{action:c.action,intents,size:"sm"})]})]})},c.id))})}function ChartBlockView({block}){const labels=block.series.map(p=>String(p.x));const values=block.series.map(p=>p.y);const money=block.unit?.kind==="money";const fmt=v=>block.unit?.kind==="percent"?`${v}\u066A`:v.toLocaleString("ar-EG");if(block.kind==="bar"){return jsx6(BarChart,{labels,series:[{label:"",values}],formatValue:fmt})}return jsx6(TrendChart,{labels:axisLabels(labels),values,pointLabels:labels,formatValue:money?v=>v.toLocaleString("ar-EG"):fmt,height:170})}function axisLabels(all){if(all.length<=3)return all;return[all[0],all[Math.floor(all.length/2)],all[all.length-1]]}function ActionBlockView({block,intents}){const runnable=block.items.filter(a=>intents[a.intent]);if(runnable.length===0)return null;return jsx6("span",{className:"flex flex-wrap gap-2",children:runnable.map((a,i)=>jsx6(ActionButton,{action:a,intents},i))})}function ActionButton({action,intents,size="sm"}){const[asking,setAsking]=useState5(false);const run=intents[action.intent];if(!run)return null;function fire(){setAsking(false);run(action.args)}return jsxs5(Fragment4,{children:[jsx6(Button,{size,variant:action.style==="quiet"?"outline":"primary",onClick:()=>action.confirm?setAsking(true):fire(),children:action.label}),jsx6(Modal,{open:asking,title:action.label,description:action.confirm,onClose:()=>setAsking(false),size:"sm",footer:jsxs5(Fragment4,{children:[jsx6(Button,{variant:"outline",onClick:()=>setAsking(false),children:"\u0625\u0644\u063A\u0627\u0621"}),jsx6(Button,{onClick:fire,children:action.label})]})})]})}function ToolBlockView({block,intents}){const undo=block.undo;const run=undo?intents[undo.intent]:void 0;return jsx6(AiToolCall,{title:block.title,detail:block.detail,state:block.state,onUndo:run&&undo?()=>run(undo.args):void 0,undoLabel:undo?.label})}function NoticeBlockView({block}){return jsx6(Alert,{tone:NOTICE_TONE[block.tone],children:block.text})}function ChipsBlockView({block,onSend}){if(!onSend)return null;const byLabel=new Map(block.items.map(c=>[c.label,c.send]));return jsx6(AiPromptChips,{prompts:block.items.map(c=>c.label),onPick:label=>onSend(byLabel.get(label)??label)})}function BlockView({block,intents,onSend,onInsertDraft,onAnswer,live=true}){switch(block.type){case"text":return jsx6(TextBlockView,{block});case"metric":return jsx6(MetricBlockView,{block});case"table":return jsx6(TableBlockView,{block});case"cards":return jsx6(CardsBlockView,{block,intents});case"chart":return jsx6(ChartBlockView,{block});case"action":return jsx6(ActionBlockView,{block,intents});case"tool":return jsx6(ToolBlockView,{block,intents});case"notice":return jsx6(NoticeBlockView,{block});case"chips":return jsx6(ChipsBlockView,{block,onSend});case"ask":return jsx6(AskCard,{block,onAnswer,live});case"draft":return jsx6(DraftPanel,{draft:block.text,basis:block.basis,label:"\u0645\u0633\u0648\u0651\u062F\u0629",onInsert:onInsertDraft});default:return null}}import{jsx as jsx7,jsxs as jsxs6}from"react/jsx-runtime";var NO_INTENTS={};function ReplyView({reply,streaming,intents=NO_INTENTS,onSend,onInsertDraft,onAnswer,live=true,onRetry,onFeedback,className}){return jsx7(AiMessage,{role:"assistant",fill:true,streaming,sources:reply.sources,copyText:plainText(reply),onRetry,onFeedback,children:jsxs6("span",{className:cn("flex flex-col gap-3",className),children:[reply.blocks.map((block,i)=>jsx7(BlockView,{block,intents,onSend,onInsertDraft,onAnswer,live},i)),reply.disclaimer!==false&&!streaming&&jsx7(AiDisclaimer,{})]})})}function plainText(reply){const parts=[];for(const b of reply.blocks){switch(b.type){case"text":parts.push(b.md);break;case"metric":parts.push(b.items.map(m=>`${m.label}: ${m.value}`).join(" \xB7 "));break;case"table":parts.push([b.cols.map(c=>c.label).join(" "),...b.rows.map(r=>r.map(c=>c??"").join(" "))].join("\n"));break;case"cards":parts.push(b.items.map(c=>c.title).join("\n"));break;case"draft":parts.push(b.text);break;case"tool":parts.push(b.detail?`${b.title} \u2014 ${b.detail}`:b.title);break;case"notice":parts.push(b.text);break;case"ask":parts.push(b.questions.map(q=>q.label).join("\n"));break;case"chart":case"action":case"chips":break}}return parts.filter(Boolean).join("\n\n")}import{useCallback as useCallback2,useEffect as useEffect5,useRef as useRef4,useState as useState6}from"react";import{parseEvent,parseSSE,reduce}from"@qumra/jawab-ai";function useReplyStream(url,init){const[reply,setReply]=useState6(null);const[streaming,setStreaming]=useState6(false);const[error,setError]=useState6(null);const abort=useRef4(null);const lastInput=useRef4("");useEffect5(()=>()=>abort.current?.abort(),[]);const stop=useCallback2(()=>{abort.current?.abort();abort.current=null;setStreaming(false)},[]);const send=useCallback2(text=>{const question=text.trim();if(!question)return;abort.current?.abort();const ctrl=new AbortController;abort.current=ctrl;lastInput.current=question;setError(null);setReply(null);setStreaming(true);void(async()=>{try{const res=await fetch(url,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},body:JSON.stringify({input:question}),signal:ctrl.signal,...init});if(!res.ok||!res.body){throw new StreamError("http_"+res.status,`\u0627\u0644\u062E\u0627\u062F\u0645 \u0631\u062C\u0651\u0639 ${res.status}`)}const decoder=new TextDecoder;const readerStream=res.body.getReader();let rest="";let state=null;for(;;){const{done,value}=await readerStream.read();if(done)break;rest+=decoder.decode(value,{stream:true});const{events,rest:tail}=parseSSE(rest);rest=tail;for(const raw of events){const ev=parseEvent(raw);if(!ev)continue;if(ev.e==="error")throw new StreamError(ev.code,ev.message);state=reduce(state,ev);setReply(state);if(ev.e==="done")break}}setStreaming(false)}catch(e){if(ctrl.signal.aborted)return;const se=e;setError({code:se.code??"unknown",message:se.message??"\u0627\u0644\u0627\u062A\u0635\u0627\u0644 \u0627\u062A\u0642\u0637\u0639.",lastInput:lastInput.current});setStreaming(false)}})()},[url,init]);return{reply,streaming,error,send,stop}}var StreamError=class extends Error{code;constructor(code,message){super(message);this.name="StreamError";this.code=code}};export{AiAvatar,AiComposer,AiDisclaimer,AiDraft,AiMessage,AiPromptChips,AiSources,AiThinking,AiToolCall,AskCard,DraftPanel,ReplyView,useMicLevel,useReplyStream,useStreamingText};
2
+ import{BarChart,ChoiceCards,DataTable,Money,TrendChart,isCurrency}from"./chunk-CTMW25W5.js";import{Button,Input,Textarea}from"./chunk-K3TNXSD7.js";import{Badge,Card,StatCard,formatTime}from"./chunk-NIEWNSOB.js";import{Alert,Modal,cn,useUIText}from"./chunk-6DTSIOCB.js";import{useEffect,useRef,useState}from"react";import{Bot,Check,Copy,ExternalLink,RotateCcw,ThumbsDown,ThumbsUp,TriangleAlert}from"lucide-react";import{Fragment,jsx,jsxs}from"react/jsx-runtime";function AiAvatar({state="idle",level,size="md",icon:Icon=Bot}){const ring=useRef(null);useEffect(()=>{if(state!=="speaking"||!level)return;let raf=0;const loop=()=>{const v=level.current??0;if(ring.current){ring.current.style.transform=`scale(${1+v**1.6*.9})`;ring.current.style.opacity=String(Math.min(.45,v))}raf=requestAnimationFrame(loop)};raf=requestAnimationFrame(loop);const el=ring.current;return()=>{cancelAnimationFrame(raf);if(el)el.style.opacity="0"}},[state,level]);const box={sm:"size-8",md:"size-9",lg:"size-12"}[size];const px={sm:16,md:18,lg:24}[size];return jsxs("span",{className:"relative inline-flex shrink-0",children:[jsx("span",{ref:ring,"aria-hidden":"true",className:cn("absolute inset-0 rounded-sm bg-brand opacity-0",box),style:{transition:"transform 90ms linear, opacity 90ms linear"}}),jsx("span",{"aria-hidden":"true",className:cn("relative rounded-sm bg-soft border border-soft2 flex items-center justify-center",box,state==="thinking"&&"animate-pulse"),children:jsx(Icon,{size:px,strokeWidth:2,className:"text-brand"})})]})}function AiThinking({label}){const ui=useUIText();return jsxs("span",{role:"status","aria-live":"polite",className:"flex items-center gap-2.5",children:[jsx(AiAvatar,{size:"sm",state:"thinking"}),jsxs("span",{className:"flex items-center gap-2 py-2.5 px-3.5 rounded-card bg-bg border border-line",children:[jsx("span",{"aria-hidden":"true",className:"flex items-center gap-1",children:[0,1,2].map(i=>jsx("span",{className:"size-1.5 rounded-full bg-muted2 animate-bounce",style:{animationDelay:`${i*140}ms`,animationDuration:"900ms"}},i))}),jsx("span",{className:"text-caption text-muted",children:label??ui.shehabThinking})]})]})}function AiToolCall({icon:Icon,title,detail,state="done",onUndo,undoLabel}){const ui=useUIText();const tone={running:"bg-bg border-line text-muted",done:"bg-green-bg2 border-green-line text-green",failed:"bg-red-bg border-red-line text-red",reverted:"bg-bg border-line text-muted2"}[state];const off=state==="reverted";return jsxs("div",{className:cn("flex items-start gap-2.5 p-3 rounded-card border",tone),children:[jsx("span",{"aria-hidden":"true",className:"shrink-0 mt-0.5",children:state==="failed"?jsx(TriangleAlert,{size:15}):off?jsx(RotateCcw,{size:15}):state==="done"?jsx(Check,{size:15}):Icon?jsx(Icon,{size:15}):jsx("span",{className:"block size-3.5 rounded-full border-2 border-current border-t-transparent animate-spin"})}),jsxs("span",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[jsx("span",{className:cn("text-ui font-bold",off?"text-muted":"text-ink"),children:title}),detail&&jsx("span",{className:cn("text-caption leading-[1.7]",off?"text-muted2 line-through":"text-ink2"),children:detail})]}),onUndo&&state==="done"&&jsx("button",{type:"button",onClick:onUndo,className:"shrink-0 text-caption font-bold text-brand-ink cursor-pointer hover:underline underline-offset-4",children:undoLabel??ui.undo})]})}function AiSources({sources,label}){const ui=useUIText();if(sources.length===0)return null;return jsxs("span",{className:"flex items-center gap-1.5 flex-wrap",children:[jsx("span",{className:"text-micro text-muted2",children:label??ui.from}),sources.map(s=>{const inner=jsxs(Fragment,{children:[s.label,jsx(ExternalLink,{size:10,"aria-hidden":"true"})]});const cls="inline-flex items-center gap-1 h-6 px-2 rounded-full bg-soft text-brand-ink text-micro font-bold no-underline cursor-pointer transition-colors hover:bg-soft2";return s.href?jsx("a",{href:s.href,className:cls,children:inner},s.id):jsx("button",{type:"button",onClick:s.onOpen,className:cls,children:inner},s.id)})]})}function AiMessage({role,children,streaming,sources,copyText,onRetry,onFeedback,tools,fill}){const ui=useUIText();const[copied,setCopied]=useState(false);const[vote,setVote]=useState(null);const user=role==="user";const actionable=!user&&!streaming&&(copyText||onRetry||onFeedback);return jsxs("div",{className:cn("flex gap-2.5",fill?"w-full":"max-w-[88%]",user?"self-end":"self-start"),children:[!user&&jsx(AiAvatar,{size:"sm"}),jsxs("div",{className:cn("flex flex-col gap-2 min-w-0",fill&&"flex-1"),children:[jsxs("div",{dir:"auto",className:cn("py-2.5 px-3.5 rounded-card text-ui leading-[1.85] whitespace-pre-line",user?"bg-brand text-white":"bg-bg text-ink border border-line"),children:[children,streaming&&jsx("span",{"aria-hidden":"true",className:"inline-block w-[2px] h-[1em] align-[-2px] ms-0.5 bg-brand animate-pulse"})]}),tools,sources&&sources.length>0&&!streaming&&jsx(AiSources,{sources}),actionable&&jsxs("div",{className:"flex items-center gap-0.5",children:[copyText&&jsx(ActionBtn,{label:copied?"\u0627\u062A\u0646\u0633\u062E":"\u0646\u0633\u062E",onClick:()=>{navigator.clipboard?.writeText(copyText);setCopied(true);setTimeout(()=>setCopied(false),1400)},children:copied?jsx(Check,{size:13,className:"text-green"}):jsx(Copy,{size:13})}),onRetry&&jsx(ActionBtn,{label:ui.tryAnotherReply,onClick:onRetry,children:jsx(RotateCcw,{size:13})}),onFeedback&&jsxs(Fragment,{children:[jsx(ActionBtn,{label:ui.helpfulReply,active:vote==="up",onClick:()=>{setVote("up");onFeedback("up")},children:jsx(ThumbsUp,{size:13})}),jsx(ActionBtn,{label:ui.unhelpfulReply,active:vote==="down",onClick:()=>{setVote("down");onFeedback("down")},children:jsx(ThumbsDown,{size:13})})]})]})]})]})}function ActionBtn({onClick,label,active,children}){return jsx("button",{type:"button",onClick,"aria-label":label,title:label,"aria-pressed":active,className:cn("size-7 rounded-xs inline-flex items-center justify-center cursor-pointer transition-colors",active?"bg-soft text-brand-ink":"text-muted2 hover:bg-hover hover:text-ink"),children})}function AiDisclaimer({children}){const ui=useUIText();return jsx("span",{className:"block text-center text-micro leading-[1.7] text-muted2 [text-wrap:pretty]",children:children??ui.aiDisclaimer})}import{useEffect as useEffect3,useRef as useRef3}from"react";import{ArrowUp,Mic,Paperclip,Square,Trash2}from"lucide-react";import{useCallback,useEffect as useEffect2,useRef as useRef2,useState as useState2}from"react";function useStreamingText({speed=18}={}){const[shown,setShown]=useState2("");const[streaming,setStreaming]=useState2(false);const full=useRef2("");const timer=useRef2(void 0);const stopTimer=useCallback(()=>{clearInterval(timer.current);timer.current=void 0},[]);useEffect2(()=>stopTimer,[stopTimer]);const run=useCallback(()=>{if(timer.current)return;timer.current=setInterval(()=>{setShown(s=>{if(s.length>=full.current.length){stopTimer();setStreaming(false);return s}return full.current.slice(0,s.length+1)})},speed)},[speed,stopTimer]);const start=useCallback(text=>{stopTimer();full.current=text;setShown("");setStreaming(true);run()},[run,stopTimer]);const push=useCallback(chunk=>{full.current+=chunk;setStreaming(true);run()},[run]);const stop=useCallback(()=>{stopTimer();full.current=shown;setStreaming(false)},[shown,stopTimer]);const finish=useCallback(()=>{stopTimer();setShown(full.current);setStreaming(false)},[stopTimer]);const reset=useCallback(()=>{stopTimer();full.current="";setShown("");setStreaming(false)},[stopTimer]);return{text:shown,streaming,start,push,stop,finish,reset}}function useMicLevel(){const level=useRef2(0);const[recording,setRecording]=useState2(false);const[seconds,setSeconds]=useState2(0);const[denied,setDenied]=useState2(false);const stream=useRef2(null);const ctx=useRef2(null);const raf=useRef2(0);const tick=useRef2(void 0);const stop=useCallback(()=>{cancelAnimationFrame(raf.current);clearInterval(tick.current);stream.current?.getTracks().forEach(t=>t.stop());void ctx.current?.close();stream.current=null;ctx.current=null;level.current=0;setRecording(false);setSeconds(0)},[]);useEffect2(()=>stop,[stop]);const start=useCallback(async()=>{if(recording)return;try{const media=await navigator.mediaDevices.getUserMedia({audio:true});const Ctx=window.AudioContext??window.webkitAudioContext;if(!Ctx)throw new Error("\u0645\u0627\u0641\u064A\u0634 Web Audio");const c=new Ctx;const src=c.createMediaStreamSource(media);const analyser=c.createAnalyser();analyser.fftSize=512;analyser.smoothingTimeConstant=.7;src.connect(analyser);stream.current=media;ctx.current=c;setDenied(false);setRecording(true);setSeconds(0);const data=new Uint8Array(analyser.frequencyBinCount);const loop=()=>{analyser.getByteTimeDomainData(data);let sum=0;for(let i=0;i<data.length;i++){const v=(data[i]-128)/128;sum+=v*v}level.current=Math.min(1,Math.sqrt(sum/data.length)*3);raf.current=requestAnimationFrame(loop)};raf.current=requestAnimationFrame(loop);tick.current=setInterval(()=>setSeconds(s=>s+1),1e3)}catch{setDenied(true);setRecording(false)}},[recording]);return{level,recording,seconds,start,stop,denied}}import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function AiPromptChips({prompts,onPick}){if(prompts.length===0)return null;return jsx2("div",{className:"flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:prompts.map(p=>jsx2("button",{type:"button",dir:"auto",onClick:()=>onPick(p),className:"shrink-0 h-8 px-3 rounded-full border border-border bg-surface text-caption font-bold text-ink2 whitespace-nowrap cursor-pointer transition-colors hover:border-brand hover:text-brand-ink",children:p},p))})}function LiveBars({level,count=28}){const bars=useRef3([]);const history=useRef3(Array.from({length:count},()=>0));useEffect3(()=>{let raf=0;let last=0;const loop=t=>{if(t-last>60){last=t;history.current=[...history.current.slice(1),level.current??0];for(let i=0;i<bars.current.length;i++){const el=bars.current[i];if(el)el.style.height=`${Math.max(10,(history.current[i]??0)*100)}%`}}raf=requestAnimationFrame(loop)};raf=requestAnimationFrame(loop);return()=>cancelAnimationFrame(raf)},[level]);return jsx2("span",{dir:"ltr","aria-hidden":"true",className:"flex-1 min-w-0 h-7 flex items-center gap-0.5",children:Array.from({length:count},(_,i)=>jsx2("span",{ref:el=>{bars.current[i]=el},className:"flex-1 rounded-full bg-brand",style:{height:"10%",transition:"height 70ms linear"}},i))})}function AiComposer({value,onChange,onSend,placeholder,busy,onStop,onVoice,onAttach,disabled,className}){const ui=useUIText();const mic=useMicLevel();const area=useRef3(null);useEffect3(()=>{const el=area.current;if(!el)return;el.style.height="auto";el.style.height=`${Math.min(el.scrollHeight,120)}px`},[value]);function submit(){const text=value.trim();if(!text||busy)return;onSend(text)}if(mic.recording){return jsxs2("div",{className:cn("flex items-center gap-3 h-14 px-3 rounded-lg bg-surface border border-brand",className),children:[jsx2("button",{type:"button",onClick:mic.stop,"aria-label":ui.cancelRecording,className:"size-9 rounded-sm shrink-0 flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-red-bg hover:text-red",children:jsx2(Trash2,{size:17,"aria-hidden":"true"})}),jsx2(LiveBars,{level:mic.level}),jsx2("span",{"data-num":true,className:"text-ui font-bold text-ink2 shrink-0 tabular-nums",children:formatTime(mic.seconds)}),jsx2("button",{type:"button",onClick:()=>{const s=mic.seconds;mic.stop();onVoice?.(s)},"aria-label":ui.sendRecording,className:"size-9 rounded-sm shrink-0 flex items-center justify-center bg-brand text-white cursor-pointer transition-colors hover:bg-brand-hover",children:jsx2(ArrowUp,{size:17,strokeWidth:2.4,"aria-hidden":"true"})})]})}const canSend=value.trim().length>0;return jsxs2("div",{className:cn("flex flex-col gap-1.5",className),children:[jsxs2("div",{className:cn("flex items-end gap-2 p-2 ps-3.5 rounded-lg bg-surface border border-border","focus-within:border-brand transition-colors",disabled&&"opacity-60 pointer-events-none"),children:[jsx2("label",{htmlFor:"ai-composer",className:"sr-only",children:placeholder??ui.askShehab}),jsx2("textarea",{id:"ai-composer",ref:area,rows:1,value,disabled,placeholder:placeholder??ui.askShehab,onChange:e=>onChange(e.target.value),onKeyDown:e=>{if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();submit()}},className:"flex-1 min-w-0 py-2 bg-transparent border-none outline-none resize-none text-body text-ink placeholder:text-muted2"}),jsxs2("span",{className:"flex items-center gap-0.5 shrink-0",children:[onAttach&&jsx2("button",{type:"button",onClick:onAttach,"aria-label":ui.attachFile,className:"size-9 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx2(Paperclip,{size:17,"aria-hidden":"true"})}),onVoice&&!canSend&&!busy&&jsx2("button",{type:"button",onClick:()=>void mic.start(),"aria-label":ui.recordVoice,className:"size-9 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx2(Mic,{size:17,"aria-hidden":"true"})}),jsx2("button",{type:"button",onClick:busy?onStop:submit,disabled:!busy&&!canSend,"aria-label":busy?"\u0623\u0648\u0642\u0641 \u0627\u0644\u062A\u0648\u0644\u064A\u062F":"\u0625\u0631\u0633\u0627\u0644",className:cn("size-9 rounded-sm flex items-center justify-center shrink-0 transition-colors",busy?"bg-ink2 text-surface cursor-pointer hover:bg-ink":canSend?"bg-brand text-white cursor-pointer hover:bg-brand-hover":"bg-soft text-brand-ink/40 cursor-not-allowed"),children:busy?jsx2(Square,{size:13,fill:"currentColor","aria-hidden":"true"}):jsx2(ArrowUp,{size:17,strokeWidth:2.4,"aria-hidden":"true"})})]})]}),mic.denied&&jsx2("span",{className:"text-caption text-red",children:"\u0627\u0644\u0645\u064A\u0643\u0631\u0648\u0641\u0648\u0646 \u0645\u0631\u0641\u0648\u0636 \u2014 \u0627\u0633\u0645\u062D \u0644\u0644\u0645\u0648\u0642\u0639 \u0628\u0627\u0644\u0648\u0635\u0648\u0644 \u0644\u0644\u0645\u064A\u0643\u0631\u0648\u0641\u0648\u0646 \u0645\u0646 \u0625\u0639\u062F\u0627\u062F\u0627\u062A \u0627\u0644\u0645\u062A\u0635\u0641\u0651\u062D."})]})}import{useState as useState5}from"react";import{useState as useState3}from"react";import{ArrowRight,Check as Check2,MessageSquarePlus}from"lucide-react";import{OTHER_PREFIX}from"@qumra/jawab-ai";import{jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";function AskCard({block,onAnswer,live=true}){const[at,setAt]=useState3(0);const[picked,setPicked]=useState3({});const[other,setOther]=useState3({});const[notes,setNotes]=useState3({});const[noting,setNoting]=useState3({});const[sent,setSent]=useState3(null);const answerable=live&&Boolean(onAnswer)&&!sent;const total=block.questions.length;const q=block.questions[at];const last=at===total-1;function toggle(question,value){setPicked(prev=>{const cur=prev[question.key]??[];if(!question.multi)return{...prev,[question.key]:[value]};return{...prev,[question.key]:cur.includes(value)?cur.filter(v=>v!==value):[...cur,value]}})}function valuesFor(question){const base=picked[question.key]??[];const typed=other[question.key]?.trim();return typed?[...base,OTHER_PREFIX+typed]:base}function labelsFor(question){return valuesFor(question).map(v=>v.startsWith(OTHER_PREFIX)?v.slice(OTHER_PREFIX.length):question.options.find(o=>o.value===v)?.label??v)}const answered=valuesFor(q).length>0;const canGo=q.required===false||answered;function submit(){const result={answers:{},values:{}};const notesOut={};for(const question of block.questions){const values=valuesFor(question);if(values.length===0)continue;result.values[question.key]=values;result.answers[question.label]=labelsFor(question).join("\u060C ");const note=notes[question.key]?.trim();if(note)notesOut[question.label]={notes:note}}if(Object.keys(notesOut).length)result.annotations=notesOut;setSent(result);onAnswer?.(block.id,result)}if(sent){return jsxs3("div",{className:"flex flex-col gap-3 p-4 rounded-card border border-line bg-bg",children:[block.questions.map(question=>jsxs3("div",{className:"flex flex-col gap-1.5",children:[jsx3("span",{className:"text-caption text-muted [text-wrap:pretty]",children:question.label}),jsx3(Picked,{labels:(sent.answers[question.label]??"").split("\u060C ").filter(Boolean),note:sent.annotations?.[question.label]?.notes})]},question.key)),jsxs3("span",{className:"flex items-center gap-1.5 text-caption font-bold text-green",children:[jsx3(Check2,{size:13,strokeWidth:2.6,"aria-hidden":"true"}),"\u0627\u062A\u0628\u0639\u062A"]})]})}return jsxs3("div",{className:"flex flex-col gap-3.5 p-4 rounded-card border border-soft2 bg-tint",children:[jsxs3("span",{className:"flex items-center justify-between gap-3",children:[q.header?jsx3("span",{className:"px-2 h-5 rounded-mark bg-soft text-brand-ink text-micro font-extrabold flex items-center",children:q.header}):jsx3("span",{}),total>1&&jsxs3("span",{className:"flex items-center gap-2 shrink-0",children:[jsx3("span",{"aria-hidden":"true",className:"flex items-center gap-1",children:block.questions.map((qq,i)=>jsx3("span",{className:cn("size-1.5 rounded-full transition-colors",i===at?"bg-brand":i<at?"bg-brand/40":"bg-border/40")},qq.key))}),jsxs3("span",{"data-num":true,className:"text-micro font-bold text-muted whitespace-nowrap",children:[at+1," \u0645\u0646 ",total]})]})]}),jsxs3("div",{className:"flex flex-col gap-2",children:[jsx3("span",{className:"text-ui font-extrabold text-ink [text-wrap:pretty]",children:q.label}),q.hint&&jsx3("span",{className:"text-caption leading-[1.7] text-muted",children:q.hint}),jsx3(ChoiceCards,{name:`${block.id}-${q.key}`,multiple:q.multi,disabled:!answerable,value:q.multi?picked[q.key]??[]:picked[q.key]?.[0]??null,onChange:v=>toggle(q,v),options:q.options.map(o=>({value:o.value,label:o.label,meta:o.description}))}),q.other!==false&&jsx3(Input,{size:"sm",value:other[q.key]??"",onChange:e=>setOther(p=>({...p,[q.key]:e.target.value})),disabled:!answerable,placeholder:q.other?.placeholder??"\u0623\u0648 \u0627\u0643\u062A\u0628 \u0625\u062C\u0627\u0628\u062A\u0643\u2026","aria-label":`\u0625\u062C\u0627\u0628\u0629 \u0623\u062E\u0631\u0649 \u0639\u0644\u0649: ${q.label}`}),noting[q.key]?jsx3(Textarea,{rows:2,value:notes[q.key]??"",onChange:e=>setNotes(p=>({...p,[q.key]:e.target.value})),disabled:!answerable,placeholder:"\u062D\u0627\u062C\u0629 \u062A\u062D\u0628\u0651 \u062A\u0642\u0648\u0644\u0647\u0627 \u0645\u0639 \u0627\u062E\u062A\u064A\u0627\u0631\u0643\u2026","aria-label":`\u0645\u0644\u0627\u062D\u0638\u0629 \u0639\u0644\u0649: ${q.label}`}):answerable&&jsxs3("button",{type:"button",onClick:()=>setNoting(p=>({...p,[q.key]:true})),className:"self-start inline-flex items-center gap-1.5 text-micro font-bold text-muted hover:text-brand cursor-pointer transition-colors",children:[jsx3(MessageSquarePlus,{size:13,"aria-hidden":"true"}),"\u0636\u064A\u0641 \u0645\u0644\u0627\u062D\u0638\u0629"]})]}),answerable&&jsxs3("span",{className:"flex items-center gap-2.5",children:[at>0&&jsx3(Button,{size:"sm",variant:"ghost",onClick:()=>setAt(i=>i-1),children:"\u0631\u062C\u0648\u0639"}),last?jsx3(Button,{size:"sm",onClick:submit,disabled:!canGo,children:block.submitLabel??"\u0627\u0628\u0639\u062A"}):jsx3(Button,{size:"sm",onClick:()=>setAt(i=>i+1),disabled:!canGo,iconEnd:jsx3(ArrowRight,{size:13,className:"rtl:rotate-180","aria-hidden":"true"}),children:"\u0627\u0644\u062A\u0627\u0644\u064A"}),!canGo&&jsx3("span",{className:"text-micro text-muted2",children:"\u0627\u062E\u062A\u0627\u0631 \u0625\u062C\u0627\u0628\u0629 \u0627\u0644\u0623\u0648\u0644"})]})]})}function Picked({labels,note}){if(labels.length===0)return jsx3("span",{className:"text-caption text-muted2",children:"\u0627\u062A\u062E\u0637\u0651\u0649"});return jsxs3("span",{className:"flex flex-col gap-1.5",children:[jsx3("span",{className:"flex flex-wrap gap-1.5",children:labels.map((l,i)=>jsxs3("span",{className:"inline-flex items-center gap-1 h-6 px-2 rounded-mark bg-soft text-brand-ink text-caption font-bold",children:[jsx3(Check2,{size:11,strokeWidth:3,"aria-hidden":"true"}),l]},i))}),note&&jsx3("span",{className:"text-micro leading-[1.7] text-muted border-s-2 border-line ps-2",children:note})]})}import{useEffect as useEffect4,useState as useState4}from"react";import{Check as Check3,Copy as Copy2,RotateCcw as RotateCcw2,Sparkles,X}from"lucide-react";import{Fragment as Fragment2,jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";function DraftPanel({draft:source,basis,label,onInsert,onClose,insertLabel="\u0623\u062F\u0631\u0650\u062C",className}){const[attempt,setAttempt]=useState4(0);const[done,setDone]=useState4(false);const{text,streaming,start,finish}=useStreamingText({speed:12});const dynamic=typeof source==="function";useEffect4(()=>{start(dynamic?source(attempt):source)},[attempt,source]);return jsxs4("div",{className:cn("flex flex-col gap-2.5 p-3.5 rounded-card bg-bg border border-line","basis-full order-last w-full",className),children:[jsxs4("span",{className:"flex items-start justify-between gap-3",children:[jsxs4("span",{className:"flex flex-col gap-0.5 min-w-0",children:[jsxs4("span",{className:"flex items-center gap-1.5 text-caption font-extrabold text-ink",children:[jsx4(Sparkles,{size:13,className:"text-brand shrink-0","aria-hidden":"true"}),label]}),jsx4("span",{className:"text-micro leading-[1.65] text-muted",children:basis})]}),onClose&&jsx4("button",{type:"button",onClick:onClose,"aria-label":"\u0625\u063A\u0644\u0627\u0642",className:"shrink-0 size-6 rounded-mark flex items-center justify-center text-muted2 hover:bg-hover hover:text-ink cursor-pointer transition-colors",children:jsx4(X,{size:14,"aria-hidden":"true"})})]}),text===""&&streaming?jsx4(AiThinking,{label:"\u0628\u064A\u0643\u062A\u0628\u2026"}):jsxs4("span",{className:"block text-caption leading-[1.9] text-ink whitespace-pre-wrap [text-wrap:pretty]","aria-live":"polite",children:[text,streaming&&jsx4("span",{"aria-hidden":"true",className:"inline-block w-[2px] h-[1em] align-[-0.15em] ms-0.5 bg-brand animate-pulse"})]}),jsx4("span",{className:"flex items-center gap-2 flex-wrap",children:streaming?jsx4(Button,{size:"sm",variant:"outline",onClick:finish,children:"\u0627\u0639\u0631\u0636\u0647\u0627 \u0643\u0644\u0647\u0627"}):jsxs4(Fragment2,{children:[onInsert&&jsx4(Button,{size:"sm",onClick:()=>{onInsert(text);setDone(true);onClose?.()},icon:jsx4(Check3,{size:13,"aria-hidden":"true"}),children:insertLabel}),jsx4(Button,{size:"sm",variant:"outline",onClick:()=>navigator.clipboard?.writeText(text),icon:jsx4(Copy2,{size:13,"aria-hidden":"true"}),children:"\u0627\u0646\u0633\u062E"}),dynamic&&jsx4(Button,{size:"sm",variant:"ghost",onClick:()=>setAttempt(a=>a+1),icon:jsx4(RotateCcw2,{size:13,"aria-hidden":"true"}),children:"\u0627\u0643\u062A\u0628 \u063A\u064A\u0631\u0647\u0627"})]})}),!streaming&&!done&&jsx4(AiDisclaimer,{children:"\u0645\u0645\u0643\u0646 \u064A\u063A\u0644\u0637 \u2014 \u0627\u0642\u0631\u0627\u0647\u0627 \u0642\u0628\u0644 \u0645\u0627 \u062A\u0646\u0634\u0631\u0647\u0627."})]})}function AiDraft({size="sm",...panel}){const[open,setOpen]=useState4(false);if(!open){return jsx4(Button,{variant:"outline",size,onClick:()=>setOpen(true),icon:jsx4(Sparkles,{size:size==="sm"?13:15,"aria-hidden":"true"}),className:panel.className,children:panel.label})}return jsx4(DraftPanel,{...panel,onClose:()=>setOpen(false)})}import{Fragment as Fragment3,jsx as jsx5}from"react/jsx-runtime";function Markdown({md}){const chunks=md.split(/\n{2,}/);return jsx5(Fragment3,{children:chunks.map((chunk,i)=>{const lines=chunk.split("\n");const bullets=lines.every(l=>/^\s*[-•]\s+/.test(l));const numbers=lines.every(l=>/^\s*\d+[.)]\s+/.test(l));if(bullets||numbers){const items=lines.map(l=>l.replace(/^\s*(?:[-•]|\d+[.)])\s+/,""));const List=numbers?"ol":"ul";return jsx5(List,{className:numbers?"my-2 ps-5 list-decimal marker:text-muted2 flex flex-col gap-1":"my-2 ps-5 list-disc marker:text-muted2 flex flex-col gap-1",children:items.map((it,j)=>jsx5("li",{children:inline(it)},j))},i)}return jsx5("p",{className:"my-2 first:mt-0 last:mb-0 [text-wrap:pretty]",children:inline(chunk)},i)})})}var TOKEN=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\n]+\*)/g;function inline(src){const out=[];let last=0;let m;TOKEN.lastIndex=0;while((m=TOKEN.exec(src))!==null){if(m.index>last)out.push(src.slice(last,m.index));const[full]=m;const key=`${m.index}`;if(full.startsWith("`")){out.push(jsx5("code",{dir:"ltr",className:"px-1 py-px rounded-mark bg-hover text-[0.9em] font-mono text-brand-ink",children:full.slice(1,-1)},key))}else if(full.startsWith("**")){out.push(jsx5("strong",{className:"font-extrabold text-ink",children:full.slice(2,-2)},key))}else{out.push(jsx5("em",{className:"not-italic font-bold",children:full.slice(1,-1)},key))}last=m.index+full.length}if(last<src.length)out.push(src.slice(last));return out}import{Fragment as Fragment4,jsx as jsx6,jsxs as jsxs5}from"react/jsx-runtime";var TONE={good:"green",warn:"amber",bad:"red",plain:"neutral"};var NOTICE_TONE={info:"brand",warn:"amber",danger:"red"};function major(a){return a.minor/10**(a.decimals??2)}function TextBlockView({block}){if(!block.md)return null;return jsx6("div",{className:"text-body leading-[1.95] text-ink2",children:jsx6(Markdown,{md:block.md})})}function MetricBlockView({block}){return jsx6("div",{className:"grid gap-2.5 grid-cols-[repeat(auto-fit,minmax(9.5rem,1fr))]",children:block.items.map((m,i)=>jsx6(StatCard,{tone:TONE[m.tone??"plain"]??"neutral",label:m.label,value:m.amount?jsx6(Money,{value:major(m.amount),currency:isCurrency(m.amount.currency)?m.amount.currency:void 0,compact:true,trimZeros:true}):m.value,hint:m.delta!==void 0?deltaHint(m.delta,m.deltaBasis):void 0},i))})}function deltaHint(delta,basis){const up=delta>0;const flat=delta===0;return jsxs5("span",{className:cn("font-bold",flat?"text-muted2":up?"text-green":"text-red"),children:[flat?"=":up?"\u25B2":"\u25BC"," ",Math.abs(delta),"\u066A",basis?` ${basis}`:""]})}function TableBlockView({block}){const rows=block.rows.map((cells,i)=>{const row={__key:String(i)};block.cols.forEach((c,j)=>{row[c.key]=cells[j]??null});return row});const columns=block.cols.map(c=>({key:c.key,header:c.label,end:c.align==="end",cell:row=>renderCell(row[c.key],c)}));return jsxs5("span",{className:"flex flex-col gap-1.5",children:[block.caption&&jsx6("span",{className:"text-micro text-muted2",children:block.caption}),jsx6(DataTable,{columns,rows,rowKey:r=>r.__key,grid:block.cols.map(c=>c.align==="end"?"1fr":"1.6fr").join("_"),minWidth:block.cols.length*120,mobileCard:row=>jsx6("span",{className:"flex flex-col gap-1",children:block.cols.map(c=>jsxs5("span",{className:"flex items-baseline justify-between gap-3",children:[jsx6("span",{className:"text-micro text-muted2",children:c.label}),jsx6("span",{className:"text-caption text-ink",children:renderCell(row[c.key],c)})]},c.key))})})]})}function renderCell(v,col){if(v===null||v==="")return jsx6("span",{className:"text-muted2",children:"\u2014"});switch(col.format){case"money":return typeof v==="number"?jsx6(Money,{value:v,trimZeros:true}):v;case"badge":return jsx6(Badge,{size:"sm",children:v});case"number":return jsx6("span",{"data-num":true,children:v});default:return v}}function CardsBlockView({block,intents}){return jsx6("div",{className:"grid gap-2.5 grid-cols-[repeat(auto-fill,minmax(13rem,1fr))]",children:block.items.map(c=>jsx6(Card,{children:jsxs5("span",{className:"flex gap-3 items-start",children:[c.img&&jsx6("img",{src:c.img,alt:"",className:"size-12 rounded-sm object-cover bg-hover shrink-0"}),jsxs5("span",{className:"flex flex-col gap-1 min-w-0",children:[jsx6("span",{className:"text-ui font-bold text-ink truncate",children:c.title}),c.subtitle&&jsx6("span",{className:"text-micro text-muted",children:c.subtitle}),c.badge&&jsx6("span",{children:jsx6(Badge,{size:"sm",tone:"brand",children:c.badge})}),c.action&&jsx6(ActionButton,{action:c.action,intents,size:"sm"})]})]})},c.id))})}function ChartBlockView({block}){const labels=block.series.map(p=>String(p.x));const values=block.series.map(p=>p.y);const money=block.unit?.kind==="money";const fmt=v=>block.unit?.kind==="percent"?`${v}\u066A`:v.toLocaleString("ar-EG");if(block.kind==="bar"){return jsx6(BarChart,{labels,series:[{label:"",values}],formatValue:fmt})}return jsx6(TrendChart,{labels:axisLabels(labels),values,pointLabels:labels,formatValue:money?v=>v.toLocaleString("ar-EG"):fmt,height:170})}function axisLabels(all){if(all.length<=3)return all;return[all[0],all[Math.floor(all.length/2)],all[all.length-1]]}function ActionBlockView({block,intents}){const runnable=block.items.filter(a=>intents[a.intent]);if(runnable.length===0)return null;return jsx6("span",{className:"flex flex-wrap gap-2",children:runnable.map((a,i)=>jsx6(ActionButton,{action:a,intents},i))})}function ActionButton({action,intents,size="sm"}){const[asking,setAsking]=useState5(false);const run=intents[action.intent];if(!run)return null;function fire(){setAsking(false);run(action.args)}return jsxs5(Fragment4,{children:[jsx6(Button,{size,variant:action.style==="quiet"?"outline":"primary",onClick:()=>action.confirm?setAsking(true):fire(),children:action.label}),jsx6(Modal,{open:asking,title:action.label,description:action.confirm,onClose:()=>setAsking(false),size:"sm",footer:jsxs5(Fragment4,{children:[jsx6(Button,{variant:"outline",onClick:()=>setAsking(false),children:"\u0625\u0644\u063A\u0627\u0621"}),jsx6(Button,{onClick:fire,children:action.label})]})})]})}function ToolBlockView({block,intents}){const undo=block.undo;const run=undo?intents[undo.intent]:void 0;return jsx6(AiToolCall,{title:block.title,detail:block.detail,state:block.state,onUndo:run&&undo?()=>run(undo.args):void 0,undoLabel:undo?.label})}function NoticeBlockView({block}){return jsx6(Alert,{tone:NOTICE_TONE[block.tone],children:block.text})}function ChipsBlockView({block,onSend}){if(!onSend)return null;const byLabel=new Map(block.items.map(c=>[c.label,c.send]));return jsx6(AiPromptChips,{prompts:block.items.map(c=>c.label),onPick:label=>onSend(byLabel.get(label)??label)})}function BlockView({block,intents,onSend,onInsertDraft,onAnswer,live=true}){switch(block.type){case"text":return jsx6(TextBlockView,{block});case"metric":return jsx6(MetricBlockView,{block});case"table":return jsx6(TableBlockView,{block});case"cards":return jsx6(CardsBlockView,{block,intents});case"chart":return jsx6(ChartBlockView,{block});case"action":return jsx6(ActionBlockView,{block,intents});case"tool":return jsx6(ToolBlockView,{block,intents});case"notice":return jsx6(NoticeBlockView,{block});case"chips":return jsx6(ChipsBlockView,{block,onSend});case"ask":return jsx6(AskCard,{block,onAnswer,live});case"draft":return jsx6(DraftPanel,{draft:block.text,basis:block.basis,label:"\u0645\u0633\u0648\u0651\u062F\u0629",onInsert:onInsertDraft});default:return null}}import{jsx as jsx7,jsxs as jsxs6}from"react/jsx-runtime";var NO_INTENTS={};function ReplyView({reply,streaming,intents=NO_INTENTS,onSend,onInsertDraft,onAnswer,live=true,onRetry,onFeedback,className}){return jsx7(AiMessage,{role:"assistant",fill:true,streaming,sources:reply.sources,copyText:plainText(reply),onRetry,onFeedback,children:jsxs6("span",{className:cn("flex flex-col gap-3",className),children:[reply.blocks.map((block,i)=>jsx7(BlockView,{block,intents,onSend,onInsertDraft,onAnswer,live},i)),reply.disclaimer!==false&&!streaming&&jsx7(AiDisclaimer,{})]})})}function plainText(reply){const parts=[];for(const b of reply.blocks){switch(b.type){case"text":parts.push(b.md);break;case"metric":parts.push(b.items.map(m=>`${m.label}: ${m.value}`).join(" \xB7 "));break;case"table":parts.push([b.cols.map(c=>c.label).join(" "),...b.rows.map(r=>r.map(c=>c??"").join(" "))].join("\n"));break;case"cards":parts.push(b.items.map(c=>c.title).join("\n"));break;case"draft":parts.push(b.text);break;case"tool":parts.push(b.detail?`${b.title} \u2014 ${b.detail}`:b.title);break;case"notice":parts.push(b.text);break;case"ask":parts.push(b.questions.map(q=>q.label).join("\n"));break;case"chart":case"action":case"chips":break}}return parts.filter(Boolean).join("\n\n")}import{useCallback as useCallback2,useEffect as useEffect5,useRef as useRef4,useState as useState6}from"react";import{parseEvent,parseSSE,reduce}from"@qumra/jawab-ai";function useReplyStream(url,init){const[reply,setReply]=useState6(null);const[streaming,setStreaming]=useState6(false);const[error,setError]=useState6(null);const abort=useRef4(null);const lastInput=useRef4("");useEffect5(()=>()=>abort.current?.abort(),[]);const stop=useCallback2(()=>{abort.current?.abort();abort.current=null;setStreaming(false)},[]);const send=useCallback2(text=>{const question=text.trim();if(!question)return;abort.current?.abort();const ctrl=new AbortController;abort.current=ctrl;lastInput.current=question;setError(null);setReply(null);setStreaming(true);void(async()=>{try{const res=await fetch(url,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},body:JSON.stringify({input:question}),signal:ctrl.signal,...init});if(!res.ok||!res.body){throw new StreamError("http_"+res.status,`\u0627\u0644\u062E\u0627\u062F\u0645 \u0631\u062C\u0651\u0639 ${res.status}`)}const decoder=new TextDecoder;const readerStream=res.body.getReader();let rest="";let state=null;for(;;){const{done,value}=await readerStream.read();if(done)break;rest+=decoder.decode(value,{stream:true});const{events,rest:tail}=parseSSE(rest);rest=tail;for(const raw of events){const ev=parseEvent(raw);if(!ev)continue;if(ev.e==="error")throw new StreamError(ev.code,ev.message);state=reduce(state,ev);setReply(state);if(ev.e==="done")break}}setStreaming(false)}catch(e){if(ctrl.signal.aborted)return;const se=e;setError({code:se.code??"unknown",message:se.message??"\u0627\u0644\u0627\u062A\u0635\u0627\u0644 \u0627\u062A\u0642\u0637\u0639.",lastInput:lastInput.current});setStreaming(false)}})()},[url,init]);return{reply,streaming,error,send,stop}}var StreamError=class extends Error{code;constructor(code,message){super(message);this.name="StreamError";this.code=code}};export{AiAvatar,AiComposer,AiDisclaimer,AiDraft,AiMessage,AiPromptChips,AiSources,AiThinking,AiToolCall,AskCard,DraftPanel,ReplyView,useMicLevel,useReplyStream,useStreamingText};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{cn,useUIText}from"./chunk-6DTSIOCB.js";import{cloneElement,isValidElement,useCallback,useEffect,useId,useRef,useState}from"react";import{createPortal}from"react-dom";import{AlertTriangle,CheckCircle2,Info,Loader2,X,XCircle}from"lucide-react";var TOAST_MS={plain:3800,withAction:6500};var TOAST_MAX=4;var TOAST_ACCENT={neutral:"text-muted2",brand:"text-brand-100",green:"text-mint",amber:"text-amber",red:"text-red-100"};var HOST_WEB="fixed z-[60] bottom-4 inset-x-4 sm:inset-x-auto sm:start-5 sm:w-[360px] flex flex-col gap-2 pointer-events-none";var TOAST_ROW="flex items-start gap-3 p-3.5 rounded-card bg-night shadow-toast";var TOAST_ROW_WEB="pointer-events-auto animate-[toast-in_.22s_cubic-bezier(.22,.61,.36,1)]";var TOAST_MARK="shrink-0 mt-0.5";var TOAST_BODY="flex-1 min-w-0 flex flex-col gap-0.5";var TOAST_TITLE="text-ui font-bold leading-snug text-white";var TOAST_DESC="text-caption leading-[1.6] text-white/65";var TOAST_ACTION="shrink-0 text-ui font-extrabold text-mint cursor-pointer";var TOAST_ACTION_WEB="hover:underline underline-offset-4";var TOAST_CLOSE="shrink-0 text-white/40 hover:text-white cursor-pointer transition-colors";var isLoudToast=tone=>tone==="red";var TIP="w-max max-w-[220px] px-2.5 py-1.5 rounded-xs bg-night text-white text-caption leading-[1.6] text-center shadow-tip";import{jsx,jsxs}from"react/jsx-runtime";function useToasts(){const[toasts,setToasts]=useState([]);const seq=useRef(0);const timers=useRef(new Map);const dismiss=useCallback(id=>{const t=timers.current.get(id);if(t)clearTimeout(t);timers.current.delete(id);setToasts(prev=>prev.filter(x=>x.id!==id))},[]);const push=useCallback(input=>{const id=++seq.current;const duration=input.duration??(input.actionLabel?TOAST_MS.withAction:TOAST_MS.plain);setToasts(prev=>[...prev.slice(-(TOAST_MAX-1)),{...input,id}]);if(duration>0&&!input.pending){timers.current.set(id,setTimeout(()=>dismiss(id),duration))}return id},[dismiss]);const update=useCallback((id,patch)=>{setToasts(prev=>prev.map(t=>t.id===id?{...t,...patch}:t))},[]);const clear=useCallback(()=>{timers.current.forEach(clearTimeout);timers.current.clear();setToasts([])},[]);return{toasts,push,dismiss,update,clear}}var TOAST_ICON={neutral:Info,brand:Info,green:CheckCircle2,amber:AlertTriangle,red:XCircle};function ToastHost({toasts,onDismiss,closeLabel}){const ui=useUIText();if(toasts.length===0)return null;return jsx("div",{role:"region","aria-label":ui.alerts,className:HOST_WEB,children:toasts.map(t=>{const Icon=TOAST_ICON[t.tone];return jsxs("div",{role:isLoudToast(t.tone)?"alert":"status",className:cn(TOAST_ROW,TOAST_ROW_WEB,"text-white"),children:[jsx("span",{"aria-hidden":"true",className:cn(TOAST_MARK,TOAST_ACCENT[t.tone]),children:t.pending?jsx(Loader2,{size:17,className:"animate-spin"}):jsx(Icon,{size:17})}),jsxs("span",{className:TOAST_BODY,children:[jsx("span",{className:TOAST_TITLE,children:t.title}),t.description&&jsx("span",{className:TOAST_DESC,children:t.description})]}),t.actionLabel&&jsx("button",{type:"button",onClick:()=>{t.onAction?.();onDismiss(t.id)},className:cn(TOAST_ACTION,TOAST_ACTION_WEB),children:t.actionLabel}),jsx("button",{type:"button",onClick:()=>onDismiss(t.id),"aria-label":closeLabel??ui.close,className:TOAST_CLOSE,children:jsx(X,{size:15,"aria-hidden":"true"})})]},t.id)})})}function Tooltip({content,children,side="top"}){const[open,setOpen]=useState(false);const anchor=useRef(null);const tip=useRef(null);const id=useId();const GAP=7;const EDGE=8;const place=useCallback(()=>{const el=tip.current;const host=anchor.current;if(!el||!host)return;const r=host.getBoundingClientRect();const w=el.offsetWidth;const h=el.offsetHeight;const vw=document.documentElement.clientWidth;const vh=document.documentElement.clientHeight;const left=Math.min(Math.max(r.left+r.width/2-w/2,EDGE),Math.max(EDGE,vw-EDGE-w));const above=side==="top"?r.top-GAP-h>=EDGE:r.bottom+GAP+h>vh-EDGE;const top=above?r.top-GAP-h:r.bottom+GAP;el.style.left=`${left}px`;el.style.top=`${Math.min(Math.max(top,EDGE),Math.max(EDGE,vh-EDGE-h))}px`;el.style.visibility="visible"},[side]);useEffect(()=>{if(!open)return;window.addEventListener("scroll",place,{capture:true,passive:true});window.addEventListener("resize",place,{passive:true});return()=>{window.removeEventListener("scroll",place,{capture:true});window.removeEventListener("resize",place)}},[open,place]);const mount=useCallback(el=>{tip.current=el;if(el)place()},[place]);const described=isValidElement(children)?cloneElement(children,{"aria-describedby":open?id:void 0}):children;return jsxs("span",{ref:anchor,className:"relative inline-flex",onMouseEnter:()=>setOpen(true),onMouseLeave:()=>setOpen(false),onFocus:()=>setOpen(true),onBlur:()=>setOpen(false),children:[described,open&&typeof document!=="undefined"&&createPortal(jsx("span",{id,role:"tooltip",ref:mount,style:{visibility:"hidden",left:0,top:0},className:cn("fixed z-[60]",TIP,"animate-[fade-in_.12s_ease-out] pointer-events-none"),children:content}),document.body)]})}export{useToasts,ToastHost,Tooltip};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var TEXT_SCALE=["micro","caption","ui","body","lead","base","h4","h3","h2","h1","display","hero","title","mega"];var RADIUS_SCALE=["mark","xs","sm","field","card","lg","section","full"];var SHADOW_SCALE=["raise","tip","panel","pop","modal","toast","sheet"];var CONTAINER_SCALE=["page","shell","note","lead"];var ANIMATE_SCALE=["qfade","qslide","tip","tip-up","drawer","drawer-rtl","savebar","skeleton"];var COLOR_SCALE=["surface","bg","line","hover","ink","ink2","muted","muted2","border","soft","soft2","brand-100","brand-900","brand-ink","brand","brand-hover","brand-deep","skeleton","tint","tint2","mint","amber-900","amber","amber-bg","amber-ink","amber-line","amber-hover","green","green-bg","green-bg2","green-line","green-solid","violet","violet-bg","violet-line","violet-solid","red-100","red","red-bg","red-line","danger","danger-hover","night","hero-body","hero-meta","hero-dim","hero-text","code-bg","code-plain","code-key","code-tag","code-attr","code-str","code-num","code-note","code-dim","code-line","code-chip"];var TOKENS={"--font-sans":'"Alexandria", system-ui, sans-serif',"--color-surface":"#ffffff","--color-bg":"#f7f9f9","--color-line":"#edf1f1","--color-hover":"#f2f6f6","--color-ink":"#020809","--color-ink2":"#3d4545","--color-muted":"#5f6a6a","--color-muted2":"#687373","--color-border":"#7f8c8c","--color-soft":"#eaf2f3","--color-soft2":"#dceded","--color-brand-100":"#a5c9cc","--color-brand-900":"#0a2528","--color-brand-ink":"#0f4a4e","--color-brand":"#207982","--color-brand-hover":"#1a646c","--color-brand-deep":"#0b3b3e","--color-skeleton":"#d6dcdc","--color-tint":"#f4faf8","--color-tint2":"#eff6f3","--color-mint":"#7dd3c0","--color-amber-900":"#3d2a05","--color-amber":"#f8ac33","--color-amber-bg":"#fef6e9","--color-amber-ink":"#85570f","--color-amber-line":"#fbd79a","--color-amber-hover":"#de9219","--color-green":"#1e7a45","--color-green-bg":"#f1faf4","--color-green-bg2":"#e9f6ee","--color-green-line":"#bfe6ce","--color-green-solid":"#1e7a45","--color-violet":"#4b3e8e","--color-violet-bg":"#edeaf6","--color-violet-line":"#ded8ef","--color-violet-solid":"#6d5eb8","--color-red-100":"#f3a79e","--color-red":"#8e2b20","--color-red-bg":"#fdecea","--color-red-line":"#f3c9c4","--color-danger":"#c94134","--color-danger-hover":"#a3362b","--color-night":"#0b0f12","--color-hero-body":"#bfd9d8","--color-hero-meta":"#8fb3b2","--color-hero-dim":"#5e7a79","--color-hero-text":"#d7e3e2","--color-code-bg":"#1f1f1f","--color-code-plain":"#d4d4d4","--color-code-key":"#569cd6","--color-code-tag":"#4ec9b0","--color-code-attr":"#9cdcfe","--color-code-str":"#ce9178","--color-code-num":"#b5cea8","--color-code-note":"#6a9955","--color-code-dim":"#858585","--color-code-line":"#303031","--color-code-chip":"#f4f7f7","--text-micro":"11px","--text-caption":"12px","--text-ui":"13px","--text-body":"14px","--text-lead":"15px","--text-base":"16px","--text-base--line-height":"initial","--text-h4":"17px","--text-h3":"20px","--text-h2":"24px","--text-h1":"30px","--text-display":"36px","--text-hero":"44px","--text-title":"40px","--text-mega":"54px","--container-page":"1600px","--container-shell":"1600px","--container-note":"340px","--container-lead":"520px","--radius-mark":"3px","--radius-xs":"5px","--radius-sm":"7px","--radius-field":"9px","--radius-card":"12px","--radius-lg":"14px","--radius-section":"18px","--radius-full":"999px","--shadow-raise":"0 1px 3px var(--shadow-color)","--shadow-tip":"0 6px 18px var(--shadow-color)","--shadow-panel":"0 10px 30px var(--shadow-color)","--shadow-pop":"0 18px 44px var(--shadow-color)","--shadow-modal":"0 24px 60px rgb(2 8 9 / 0.28)","--shadow-toast":"0 16px 40px rgb(2 8 9 / 0.26)","--shadow-sheet":"0 -14px 40px rgb(2 8 9 / 0.28), inset 0 1px 0 rgb(255 255 255 / 0.06)","--shadow-color":"rgb(2 8 9 / 0.14)","--animate-qfade":"qfade 0.16s ease-out","--animate-qslide":"qslidein 0.22s ease-out","--animate-tip":"tip-in 0.26s cubic-bezier(0.2, 0.8, 0.2, 1)","--animate-tip-up":"tip-up 0.3s cubic-bezier(0.2, 0.9, 0.2, 1)","--animate-drawer":"drawer-ltr 0.32s cubic-bezier(0.2, 0.9, 0.2, 1)","--animate-drawer-rtl":"drawer-rtl 0.32s cubic-bezier(0.2, 0.9, 0.2, 1)","--animate-savebar":"savebar-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1)","--animate-skeleton":"skeleton-pulse 1.6s ease-in-out infinite","--num-align":"right","--num-align-far":"left","--num-pad-right":"0.875rem","--num-pad-left":"3.5rem","--num-icon-pad-right":"2.5rem","--num-icon-pad-left":"0.875rem"};var DARK_TOKENS={"--color-surface":"#101718","--color-bg":"#0a0f10","--color-line":"#1e2829","--color-hover":"#1a2425","--color-ink":"#f2f6f6","--color-ink2":"#c7d1d1","--color-muted":"#93a0a0","--color-muted2":"#7a8787","--color-border":"#5e6b6c","--color-soft":"#12363a","--color-soft2":"#17454a","--color-brand-ink":"#7dd3c0","--color-skeleton":"#2c3232","--color-amber":"#f8ac33","--color-amber-bg":"#2b2009","--color-amber-ink":"#f5c77a","--color-amber-line":"#5c4415","--color-green":"#6ecf9a","--color-green-bg":"#0d2119","--color-green-bg2":"#102a22","--color-green-line":"#245140","--color-violet":"#b9aeea","--color-violet-bg":"#1e1a33","--color-violet-line":"#38305c","--color-red":"#f3a79e","--color-red-bg":"#2c1613","--color-red-line":"#5c2a24","--color-code-chip":"#17201f","--shadow-color":"rgb(0 0 0 / 0.55)"};import{extendTailwindMerge}from"tailwind-merge";var twMerge=extendTailwindMerge({extend:{classGroups:{"font-size":[{text:TEXT_SCALE}],rounded:[{rounded:RADIUS_SCALE}],shadow:[{shadow:SHADOW_SCALE}],"max-w":[{"max-w":CONTAINER_SCALE}],animate:[{animate:ANIMATE_SCALE}]}}});function cn(...parts){return twMerge(parts.filter(p=>typeof p==="string"&&p.length>0).join(" "))}var TONE_SOFT={neutral:"bg-hover text-muted",brand:"bg-soft text-brand-ink",amber:"bg-amber-bg text-amber-ink",green:"bg-green-bg2 text-green",red:"bg-red-bg text-red",violet:"bg-violet-bg text-violet"};var TONE_SOLID={neutral:"bg-ink2 text-surface",brand:"bg-brand text-white",amber:"bg-amber text-amber-900",green:"bg-green-solid text-white",red:"bg-danger text-white",violet:"bg-violet-solid text-white"};function toLatinDigits(s){return s.replace(/[٠-٩۰-۹٫٬]/g,c=>{const code=c.charCodeAt(0);if(code===1643)return".";if(code===1644)return"";const base=code>=1776?1776:1632;return String(code-base)})}var VARIANTS={primary:"bg-brand border-brand text-white hover:bg-brand-hover",soft:"bg-soft border-soft2 text-brand-ink hover:bg-soft2",outline:"bg-surface border-border text-ink2 hover:border-brand hover:text-brand-ink",ghost:"bg-transparent border-transparent text-ink2 hover:bg-hover",danger:"bg-danger border-danger text-white hover:bg-danger-hover",link:"bg-transparent border-transparent text-brand-ink hover:underline underline-offset-4 px-0!"};var SIZES={sm:"h-9 px-3.5 gap-1.5 text-ui rounded-sm",md:"h-11 px-4 gap-2 text-body rounded-field",lg:"h-12 px-5 gap-2 text-lead rounded-card",xl:"h-14 px-5.5 gap-4 text-h3 font-extrabold rounded-field"};function buttonClasses(variant="primary",size="md",extra){return cn("inline-flex items-center justify-center border font-bold whitespace-nowrap","cursor-pointer transition-colors duration-150 select-none","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",SIZES[size],VARIANTS[variant],extra)}import{createContext,useCallback,useContext,useSyncExternalStore}from"react";var langStore={subscribe(cb){if(typeof MutationObserver==="undefined")return()=>{};const o=new MutationObserver(cb);o.observe(document.documentElement,{attributes:true,attributeFilter:["lang"]});return()=>o.disconnect()},get:()=>typeof document==="undefined"?"ar-EG":document.documentElement.lang||"ar-EG"};function setLang(tag){if(typeof document==="undefined")return;document.documentElement.lang=tag??""}var LocaleCtx=createContext(null);function useMoneyLocale(){const fromProvider=useContext(LocaleCtx);const serverSnapshot=useCallback(()=>fromProvider??"ar-EG",[fromProvider]);return useSyncExternalStore(langStore.subscribe,langStore.get,serverSnapshot)}function useMoneyLang(){return useMoneyLocale().startsWith("en")}var AR=0;var EN=1;var TEXT={close:["\u0625\u063A\u0644\u0627\u0642","Close"],select:["\u0627\u062E\u062A\u0631\u2026","Select\u2026"],search:["\u0627\u0628\u062D\u062B\u2026","Search\u2026"],searchEverything:["\u0627\u0628\u062D\u062B \u0641\u064A \u0643\u0644 \u062D\u0627\u062C\u0629\u2026","Search everything\u2026"],noResults:["\u0645\u0627\u0641\u064A\u0634 \u0646\u062A\u0627\u064A\u062C","No results"],searchOrAdd:["\u0627\u0628\u062D\u062B \u0623\u0648 \u0623\u0636\u0641\u2026","Search or add\u2026"],now:["\u0627\u0644\u0622\u0646","Now"],videoPlayer:["\u0645\u0634\u063A\u0651\u0644 \u0627\u0644\u0641\u064A\u062F\u064A\u0648","Video player"],rating:["\u0627\u0644\u062A\u0642\u064A\u064A\u0645","Rating"],activeFilters:["\u0627\u0644\u0641\u0644\u0627\u062A\u0631 \u0627\u0644\u0645\u0637\u0628\u0651\u0642\u0629:","Active filters:"],clearAll:["\u0645\u0633\u062D \u0627\u0644\u0643\u0644","Clear all"],row:["\u0635\u0641\u0651","row"],dropImages:["\u0627\u0633\u062D\u0628 \u0627\u0644\u0635\u0648\u0631 \u0647\u0646\u0627","Drop images here"],chooseFromDevice:["\u0627\u062E\u062A\u0631 \u0645\u0646 \u0627\u0644\u062C\u0647\u0627\u0632","Choose from device"],previousPeriod:["\u0627\u0644\u0641\u062A\u0631\u0629 \u0627\u0644\u0633\u0627\u0628\u0642\u0629","Previous period"],less:["\u0623\u0642\u0644","Less"],more:["\u0623\u0643\u062B\u0631","More"],totalSales:["\u0625\u062C\u0645\u0627\u0644\u064A \u0627\u0644\u0645\u0628\u064A\u0639\u0627\u062A","Total sales"],netToYou:["\u0635\u0627\u0641\u064A \u0644\u0643","Net to you"],verifiedAccount:["\u062D\u0633\u0627\u0628 \u0645\u0648\u062B\u0651\u0642","Verified account"],grabHint:["\u0639\u0646\u0635\u0631 \u0642\u0627\u0628\u0644 \u0644\u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0631\u062A\u064A\u0628. \u0627\u0636\u063A\u0637 \u0645\u0633\u0627\u0641\u0629 \u0644\u0645\u0633\u0643\u0647 \u062B\u0645 \u0627\u0644\u0623\u0633\u0647\u0645 \u0644\u062A\u062D\u0631\u064A\u0643\u0647.","Reorderable item. Press space to grab it, then the arrows to move it."],notifications:["\u0627\u0644\u0625\u0634\u0639\u0627\u0631\u0627\u062A","Notifications"],dismiss:["\u0625\u062E\u0641\u0627\u0621","Dismiss"],unread:["\u063A\u064A\u0631 \u0645\u0642\u0631\u0648\u0621","Unread"],noNotifications:["\u0645\u0641\u064A\u0634 \u0625\u0634\u0639\u0627\u0631\u0627\u062A","No notifications"],noNotificationsDesc:["\u0623\u0648\u0644 \u0645\u0627 \u064A\u062D\u0635\u0644 \u062D\u0627\u062C\u0629 \u062A\u0633\u062A\u0627\u0647\u0644\u060C \u0647\u062A\u0644\u0627\u0642\u064A\u0647\u0627 \u0647\u0646\u0627.","When something worth knowing happens, it lands here."],markAllRead:["\u062A\u0639\u0644\u064A\u0645 \u0627\u0644\u0643\u0644 \u0643\u0645\u0642\u0631\u0648\u0621","Mark all as read"],viewAllNotifications:["\u0639\u0631\u0636 \u0643\u0644 \u0627\u0644\u0625\u0634\u0639\u0627\u0631\u0627\u062A","View all notifications"],newNotifications:["\u0625\u0634\u0639\u0627\u0631\u0627\u062A \u062C\u062F\u064A\u062F\u0629","New notifications"],reloadPreview:["\u0625\u0639\u0627\u062F\u0629 \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u0639\u0627\u064A\u0646\u0629","Reload preview"],previousMonth:["\u0627\u0644\u0634\u0647\u0631 \u0627\u0644\u0644\u064A \u0642\u0628\u0644\u0647","Previous month"],nextMonth:["\u0627\u0644\u0634\u0647\u0631 \u0627\u0644\u0644\u064A \u0628\u0639\u062F\u0647","Next month"],whatIsThisNumber:["\u0645\u0627 \u0645\u0639\u0646\u0649 \u0647\u0630\u0627 \u0627\u0644\u0631\u0642\u0645\u061F","What does this number mean?"],explainToMe:["\u0627\u0634\u0631\u062D \u0644\u064A","Explain this"],clearSearch:["\u0645\u0633\u062D \u0627\u0644\u0628\u062D\u062B","Clear search"],alerts:["\u0627\u0644\u062A\u0646\u0628\u064A\u0647\u0627\u062A","Alerts"],whatIsThisOption:["\u0645\u0627 \u0647\u0630\u0627 \u0627\u0644\u062E\u064A\u0627\u0631\u061F","What is this option?"],shouldBeHere:["\u0627\u0644\u0645\u0641\u0631\u0648\u0636 \u062A\u0643\u0648\u0646 \u0647\u0646\u0627","Should be here"],closeExplainer:["\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0634\u0631\u062D","Close explainer"],cancelRecording:["\u0625\u0644\u063A\u0627\u0621 \u0627\u0644\u062A\u0633\u062C\u064A\u0644","Cancel recording"],sendRecording:["\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u062A\u0633\u062C\u064A\u0644","Send recording"],attachFile:["\u0625\u0631\u0641\u0627\u0642 \u0645\u0644\u0641","Attach file"],recordVoice:["\u062A\u0633\u062C\u064A\u0644 \u0635\u0648\u062A\u064A","Record a voice note"],playbackPosition:["\u0645\u0648\u0636\u0639 \u0627\u0644\u062A\u0634\u063A\u064A\u0644","Playback position"],volume:["\u0645\u0633\u062A\u0648\u0649 \u0627\u0644\u0635\u0648\u062A","Volume"],hideSuggestions:["\u0625\u062E\u0641\u0627\u0621 \u0627\u0644\u0627\u0642\u062A\u0631\u0627\u062D\u0627\u062A","Hide suggestions"],askShehab:["\u0627\u0633\u0623\u0644 \u0634\u0647\u0627\u0628\u2026","Ask Shehab\u2026"],shehabThinking:["\u0634\u0647\u0627\u0628 \u0628\u064A\u0641\u0643\u0651\u0631\u2026","Shehab is thinking\u2026"],undo:["\u062A\u0631\u0627\u062C\u0639","Undo"],from:["\u0645\u0646","from"],tryAnotherReply:["\u062C\u0631\u0651\u0628 \u0631\u062F \u062A\u0627\u0646\u064A","Try another reply"],helpfulReply:["\u0631\u062F \u0645\u0641\u064A\u062F","Helpful reply"],unhelpfulReply:["\u0631\u062F \u0645\u0634 \u0645\u0641\u064A\u062F","Unhelpful reply"],aiDisclaimer:["\u0634\u0647\u0627\u0628 \u0645\u0645\u0643\u0646 \u064A\u063A\u0644\u0637. \u0631\u0627\u062C\u0639 \u0627\u0644\u0623\u0631\u0642\u0627\u0645 \u0642\u0628\u0644 \u0645\u0627 \u062A\u062A\u0635\u0631\u0651\u0641 \u0639\u0644\u064A\u0647\u0627.","Shehab can get things wrong. Check the numbers before acting on them."],back10:["\u0631\u062C\u0648\u0639 \u0661\u0660 \u062B\u0648\u0627\u0646\u064A","Back 10 seconds"],forward10:["\u062A\u0642\u062F\u064A\u0645 \u0661\u0660 \u062B\u0648\u0627\u0646\u064A","Forward 10 seconds"],playbackSpeed:["\u0633\u0631\u0639\u0629 \u0627\u0644\u062A\u0634\u063A\u064A\u0644","Playback speed"],arabic:["\u0627\u0644\u0639\u0631\u0628\u064A\u0629","Arabic"],seeMore:["\u0634\u0648\u0641 \u0643\u0645\u0627\u0646","See more"],pictureInPicture:["\u0646\u0627\u0641\u0630\u0629 \u0639\u0627\u0626\u0645\u0629","Picture in picture"]};function useUIText(){return useMoneyLang()?BUNDLES[EN]:BUNDLES[AR]}function build(i){const out={};for(const key of Object.keys(TEXT))out[key]=TEXT[key][i];return out}var BUNDLES=[build(AR),build(EN)];import{useEffect,useId}from"react";import{AlertTriangle,CheckCircle2,Info,X,XCircle}from"lucide-react";var SHEET_LAYER_WEB="fixed inset-0 z-50 flex flex-col justify-end";var SCRIM="bg-black/50";var SCRIM_WEB="flex-1 backdrop-blur-[3px] cursor-default animate-[fade-in_0.2s_ease-out]";var SCRIM_FILL="flex-1";var SHEET="bg-surface rounded-t-section max-h-[82dvh] flex flex-col shadow-sheet";var SHEET_WEB="overflow-clip animate-[sheet-up_0.26s_cubic-bezier(.22,.61,.36,1)]";var SHEET_GRIP_ROW="shrink-0 pt-3 pb-1.5 flex justify-center";var SHEET_GRIP="h-1.5 w-11 rounded-full bg-border";var SHEET_HEAD="shrink-0 flex items-center justify-between gap-3 px-5 pb-3";var SHEET_TITLE="text-h4 font-black tracking-tight";var SHEET_HEAD_ACTIONS="flex items-center gap-3";var SHEET_CLOSE="size-9 rounded-full bg-bg flex items-center justify-center text-muted active:bg-hover active:scale-95 transition-transform cursor-pointer";var SHEET_BODY="flex-1 min-h-0 px-3 pb-4 flex flex-col";var MODAL_LAYER_WEB="fixed inset-0 z-50 flex items-center justify-center p-4";var MODAL_SCRIM="bg-black/45";var MODAL_SCRIM_WEB="absolute inset-0 backdrop-blur-[2px] cursor-default";var MODAL="relative w-full bg-surface rounded-lg border border-line flex flex-col max-h-[85dvh] shadow-modal";var MODAL_WIDTHS={sm:"max-w-md",md:"max-w-xl",lg:"max-w-3xl"};var MODAL_HEAD="shrink-0 flex items-start justify-between gap-4 p-5 border-b border-line";var MODAL_HEAD_TEXT="flex flex-col gap-1 min-w-0";var MODAL_TITLE="text-h4 font-extrabold text-ink m-0";var MODAL_DESC="text-ui text-muted m-0";var MODAL_BODY="flex-1 min-h-0 p-5";var MODAL_FOOT="shrink-0 flex items-center justify-end gap-2.5 p-5 border-t border-line";var CLOSE_BTN="shrink-0 size-8 rounded-sm flex items-center justify-center text-muted hover:bg-hover hover:text-ink transition-colors cursor-pointer";var DRAWER_LAYER_WEB="fixed inset-0 z-50 flex";var DRAWER="w-full sm:w-[420px] bg-surface border-s border-line flex flex-col";var DRAWER_HEAD="shrink-0 h-16 px-4 border-b border-line flex items-center justify-between gap-3";var DRAWER_HEAD_TEXT="flex flex-col gap-0.5 min-w-0";var DRAWER_TITLE="text-lead font-extrabold truncate";var DRAWER_DESC="text-caption text-muted truncate";var DRAWER_BODY="flex-1 min-h-0";var DRAWER_BODY_PAD="p-4";var DRAWER_FOOT="shrink-0 p-4 border-t border-line flex gap-2.5";var ALERT_BORDER={neutral:"border-line",brand:"border-soft2",amber:"border-amber-line",green:"border-green-line",red:"border-red-line",violet:"border-violet-line"};var ALERT="flex items-start gap-3 p-4 rounded-card border";var ALERT_BODY="flex flex-col gap-1.5 flex-1 min-w-0";var ALERT_TITLE="text-body font-extrabold";var ALERT_TEXT="text-ui leading-[1.7] opacity-90";var ALERT_ACTIONS="flex items-center gap-2 mt-1";var isUrgent=tone=>tone==="red"||tone==="amber";var TOAST="flex items-center gap-3 px-4 py-3.5 rounded-card bg-brand-900 shadow-toast";var TOAST_WEB="animate-[fade-in_0.18s_ease-out]";var TOAST_ICON="text-brand-100 shrink-0";var TOAST_TEXT="text-body font-bold text-white flex-1";var EMPTY="flex flex-col items-center justify-center gap-2.5 py-12 px-5 text-center";var EMPTY_ICON="size-12 rounded-card bg-hover flex items-center justify-center text-muted mb-1";var EMPTY_TITLE="text-lead font-extrabold text-ink";var EMPTY_DESC="text-ui leading-[1.75] text-muted max-w-note";var EMPTY_ACTION="mt-1";import{jsx,jsxs}from"react/jsx-runtime";function Sheet({open,title,onClose,action,children,closeLabel}){const ui=useUIText();useEffect(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);if(!open)return null;return jsxs("div",{className:SHEET_LAYER_WEB,role:"dialog","aria-modal":"true","aria-label":title,children:[jsx("button",{type:"button","aria-label":closeLabel??ui.close,onClick:onClose,className:cn(SCRIM,SCRIM_WEB)}),jsxs("div",{className:cn(SHEET,SHEET_WEB,"pb-[env(safe-area-inset-bottom)]"),children:[jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:cn(SHEET_GRIP_ROW,"cursor-grab active:cursor-grabbing"),children:jsx("span",{"aria-hidden":"true",className:SHEET_GRIP})}),jsxs("div",{className:SHEET_HEAD,children:[jsx("span",{className:SHEET_TITLE,children:title}),jsxs("span",{className:SHEET_HEAD_ACTIONS,children:[action,jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:SHEET_CLOSE,children:jsx(X,{size:17,strokeWidth:2.4,"aria-hidden":"true"})})]})]}),jsx("div",{className:cn(SHEET_BODY,"overflow-y-auto overscroll-contain"),children})]})]})}function Modal({open,title,description,onClose,footer,children,size="md",closeLabel}){const ui=useUIText();const titleId=useId();useEffect(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);if(!open)return null;return jsxs("div",{className:MODAL_LAYER_WEB,role:"dialog","aria-modal":"true","aria-labelledby":titleId,children:[jsx("button",{type:"button","aria-label":closeLabel??ui.close,onClick:onClose,className:cn(MODAL_SCRIM,MODAL_SCRIM_WEB)}),jsxs("div",{className:cn(MODAL,"animate-qfade",MODAL_WIDTHS[size]),children:[jsxs("header",{className:MODAL_HEAD,children:[jsxs("div",{className:MODAL_HEAD_TEXT,children:[jsx("h2",{id:titleId,className:MODAL_TITLE,children:title}),description&&jsx("p",{className:MODAL_DESC,children:description})]}),jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:CLOSE_BTN,children:jsx(X,{size:17,"aria-hidden":"true"})})]}),children&&jsx("div",{className:cn(MODAL_BODY,"overflow-y-auto"),children}),footer&&jsx("footer",{className:MODAL_FOOT,children:footer})]})]})}function Drawer({open,title,description,onClose,footer,children,bodyClassName,closeLabel}){const ui=useUIText();const titleId=useId();useEffect(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);if(!open)return null;return jsxs("div",{className:DRAWER_LAYER_WEB,role:"dialog","aria-modal":"true","aria-labelledby":titleId,children:[jsx("button",{type:"button","aria-label":closeLabel??ui.close,onClick:onClose,className:cn(SCRIM_FILL,MODAL_SCRIM,"backdrop-blur-[2px] cursor-default")}),jsxs("aside",{className:cn(DRAWER,"animate-qfade"),children:[jsxs("header",{className:DRAWER_HEAD,children:[jsxs("span",{className:DRAWER_HEAD_TEXT,children:[jsx("span",{id:titleId,className:DRAWER_TITLE,children:title}),description&&jsx("span",{className:DRAWER_DESC,children:description})]}),jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:CLOSE_BTN,children:jsx(X,{size:17,"aria-hidden":"true"})})]}),children&&jsx("div",{className:cn(DRAWER_BODY,"overflow-y-auto",bodyClassName??DRAWER_BODY_PAD),children}),footer&&jsx("footer",{className:DRAWER_FOOT,children:footer})]})]})}var ALERT_ICON={neutral:Info,brand:Info,amber:AlertTriangle,green:CheckCircle2,red:XCircle,violet:Info};function Alert({tone="brand",title,children,actions}){const Icon=ALERT_ICON[tone];return jsxs("div",{role:isUrgent(tone)?"alert":"status",className:cn(ALERT,TONE_SOFT[tone],ALERT_BORDER[tone]),children:[jsx(Icon,{size:18,strokeWidth:2,"aria-hidden":"true"}),jsxs("div",{className:ALERT_BODY,children:[title&&jsx("span",{className:ALERT_TITLE,children:title}),children&&jsx("span",{className:cn(ALERT_TEXT,"[text-wrap:pretty]"),children}),actions&&jsx("span",{className:ALERT_ACTIONS,children:actions})]})]})}function Toast({children,action,icon}){return jsxs("div",{role:"status","aria-live":"polite",className:cn(TOAST,TOAST_WEB),children:[icon??jsx(CheckCircle2,{size:17,className:TOAST_ICON,"aria-hidden":"true"}),jsx("span",{className:TOAST_TEXT,children}),action]})}function EmptyState({icon:Icon,title,description,action}){return jsxs("div",{className:EMPTY,children:[Icon&&jsx("span",{"aria-hidden":"true",className:EMPTY_ICON,children:jsx(Icon,{size:21})}),jsx("span",{className:EMPTY_TITLE,children:title}),description&&jsx("span",{className:cn(EMPTY_DESC,"[text-wrap:pretty]"),children:description}),action&&jsx("span",{className:EMPTY_ACTION,children:action})]})}export{TEXT_SCALE,RADIUS_SCALE,SHADOW_SCALE,CONTAINER_SCALE,ANIMATE_SCALE,COLOR_SCALE,TOKENS,DARK_TOKENS,cn,TONE_SOFT,TONE_SOLID,toLatinDigits,buttonClasses,setLang,LocaleCtx,useMoneyLocale,useMoneyLang,useUIText,Sheet,Modal,Drawer,Alert,Toast,EmptyState};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{Coach,useCoachOptional}from"./chunk-NIEWNSOB.js";import{LocaleCtx,cn,useMoneyLocale,useUIText}from"./chunk-6DTSIOCB.js";var GLYPHS={dollar:{label:"\u062F\u0648\u0644\u0627\u0631",w:24,paths:["M12 2.5v19","M16.5 7c0-1.9-2-3.2-4.5-3.2S7.5 5.1 7.5 7s2 2.8 4.5 3.4 4.5 1.5 4.5 3.4-2 3.2-4.5 3.2S7.5 15.7 7.5 13.8"]},euro:{label:"\u064A\u0648\u0631\u0648",w:24,paths:["M17.5 6.4A7 7 0 1 0 17.5 17.6","M3.5 10h10","M3.5 14h10"]},pound:{label:"\u062C\u0646\u064A\u0647",w:24,paths:["M16 6.2A3.7 3.7 0 0 0 9 7.8v6.4a5 5 0 0 1-2 4h11","M6 12h7"]},egp:{label:"\u062C\u0646\u064A\u0647 \u0645\u0635\u0631\u064A",w:31,paths:["M10.5 6H3.5v12h7","M3.5 12h5.5","M26.5 6.2A3.7 3.7 0 0 0 19.5 7.8v6.4a5 5 0 0 1-2 4h11","M16.5 12h7"]},riyal:{label:"\u0631\u064A\u0627\u0644 \u0633\u0639\u0648\u062F\u064A",w:24,fill:true,paths:["M13.89 3.36L13.89 18.83L21.99 17.11C22.37 16.22 22.62 15.31 22.75 14.36L16.43 15.69L16.43 1.24C15.38 1.82 14.53 2.53 13.89 3.36M2.46 16.08L21.99 11.97C22.37 11.04 22.62 10.12 22.75 9.19L3.19 13.33C2.77 14.24 2.52 15.15 2.46 16.08M13.89 24.0L21.99 22.28C22.37 21.37 22.62 20.45 22.75 19.53L14.58 21.25C14.4 21.65 14.25 22.09 14.13 22.55C14.01 23.01 13.93 23.5 13.89 24.0M1.25 22.22L8.42 20.64C8.98 20.52 9.45 20.21 9.81 19.71L11.14 17.77C11.2 17.67 11.25 17.56 11.29 17.44C11.33 17.32 11.35 17.2 11.35 17.08L11.35 0.0C10.38 0.56 9.54 1.27 8.81 2.12L8.81 18.02L1.98 19.47C1.54 20.47 1.29 21.39 1.25 22.22"]}};var GLYPH_STROKE=2.1;var CURRENCY={SAR:{short:"\u0631.\u0633",word:"\u0631\u064A\u0627\u0644",best:"sign",code:"SAR",sign:"riyal",name:"\u0631\u064A\u0627\u0644 \u0633\u0639\u0648\u062F\u064A",en:"Saudi riyals",decimals:2},AED:{short:"\u062F.\u0625",word:"\u062F\u0631\u0647\u0645",best:"word",code:"AED",sign:null,name:"\u062F\u0631\u0647\u0645 \u0625\u0645\u0627\u0631\u0627\u062A\u064A",en:"UAE dirhams",decimals:2},QAR:{short:"\u0631.\u0642",word:"\u0631\u064A\u0627\u0644",best:"word",code:"QAR",sign:null,name:"\u0631\u064A\u0627\u0644 \u0642\u0637\u0631\u064A",en:"Qatari riyals",decimals:2},KWD:{short:"\u062F.\u0643",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"KWD",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u0643\u0648\u064A\u062A\u064A",en:"Kuwaiti dinars",decimals:3},BHD:{short:"\u062F.\u0628",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"BHD",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u0628\u062D\u0631\u064A\u0646\u064A",en:"Bahraini dinars",decimals:3},OMR:{short:"\u0631.\u0639",word:"\u0631\u064A\u0627\u0644",best:"word",code:"OMR",sign:null,name:"\u0631\u064A\u0627\u0644 \u0639\u0645\u0627\u0646\u064A",en:"Omani riyals",decimals:3},EGP:{short:"\u062C.\u0645",word:"\u062C\u0646\u064A\u0647",best:"word",code:"EGP",sign:"egp",name:"\u062C\u0646\u064A\u0647 \u0645\u0635\u0631\u064A",en:"Egyptian pounds",decimals:2},JOD:{short:"\u062F.\u0623",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"JOD",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u0623\u0631\u062F\u0646\u064A",en:"Jordanian dinars",decimals:3},IQD:{short:"\u062F.\u0639",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"IQD",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u0639\u0631\u0627\u0642\u064A",en:"Iraqi dinars",decimals:3},LBP:{short:"\u0644.\u0644",word:"\u0644\u064A\u0631\u0629",best:"word",code:"LBP",sign:null,name:"\u0644\u064A\u0631\u0629 \u0644\u0628\u0646\u0627\u0646\u064A\u0629",en:"Lebanese pounds",decimals:2},SYP:{short:"\u0644.\u0633",word:"\u0644\u064A\u0631\u0629",best:"word",code:"SYP",sign:null,name:"\u0644\u064A\u0631\u0629 \u0633\u0648\u0631\u064A\u0629",en:"Syrian pounds",decimals:2},YER:{short:"\u0631.\u064A",word:"\u0631\u064A\u0627\u0644",best:"word",code:"YER",sign:null,name:"\u0631\u064A\u0627\u0644 \u064A\u0645\u0646\u064A",en:"Yemeni rials",decimals:2},SDG:{short:"\u062C.\u0633",word:"\u062C\u0646\u064A\u0647",best:"word",code:"SDG",sign:null,name:"\u062C\u0646\u064A\u0647 \u0633\u0648\u062F\u0627\u0646\u064A",en:"Sudanese pounds",decimals:2},MAD:{short:"\u062F.\u0645",word:"\u062F\u0631\u0647\u0645",best:"word",code:"MAD",sign:null,name:"\u062F\u0631\u0647\u0645 \u0645\u063A\u0631\u0628\u064A",en:"Moroccan dirhams",decimals:2},DZD:{short:"\u062F.\u062C",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"DZD",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u062C\u0632\u0627\u0626\u0631\u064A",en:"Algerian dinars",decimals:2},TND:{short:"\u062F.\u062A",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"TND",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u062A\u0648\u0646\u0633\u064A",en:"Tunisian dinars",decimals:3},LYD:{short:"\u062F.\u0644",word:"\u062F\u064A\u0646\u0627\u0631",best:"word",code:"LYD",sign:null,name:"\u062F\u064A\u0646\u0627\u0631 \u0644\u064A\u0628\u064A",en:"Libyan dinars",decimals:3},MRU:{short:"\u0623.\u0645",word:"\u0623\u0648\u0642\u064A\u0629",best:"word",code:"MRU",sign:null,name:"\u0623\u0648\u0642\u064A\u0629 \u0645\u0648\u0631\u064A\u062A\u0627\u0646\u064A\u0629",en:"Mauritanian ouguiya",decimals:2},SOS:{short:"\u0634.\u0635",word:"\u0634\u0644\u0646",best:"word",code:"SOS",sign:null,name:"\u0634\u0644\u0646 \u0635\u0648\u0645\u0627\u0644\u064A",en:"Somali shillings",decimals:0},DJF:{short:"\u0641.\u062C",word:"\u0641\u0631\u0646\u0643",best:"word",code:"DJF",sign:null,name:"\u0641\u0631\u0646\u0643 \u062C\u064A\u0628\u0648\u062A\u064A",en:"Djiboutian francs",decimals:0},KMF:{short:"\u0641.\u0642",word:"\u0641\u0631\u0646\u0643",best:"word",code:"KMF",sign:null,name:"\u0641\u0631\u0646\u0643 \u0642\u0645\u0631\u064A",en:"Comorian francs",decimals:0},USD:{short:"$",word:"\u062F\u0648\u0644\u0627\u0631",best:"sign",code:"USD",sign:"dollar",name:"\u062F\u0648\u0644\u0627\u0631 \u0623\u0645\u0631\u064A\u0643\u064A",en:"US dollars",decimals:2},EUR:{short:"\u20AC",word:"\u064A\u0648\u0631\u0648",best:"sign",code:"EUR",sign:"euro",name:"\u064A\u0648\u0631\u0648",en:"euros",decimals:2},GBP:{short:"\xA3",word:"\u0625\u0633\u062A\u0631\u0644\u064A\u0646\u064A",best:"sign",code:"GBP",sign:"pound",name:"\u062C\u0646\u064A\u0647 \u0625\u0633\u062A\u0631\u0644\u064A\u0646\u064A",en:"pounds sterling",decimals:2}};function isCurrency(c){return Boolean(c&&c in CURRENCY)}function resolve(style,c,locale){if(style!=="best")return style;if(locale.startsWith("ar"))return c.best;return c.sign?"sign":"code"}function format(v,decimals,locale,{signed,compact,trimZeros}){const whole=trimZeros&&Number.isInteger(v);const nf=new Intl.NumberFormat(locale,compact?{notation:"compact",minimumFractionDigits:0,maximumFractionDigits:1}:{minimumFractionDigits:whole?0:decimals,maximumFractionDigits:whole?0:decimals});const sign=v<0?"\u2212":signed&&v>0?"+":"";return sign+nf.format(Math.abs(v))}function unitOf(c,style){return style==="code"?c.code:style==="word"?c.word:style==="sign"?c.sign:c.short}var UNIT={short:"text-[0.82em]",word:"text-[0.86em] font-normal tracking-wide",code:"text-[0.78em] font-bold tracking-wide",sign:"text-[0.9em]"};var SIZE={inherit:"",sm:"text-caption",md:"text-ui",lg:"text-body font-extrabold",xl:"text-h2 font-black"};var TONE={inherit:"",muted:"text-muted",ink:"text-ink",green:"text-green",red:"text-red"};var ROW="inline-flex items-baseline gap-1 whitespace-nowrap";var UNIT_TEXT="opacity-65";var WAS="text-[0.82em] text-muted2 line-through decoration-1";var GLYPH_WEB="inline-block shrink-0 translate-y-[0.1em]";import{createContext,useContext}from"react";import{Fragment,jsx,jsxs}from"react/jsx-runtime";function GlyphMark({glyph}){const g=GLYPHS[glyph];return jsx("svg",{viewBox:`0 0 ${g.w} 24`,width:`${g.w/24}em`,height:"1em",fill:g.fill?"currentColor":"none",stroke:g.fill?void 0:"currentColor",strokeWidth:g.fill?void 0:GLYPH_STROKE,strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":g.label,className:GLYPH_WEB,children:g.paths.map(d=>jsx("path",{d},d))})}var CurrencyCtx=createContext(null);function MoneyProvider({currency,locale,children}){return jsx(CurrencyCtx.Provider,{value:currency,children:jsx(LocaleCtx.Provider,{value:locale??null,children})})}function useCurrency(){return useContext(CurrencyCtx)??"EGP"}function Money({value,currency,size="md",tone="inherit",signed,compact,trimZeros,was,symbol,hideSymbol,className}){const locale=useMoneyLocale();const isEn=locale.startsWith("en");const store=useCurrency();const c=CURRENCY[currency??store];const decimals=c.decimals;const style=resolve(symbol??"best",c,locale);const unitKey=unitOf(c,style);const unit=style==="sign"?c.sign?jsx(GlyphMark,{glyph:c.sign}):c.short:unitKey;return jsxs("span",{className:cn(ROW,SIZE[size],TONE[tone],className),children:[jsx("span",{"data-num":true,children:format(value,decimals,locale,{signed,compact,trimZeros})}),!hideSymbol&&jsxs(Fragment,{children:[jsx("span",{"aria-hidden":"true",className:cn(UNIT_TEXT,UNIT[style]),children:unit}),jsx("span",{className:"sr-only",children:locale.startsWith("ar")?c.name:isEn?c.en:c.code})]}),was!==void 0&&was!==value&&jsx("span",{className:WAS,children:jsx("span",{"data-num":true,children:format(was,decimals,locale,{compact,trimZeros})})})]})}function currencySymbol(c="EGP",style="best",locale="ar"){const cur=CURRENCY[c];const s=resolve(style,cur,locale);if(s==="code")return cur.code;if(s==="word")return cur.word;if(s==="sign")return cur.sign?jsx(GlyphMark,{glyph:cur.sign}):cur.short;return cur.short}var currencyName=(c="EGP")=>CURRENCY[c].name;function useCurrencySymbol(c,style){const locale=useMoneyLocale();const store=useCurrency();return currencySymbol(c??store,style??"best",locale)}import{useState}from"react";import{ChevronLeft,ChevronRight}from"lucide-react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function DataTable({columns,rows,rowKey,grid,minWidth,onRowClick,mobileCard,empty,footer,pageSize,unit,className}){const ui=useUIText();const gridClass=`grid-cols-[${grid}]`;const[page,setPage]=useState(0);const pages=pageSize?Math.max(1,Math.ceil(rows.length/pageSize)):1;const safePage=Math.min(page,Math.max(0,pages-1));const shown=pageSize?rows.slice(safePage*pageSize,safePage*pageSize+pageSize):rows;if(rows.length===0&&empty){return jsx2("div",{className:cn("bg-surface border border-line rounded-card",className),children:empty})}return jsxs2("div",{role:"table",className:cn("bg-surface border border-line rounded-card overflow-clip",className),children:[mobileCard&&jsx2("ul",{className:"md:hidden flex flex-col m-0 p-0 list-none",children:shown.map(row=>jsx2("li",{className:"border-b border-line last:border-0",children:onRowClick?jsx2("button",{type:"button",onClick:()=>onRowClick(row),className:"w-full text-start px-4 py-3 cursor-pointer transition-colors active:bg-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",children:mobileCard(row)}):jsx2("div",{className:"px-4 py-3",children:mobileCard(row)})},rowKey(row)))}),jsx2("div",{className:cn("overflow-x-auto",mobileCard&&"max-md:hidden"),children:jsxs2("div",{style:{minWidth},children:[jsx2("div",{role:"row",className:cn("grid gap-3 items-center px-4 py-3 bg-bg border-b border-line",gridClass),style:{gridTemplateColumns:grid.replace(/_/g," ")},children:columns.map(c=>jsx2("span",{role:"columnheader",className:cn("text-caption font-bold text-muted",c.end&&"text-end"),children:c.header},c.key))}),shown.map(row=>jsx2("div",{role:"row",tabIndex:onRowClick?0:void 0,onKeyDown:onRowClick?e=>{if(e.key==="Enter"||e.key===" "){e.preventDefault();onRowClick(row)}}:void 0,onClick:onRowClick?()=>onRowClick(row):void 0,className:cn("grid gap-3 items-center px-4 py-3 border-b border-line last:border-0 transition-colors",onRowClick&&"cursor-pointer hover:bg-hover focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-brand",!onRowClick&&"hover:bg-hover"),style:{gridTemplateColumns:grid.replace(/_/g," ")},children:columns.map(c=>jsx2("span",{role:"cell",className:cn("min-w-0",c.end&&"flex justify-end"),children:c.cell(row)},c.key))},rowKey(row)))]})}),(footer||pageSize)&&jsxs2("div",{className:"flex items-center justify-between gap-3 px-4 py-3 bg-bg flex-wrap",children:[footer,pageSize&&jsx2(Pager,{page:safePage,pages,from:page*pageSize+1,to:Math.min(rows.length,(page+1)*pageSize),total:rows.length,unit:unit??ui.row,onPage:setPage})]})]})}function Pager({page,pages,from,to,total,unit,onPage}){const ar=new Intl.NumberFormat("ar-EG");const first=page===0;const last=page>=pages-1;const btn=dir=>{const off=dir===-1?first:last;return jsx2("button",{type:"button",disabled:off,"aria-label":dir===-1?"\u0627\u0644\u0635\u0641\u062D\u0629 \u0627\u0644\u0633\u0627\u0628\u0642\u0629":"\u0627\u0644\u0635\u0641\u062D\u0629 \u0627\u0644\u062A\u0627\u0644\u064A\u0629",onClick:()=>onPage(page+dir),className:cn("size-8 rounded-sm flex items-center justify-center transition-colors",off?"text-muted2/40 cursor-not-allowed":"text-ink2 hover:bg-hover cursor-pointer"),children:dir===-1?jsx2(ChevronRight,{size:16,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"}):jsx2(ChevronLeft,{size:16,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"})})};return jsxs2("div",{className:"flex items-center gap-2 ms-auto",children:[jsxs2("span",{className:"text-caption text-muted",children:[jsxs2("span",{"data-num":true,className:"font-bold text-ink2",children:[ar.format(from),"\u2013",ar.format(to)]})," ","\u0645\u0646"," ",jsx2("span",{"data-num":true,className:"font-bold text-ink2",children:ar.format(total)})," ",unit]}),jsx2("span",{"aria-live":"polite",className:"sr-only",children:`\u0639\u0631\u0636 ${from} \u0625\u0644\u0649 ${to} \u0645\u0646 ${total}`}),btn(-1),btn(1)]})}import{useEffect,useId,useMemo,useRef,useState as useState2}from"react";import{scaleLinear}from"@visx/scale";import{AreaClosed,LinePath}from"@visx/shape";import{curveMonotoneX}from"@visx/curve";import{TooltipWithBounds}from"@visx/tooltip";var clamp=(v,lo=0,hi=100)=>Math.min(hi,Math.max(lo,v));var BAR_WRAP="flex flex-col gap-2.5";var BAR_LEGEND="flex items-center gap-4 text-micro text-muted";var BAR_LEGEND_ITEM="flex items-center gap-1.5";var BAR_LEGEND_DOT="size-2.5 rounded-mark";var BAR_PLOT="flex items-end gap-1.5";var BAR_COL="flex-1 flex flex-col items-center justify-end gap-1.5 h-full min-w-0";var BAR_SLOT="w-full flex items-end justify-center gap-[3px]";var BAR="rounded-t-mark transition-[height] duration-300";var BAR_W_MULTI="w-1/2";var BAR_W_SOLO="w-3/5";var BAR_FILL="bg-brand";var BAR_FILL_MUTED="bg-brand-100";var BAR_LABEL="text-micro text-muted2 truncate max-w-full";var BAR_AXIS_H=26;var BAR_MIN_H=2;var TREND_PAD_T=6;var TREND_AXIS_H=24;var TREND_BAR_RATIO=.62;var TREND_WRAP="flex flex-col gap-2";var TREND_GRID_LINE="border-t border-line";var TREND_GRID_TEXT="text-micro text-muted2 bg-surface";var TREND_AXIS_ROW="flex items-center justify-between text-micro text-muted2";var TREND_TIP="rounded-sm border border-line bg-surface px-2.5 py-1.5 shadow-tip flex flex-col gap-0.5";var TREND_TIP_META="text-micro text-muted2";var TREND_TIP_VALUE="text-caption font-extrabold text-ink";var FUNNEL_WRAP="flex flex-col";var FUNNEL_ROW="flex flex-col";var FUNNEL_DROP="flex items-center gap-1.5 ps-1 py-1 text-micro";var FUNNEL_DROP_WORST="font-extrabold text-amber-ink";var FUNNEL_DROP_IDLE="text-muted2";var FUNNEL_TICK="w-px h-3";var FUNNEL_TICK_WORST="bg-amber";var FUNNEL_TICK_IDLE="bg-line";var FUNNEL_BODY="flex items-center gap-3";var FUNNEL_LABEL="w-32 sm:w-40 shrink-0 text-ui text-ink2 truncate";var FUNNEL_TRACK="flex-1 h-8 rounded-xs bg-hover";var FUNNEL_BAR="h-full rounded-xs transition-[width] duration-500";var FUNNEL_BAR_WORST="bg-amber";var FUNNEL_BAR_IDLE="bg-brand";var FUNNEL_VALUE="w-20 shrink-0 text-ui font-extrabold text-ink text-end";var FUNNEL_ADVICE="mt-3 flex items-start gap-2 p-3 rounded-field bg-amber-bg text-caption leading-[1.7] text-amber-ink";function funnelDrops(values){const drops=values.map((v,i)=>{if(i===0)return null;const prev=values[i-1];return prev>0?(prev-v)/prev*100:0});const worst=drops.reduce((acc,d,i)=>d!==null&&d>acc.d?{i,d}:acc,{i:-1,d:-1});return{drops,worst}}var HEAT_TINT=["bg-hover","bg-brand/25","bg-brand/55","bg-brand"];var heatStep=(v,peak)=>v===0?0:Math.min(3,Math.ceil(v/peak*3));var HEAT_WRAP="flex flex-col gap-1";var HEAT_HEAD="text-micro text-muted2 text-center";var HEAT_ROW_LABEL="text-micro text-muted truncate";var HEAT_CELL="h-6 rounded-mark transition-colors";var HEAT_LEGEND="flex items-center gap-2 pt-1 text-micro text-muted2";var HEAT_LEGEND_SWATCH="size-3 rounded-mark";var HEAT_LABEL_W=56;var SHARE_FILL={brand:"bg-brand",amber:"bg-amber",red:"bg-danger",muted:"bg-border"};var SHARE_TRACK="rounded-full bg-hover";var SHARE_TRACK_INLINE="flex-1 h-1.5 min-w-0";var SHARE_TRACK_STACKED="h-1.5";var SHARE_BAR="h-full rounded-full transition-[width] duration-500";var SHARE_ROW_INLINE="flex items-center gap-2.5";var SHARE_ROW_STACKED="flex flex-col gap-1.5";var SHARE_LIST="flex flex-col";var SHARE_LIST_INLINE="gap-1.5";var SHARE_LIST_STACKED="gap-3";var SHARE_HEAD="flex items-center justify-between gap-3";var SHARE_LABEL="text-ui font-bold text-ink truncate";var SHARE_META="text-micro text-muted truncate";var SHARE_VALUE="text-ui font-extrabold text-ink min-w-[64px] text-end";var SHARE_PCT="text-micro text-muted2 w-9 text-end";var SHARE_INLINE_LABEL="shrink-0 text-micro text-muted truncate";var SHARE_INLINE_VALUE="shrink-0 text-caption text-muted2 text-end truncate";import{Fragment as Fragment2,jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";function BarChart({labels,series,height=180,formatValue=String,className}){const peak=Math.max(1,...series.flatMap(s=>s.values));const plot=height-BAR_AXIS_H;return jsxs3("div",{className:cn(BAR_WRAP,className),children:[series.length>1&&jsx3("div",{className:BAR_LEGEND,children:series.map(s=>jsxs3("span",{className:BAR_LEGEND_ITEM,children:[jsx3("span",{"aria-hidden":"true",className:cn(BAR_LEGEND_DOT,s.muted?BAR_FILL_MUTED:BAR_FILL)}),s.label]},s.label))}),jsx3("div",{className:BAR_PLOT,style:{height},role:"img","aria-label":labels.join("\u060C "),children:labels.map((label,i)=>jsxs3("div",{className:BAR_COL,children:[jsx3("span",{className:BAR_SLOT,style:{height:plot},children:series.map(s=>jsx3("span",{title:`${label} \xB7 ${s.label}: ${formatValue(s.values[i]??0)}`,className:cn(BAR,series.length>1?BAR_W_MULTI:BAR_W_SOLO,s.muted?BAR_FILL_MUTED:BAR_FILL),style:{height:Math.max(BAR_MIN_H,Math.round((s.values[i]??0)/peak*plot))}},s.label))}),jsx3("span",{className:BAR_LABEL,children:label})]},label))})]})}function TrendChart({labels,values,compare,pointLabels,mode="area",height=200,formatValue=String,compareLabel,className}){const ui=useUIText();const gid=useId().replace(/:/g,"");const plot=useRef(null);const[w,setW]=useState2(0);const[at,setAt]=useState2(null);const H=height-TREND_AXIS_H;const PAD_T=TREND_PAD_T;useEffect(()=>{const el=plot.current;if(!el)return;const measure=()=>setW(el.clientWidth);measure();const ro=new ResizeObserver(measure);ro.observe(el);return()=>ro.disconnect()},[]);const max=Math.max(1,...values,...compare??[]);const n=values.length;const nameAt=i=>pointLabels?.[i]??(labels.length===n?labels[i]:void 0);const slot=n>0?w/n:w;const bw=slot*TREND_BAR_RATIO;const inset=mode==="bars"?slot/2:0;const x=useMemo(()=>scaleLinear({domain:[0,Math.max(1,n-1)],range:[inset,w-inset]}),[n,w,inset]);const y=useMemo(()=>scaleLinear({domain:[0,max],range:[H,PAD_T]}),[max,H]);function pick(clientX){const el=plot.current;if(!el||!w)return;const rect=el.getBoundingClientRect();const i=Math.round(x.invert(clientX-rect.left));setAt(Math.min(n-1,Math.max(0,i)))}function onKey(e){const step=e.key==="ArrowRight"?1:e.key==="ArrowLeft"?-1:0;if(step){e.preventDefault();setAt(p=>Math.min(n-1,Math.max(0,(p??0)+step)))}else if(e.key==="Home"){e.preventDefault();setAt(0)}else if(e.key==="End"){e.preventDefault();setAt(n-1)}else if(e.key==="Escape"){setAt(null)}}return jsxs3("div",{className:cn(TREND_WRAP,className),children:[jsxs3("div",{ref:plot,dir:"ltr",className:"relative outline-none focus-visible:ring-2 focus-visible:ring-brand/40 rounded-xs",style:{height:H},tabIndex:0,role:"img","aria-label":`${labels[0]} \u2014 ${labels[labels.length-1]}`,onKeyDown:onKey,onPointerMove:e=>pick(e.clientX),onPointerLeave:()=>setAt(null),onBlur:()=>setAt(null),children:[[1,.5,0].map(f=>jsx3("span",{"aria-hidden":"true",className:cn("absolute inset-x-0 flex items-start",TREND_GRID_LINE),style:{top:y(max*f)},children:jsx3("span",{"data-num":true,dir:"auto",className:cn(TREND_GRID_TEXT,"-mt-2 pe-1"),children:formatValue(Math.round(max*f))})},f)),jsxs3("svg",{width:w,height:H,className:"absolute inset-0","aria-hidden":"true",children:[jsx3("defs",{children:jsxs3("linearGradient",{id:`g${gid}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[jsx3("stop",{offset:"0%",stopColor:"currentColor",stopOpacity:"0.16"}),jsx3("stop",{offset:"100%",stopColor:"currentColor",stopOpacity:"0"})]})}),mode==="area"?jsxs3(Fragment2,{children:[jsx3(AreaClosed,{data:values,x:(_,i)=>x(i),y:v=>y(v),yScale:y,curve:curveMonotoneX,className:"text-brand",fill:`url(#g${gid})`,stroke:"none"}),jsx3(LinePath,{data:values,x:(_,i)=>x(i),y:v=>y(v),curve:curveMonotoneX,fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"stroke-brand"})]}):values.map((v,i)=>jsx3("rect",{x:x(i)-bw/2,y:y(v),width:bw,height:Math.max(2,H-y(v)),rx:3,className:at===i?"fill-brand":"fill-brand-100"},i)),compare&&jsx3(LinePath,{data:compare,x:(_,i)=>x(i),y:v=>y(v),curve:curveMonotoneX,fill:"none",strokeWidth:1.5,strokeDasharray:"3 3",strokeLinecap:"round",className:"stroke-brand-100"}),at!==null&&jsxs3(Fragment2,{children:[jsx3("line",{x1:x(at),y1:0,x2:x(at),y2:H,strokeWidth:1,strokeDasharray:"4 4",className:"stroke-brand opacity-45"}),mode==="area"&&jsx3("circle",{cx:x(at),cy:y(values[at]),r:5,strokeWidth:3,className:"fill-surface stroke-brand"})]})]}),at!==null&&w>0&&jsxs3(TooltipWithBounds,{unstyled:true,applyPositionStyle:true,left:x(at),top:y(values[at]),dir:"rtl",className:cn("pointer-events-none",TREND_TIP),children:[nameAt(at)&&jsx3("span",{className:TREND_TIP_META,children:nameAt(at)}),jsx3("span",{"data-num":true,className:TREND_TIP_VALUE,children:formatValue(values[at])}),compare?.[at]!==void 0&&jsxs3("span",{"data-num":true,className:TREND_TIP_META,children:[compareLabel??ui.previousPeriod,": ",formatValue(compare[at])]})]})]}),jsx3("span",{className:"sr-only","aria-live":"polite",children:at!==null?[nameAt(at),formatValue(values[at])].filter(Boolean).join(": "):""}),jsx3("ul",{className:"sr-only",children:values.map((v,i)=>jsx3("li",{children:[nameAt(i),formatValue(v)].filter(Boolean).join(": ")},i))}),jsx3("div",{dir:"ltr",className:TREND_AXIS_ROW,children:labels.map(l=>jsx3("span",{children:l},l))})]})}function FunnelChart({stages,formatValue=String,className}){const top=Math.max(1,stages[0]?.value??1);const{drops,worst}=funnelDrops(stages.map(s=>s.value));return jsxs3("div",{className:cn(FUNNEL_WRAP,className),children:[stages.map((s,i)=>{const share=clamp(s.value/top*100);const drop=drops[i];const isWorst=i===worst.i;return jsxs3("div",{className:FUNNEL_ROW,children:[drop!==null&&jsxs3("span",{className:cn(FUNNEL_DROP,isWorst?FUNNEL_DROP_WORST:FUNNEL_DROP_IDLE),children:[jsx3("span",{"aria-hidden":"true",className:cn(FUNNEL_TICK,isWorst?FUNNEL_TICK_WORST:FUNNEL_TICK_IDLE)}),jsxs3("span",{"data-num":true,children:["\u2212",drop.toFixed(0),"%"]}),isWorst&&jsx3("span",{children:"\xB7 \u0623\u0643\u0628\u0631 \u062A\u0633\u0631\u0651\u0628"})]}),jsxs3("div",{className:FUNNEL_BODY,children:[jsx3("span",{className:FUNNEL_LABEL,children:s.label}),jsx3("span",{className:cn(FUNNEL_TRACK,"overflow-clip"),children:jsx3("span",{className:cn("block",FUNNEL_BAR,isWorst?FUNNEL_BAR_WORST:FUNNEL_BAR_IDLE),style:{width:`${share}%`}})}),jsx3("span",{"data-num":true,className:FUNNEL_VALUE,children:formatValue(s.value)})]})]},s.key)}),worst.i>0&&stages[worst.i].advice&&jsx3("span",{className:FUNNEL_ADVICE,children:stages[worst.i].advice})]})}function Heatmap({rows,cols,values,formatCell=v=>String(v),lowLabel,highLabel,className}){const ui=useUIText();const peak=Math.max(1,...values.flat());const step=v=>heatStep(v,peak);const grid={gridTemplateColumns:`${HEAT_LABEL_W}px repeat(${cols.length}, minmax(0,1fr))`};return jsxs3("div",{className:cn(HEAT_WRAP,className),children:[jsxs3("span",{className:"grid gap-1",style:grid,children:[jsx3("span",{}),cols.map(c=>jsx3("span",{"data-num":true,className:HEAT_HEAD,children:c},c))]}),rows.map((r,ri)=>jsxs3("span",{className:"grid gap-1 items-center",style:grid,children:[jsx3("span",{className:HEAT_ROW_LABEL,children:r}),cols.map((c,ci)=>{const v=values[ri]?.[ci]??0;return jsx3("span",{title:formatCell(v,r,c),className:cn(HEAT_CELL,HEAT_TINT[step(v)])},c)})]},r)),jsxs3("span",{className:HEAT_LEGEND,children:[lowLabel??ui.less,jsx3("span",{className:"flex gap-1",children:HEAT_TINT.map(c=>jsx3("span",{className:cn(HEAT_LEGEND_SWATCH,c)},c))}),highLabel??ui.more]})]})}function ShareList({items,total,layout="stacked",showPercent=true,labelWidth="6rem",formatValue=String,className}){const sum=total??items.reduce((s,i)=>s+i.value,0);const inline=layout==="inline";return jsx3("div",{className:cn(SHARE_LIST,inline?SHARE_LIST_INLINE:SHARE_LIST_STACKED,className),children:items.map(it=>{const pct=sum>0?it.value/sum*100:0;const bar=jsx3("span",{className:cn(SHARE_TRACK,"overflow-clip",inline?SHARE_TRACK_INLINE:cn("block",SHARE_TRACK_STACKED)),children:jsx3("span",{className:cn("block",SHARE_BAR,SHARE_FILL[it.tone??"brand"]),style:{width:`${clamp(pct)}%`}})});if(inline){return jsxs3("span",{className:SHARE_ROW_INLINE,children:[jsx3("span",{style:{width:labelWidth},className:SHARE_INLINE_LABEL,children:it.label}),bar,jsx3("span",{"data-num":true,style:{width:labelWidth},className:SHARE_INLINE_VALUE,children:it.trailing??formatValue(it.value)})]},it.key)}return jsxs3("span",{className:SHARE_ROW_STACKED,children:[jsxs3("span",{className:SHARE_HEAD,children:[jsxs3("span",{className:"flex flex-col min-w-0",children:[jsx3("span",{className:SHARE_LABEL,children:it.label}),it.meta&&jsx3("span",{className:SHARE_META,children:it.meta})]}),jsxs3("span",{className:"flex items-center gap-3 shrink-0",children:[it.trailing,jsx3("span",{"data-num":true,className:SHARE_VALUE,children:formatValue(it.value)}),showPercent&&jsxs3("span",{"data-num":true,className:SHARE_PCT,children:[pct.toFixed(0),"%"]})]})]}),bar]},it.key)})})}import{Check,Info,Lock}from"lucide-react";var GRID="grid gap-2.5";var GRID_COLS={1:"",2:"sm:grid-cols-2",3:"sm:grid-cols-3"};var CARD="relative flex items-start gap-3 p-3.5 rounded-card border transition-colors";var CARD_OFF="border-line bg-bg cursor-not-allowed opacity-70";var CARD_ON="border-brand bg-soft";var CARD_IDLE="border-border bg-surface";var CARD_PICKABLE="cursor-pointer hover:border-brand";var MARK="mt-0.5 size-[19px] border-[1.5px] flex items-center justify-center shrink-0 transition-colors";var MARK_SINGLE="rounded-full";var MARK_MULTI="rounded-mark";var MARK_ON="border-brand bg-brand";var MARK_IDLE="border-border bg-surface";var MARK_CHECK="text-white";var CARD_ICON="size-9 rounded-field flex items-center justify-center shrink-0 transition-colors";var CARD_ICON_ON="bg-brand text-white";var CARD_ICON_IDLE="bg-hover text-muted";var CARD_BODY="flex-1 min-w-0 flex flex-col gap-0.5";var CARD_LABEL="text-body font-extrabold text-ink";var CARD_META="text-caption leading-[1.6] text-muted";var CARD_LOCK="inline-flex items-center gap-1 mt-1 text-caption font-bold text-amber-ink";var CARD_PRICE="text-ui font-extrabold text-ink shrink-0";var CARD_COACH="self-start ms-auto -me-1 -mt-1 size-7 rounded-full shrink-0 flex items-center justify-center text-brand cursor-pointer transition-colors hover:bg-soft hover:text-brand-hover focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand";var SPARK_TOKEN={brand:"brand",green:"green",red:"danger",muted:"muted2"};var SPARK_STROKE_WIDTH=1.5;function sparkPoints(values,width,height){const max=Math.max(...values);const min=Math.min(...values);const span=max-min||1;const step=width/(values.length-1);return values.map((v,i)=>{const x=i*step;const y=height-(v-min)/span*(height-3)-1.5;return[x,y]})}function sparkPaths(values,width,height){const points=sparkPoints(values,width,height);const line=points.map(([x,y],i)=>`${i===0?"M":"L"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");return{line,area:`${line} L${width},${height} L0,${height} Z`}}import{jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";function ChoiceCards({name,value,onChange,options,columns=1,hideMark,multiple,disabled:allDisabled,className}){const ui=useUIText();const coach=useCoachOptional();const cols=GRID_COLS[columns];const picked=Array.isArray(value)?new Set(value):null;return jsx4("div",{role:multiple?"group":"radiogroup",className:cn(GRID,cols,className),children:options.map(o=>{const on=picked?picked.has(o.value):o.value===value;const off=o.disabled||allDisabled;const card=jsxs4("label",{className:cn(CARD,off?CARD_OFF:CARD_PICKABLE,on&&!off?CARD_ON:CARD_IDLE),children:[jsx4("input",{type:multiple?"checkbox":"radio",name,value:o.value,checked:on,disabled:off,onChange:()=>onChange(o.value),className:"sr-only peer"}),!hideMark&&jsx4("span",{"aria-hidden":"true",className:cn(MARK,multiple?MARK_MULTI:MARK_SINGLE,"peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-brand",on&&!off?MARK_ON:MARK_IDLE),children:on&&!off&&jsx4(Check,{size:12,strokeWidth:3,className:MARK_CHECK})}),o.icon&&jsx4("span",{"aria-hidden":"true",className:cn(CARD_ICON,on&&!off?CARD_ICON_ON:CARD_ICON_IDLE),children:jsx4(o.icon,{size:17,strokeWidth:2})}),jsxs4("span",{className:CARD_BODY,children:[jsx4("span",{className:CARD_LABEL,children:o.label}),o.meta&&jsx4("span",{className:CARD_META,children:o.meta}),off&&o.lockReason&&jsxs4("span",{className:CARD_LOCK,children:[jsx4(Lock,{size:11,"aria-hidden":"true"}),o.lockReason]})]}),o.price&&jsx4("span",{"data-num":true,className:CARD_PRICE,children:o.price}),o.coachId&&coach&&jsx4("button",{type:"button",onClick:e=>{e.preventDefault();e.stopPropagation();coach.replay(o.coachId)},"aria-label":typeof o.label==="string"?`\u0645\u0627 \u0645\u0639\u0646\u0649 \xAB${o.label}\xBB\u061F`:"\u0645\u0627 \u0647\u0630\u0627 \u0627\u0644\u062E\u064A\u0627\u0631\u061F",title:ui.whatIsThisOption,className:CARD_COACH,children:jsx4(Info,{size:15,strokeWidth:2,"aria-hidden":"true"})})]});return o.coachId&&coach?jsx4(Coach,{id:o.coachId,children:card},o.value):jsx4("span",{className:"contents",children:card},o.value)})})}function Sparkline({values,width=72,height=24,tone="brand",fluid,className}){if(values.length<2)return null;const{line,area}=sparkPaths(values,width,height);const token=SPARK_TOKEN[tone];const stroke=`stroke-${token}`;const fill=`fill-${token}/10`;return jsxs4("svg",{width:fluid?void 0:width,height:fluid?void 0:height,viewBox:`0 0 ${width} ${height}`,preserveAspectRatio:fluid?"none":void 0,"aria-hidden":"true",style:{direction:"ltr"},className:cn(fluid?"w-full block":"shrink-0","overflow-visible",className),children:[jsx4("path",{d:area,className:cn("stroke-none",fill)}),jsx4("path",{d:line,fill:"none",strokeWidth:SPARK_STROKE_WIDTH,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke",className:stroke})]})}export{isCurrency,MoneyProvider,useCurrency,Money,currencySymbol,currencyName,useCurrencySymbol,DataTable,BarChart,TrendChart,FunnelChart,Heatmap,ShareList,ChoiceCards,Sparkline};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{buttonClasses,cn,toLatinDigits}from"./chunk-6DTSIOCB.js";import{forwardRef}from"react";import{Loader2}from"lucide-react";var ICON_ONLY={sm:"w-9 px-0!",md:"w-10 px-0!",lg:"w-12 px-0!",xl:"w-14 px-0!"};var SPINNER={sm:14,md:15,lg:17,xl:20};var DISABLED="disabled:opacity-50 disabled:cursor-not-allowed";var BLOCK="w-full";import{jsx,jsxs}from"react/jsx-runtime";var Button=forwardRef(function Button2({variant="primary",size="md",icon,iconEnd,iconOnly,loading,block,disabled,className,children,type="button",...rest},ref){return jsxs("button",{ref,type,disabled:disabled||loading,"aria-busy":loading||void 0,className:buttonClasses(variant,size,cn(DISABLED,iconOnly&&ICON_ONLY[size],block&&BLOCK,className)),...rest,children:[loading?jsx(Loader2,{size:SPINNER[size],className:"animate-spin shrink-0","aria-hidden":"true"}):icon&&jsx("span",{className:"flex shrink-0",children:icon}),!iconOnly&&children,!loading&&iconEnd&&jsx("span",{className:"flex shrink-0",children:iconEnd})]})});import{forwardRef as forwardRef2,useId}from"react";import{AlertCircle,Check,ChevronDown,Minus,Search}from"lucide-react";var SHELL="flex flex-col gap-1.5";var SHELL_LABEL_ROW="flex items-center justify-between gap-3 flex-wrap";var LABEL="font-bold text-ink2";var LABEL_SIZE_DEFAULT="text-ui";var LABEL_SIZE_LG="text-body";var LABEL_REQUIRED="text-danger ms-1";var ERROR="flex items-center gap-1.5 text-caption text-red";var HINT="text-caption text-muted";var SIZES={sm:"h-9 text-ui",md:"h-11 text-body",lg:"h-14 text-base border-[1.5px]!"};var base=invalid=>cn("w-full bg-surface text-ink rounded-field border transition-colors outline-none","placeholder:text-muted2","focus:border-brand","disabled:bg-bg disabled:text-muted disabled:cursor-not-allowed",invalid?"border-danger":"border-border hover:border-brand");var PAD={normal:"px-3.5",lg:"px-4.5"};var PAD_ICON={normal:"ps-10",lg:"ps-12"};var PAD_SUFFIX="pe-14";var PAD_ACTION={normal:"pe-11",lg:"pe-14"};var INPUT_ROW="relative flex items-center";var INPUT_ICON="absolute flex text-muted pointer-events-none";var INPUT_ICON_POS={normal:"start-3.5",lg:"start-4.5"};var INPUT_SUFFIX="absolute text-ui text-muted pointer-events-none";var INPUT_SUFFIX_POS={normal:"end-3.5",lg:"end-4.5"};var INPUT_ACTION="absolute flex";var INPUT_ACTION_POS={normal:"end-3",lg:"end-4"};var TEXTAREA="text-body px-3.5 py-3 resize-y min-h-20";var SELECT="appearance-none ps-3.5 pe-9 cursor-pointer font-medium";var SELECT_CHEVRON="absolute end-3.5 text-muted2 pointer-events-none";var CONTROL="peer appearance-none size-[19px] shrink-0 bg-surface border-[1.5px] border-border cursor-pointer transition-colors checked:bg-brand checked:border-brand hover:border-brand focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand disabled:bg-bg disabled:cursor-not-allowed";var CONTROL_CHECKED="bg-brand border-brand";var CONTROL_SQUARE="rounded-xs";var CONTROL_ROUND="rounded-full";var CONTROL_MARK="text-white";var CHOICE_ROW="flex items-start gap-2.5";var CHOICE_BOX="relative inline-flex items-center justify-center mt-px";var CHOICE_LABEL="flex flex-col gap-0.5 cursor-pointer select-none";var CHOICE_LABEL_TEXT="text-body text-ink";var CHOICE_DESC="text-caption text-muted";var RADIO_DOT="absolute size-1.5 rounded-full bg-white pointer-events-none";var GROUP="flex flex-col gap-2.5 border-0 p-0 m-0";var GROUP_LEGEND="text-ui font-bold text-ink2 p-0 mb-1";var GROUP_ROW={inline:"flex flex-row flex-wrap gap-5",stacked:"flex flex-col gap-3"};var SWITCH_TRACK="relative shrink-0 w-11 h-6 rounded-full cursor-pointer transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand disabled:opacity-50 disabled:cursor-not-allowed";var SWITCH_TRACK_ON="bg-brand";var SWITCH_TRACK_OFF="bg-border";var SWITCH_THUMB="absolute top-1/2 -translate-y-1/2 size-5 rounded-full bg-white shadow-sm transition-all duration-200";var SWITCH_THUMB_ON="start-[calc(100%-1.375rem)]";var SWITCH_THUMB_OFF="start-0.5";var SWITCH_ROW="flex items-start gap-3";var SWITCH_TEXT="flex flex-col gap-0.5";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function FieldShell({id,label,labelAside,labelSize,hint,error,required,hideLabel,className,children}){const labelEl=label&&jsxs2("label",{htmlFor:id,className:cn(labelSize??LABEL_SIZE_DEFAULT,LABEL,hideLabel&&"sr-only"),children:[label,required&&jsx2("span",{className:LABEL_REQUIRED,"aria-hidden":"true",children:"*"})]});return jsxs2("div",{className:cn(SHELL,className),children:[labelAside?jsxs2("div",{className:SHELL_LABEL_ROW,children:[labelEl,labelAside]}):labelEl,children,error?jsxs2("span",{id:`${id}-error`,role:"alert",className:ERROR,children:[jsx2(AlertCircle,{size:12,className:"shrink-0","aria-hidden":"true"}),error]}):hint?jsx2("span",{id:`${id}-hint`,className:HINT,children:hint}):null]})}var Input=forwardRef2(function Input2({label,labelAside,hint,error,size="md",hideLabel,icon,suffix,action,numeric,required,className,wrapperClassName,id:idProp,onChange,type,inputMode,...rest},ref){const auto=useId();const id=idProp??auto;const invalid=Boolean(error);const lg=size==="lg";return jsx2(FieldShell,{id,label,labelAside,labelSize:lg?LABEL_SIZE_LG:void 0,hint,error,required,hideLabel,className:wrapperClassName,children:jsxs2("div",{className:INPUT_ROW,children:[icon&&jsx2("span",{className:cn(INPUT_ICON,lg?INPUT_ICON_POS.lg:INPUT_ICON_POS.normal),"aria-hidden":"true",children:icon}),jsx2("input",{ref,id,required,type:numeric?"text":type,inputMode:numeric?inputMode??"decimal":inputMode,"aria-invalid":invalid||void 0,"aria-describedby":error?`${id}-error`:hint?`${id}-hint`:void 0,"data-num":numeric||void 0,"data-suffix":numeric&&suffix?"":void 0,"data-icon":numeric&&icon?"":void 0,onChange:numeric?e=>{const fixed=toLatinDigits(e.target.value);if(fixed!==e.target.value)e.target.value=fixed;onChange?.(e)}:onChange,className:cn(base(invalid),SIZES[size],lg?PAD.lg:PAD.normal,icon&&(lg?PAD_ICON.lg:PAD_ICON.normal),suffix&&PAD_SUFFIX,action&&(lg?PAD_ACTION.lg:PAD_ACTION.normal),className),...rest}),suffix&&jsx2("span",{className:cn(INPUT_SUFFIX,lg?INPUT_SUFFIX_POS.lg:INPUT_SUFFIX_POS.normal),children:suffix}),action&&jsx2("span",{className:cn(INPUT_ACTION,lg?INPUT_ACTION_POS.lg:INPUT_ACTION_POS.normal),children:action})]})})});var SearchInput=forwardRef2(function SearchInput2(props,ref){return jsx2(Input,{ref,icon:jsx2(Search,{size:16}),hideLabel:true,...props})});var Textarea=forwardRef2(function Textarea2({label,hint,error,required,hideLabel,rows=3,className,wrapperClassName,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsx2(FieldShell,{id,label,hint,error,required,hideLabel,className:wrapperClassName,children:jsx2("textarea",{ref,id,rows,required,"aria-invalid":Boolean(error)||void 0,className:cn(base(Boolean(error)),TEXTAREA,className),...rest})})});var Select=forwardRef2(function Select2({label,hint,error,size="md",hideLabel,options,required,className,wrapperClassName,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsx2(FieldShell,{id,label,hint,error,required,hideLabel,className:wrapperClassName,children:jsxs2("div",{className:INPUT_ROW,children:[jsx2("select",{ref,id,required,className:cn(base(Boolean(error)),SIZES[size],SELECT,className),...rest,children:options.map(o=>jsx2("option",{value:o.value,children:o.label},o.value))}),jsx2(ChevronDown,{size:15,"aria-hidden":"true",className:SELECT_CHEVRON})]})})});var Checkbox=forwardRef2(function Checkbox2({label,description,indeterminate,className,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsxs2("span",{className:CHOICE_ROW,children:[jsxs2("span",{className:CHOICE_BOX,children:[jsx2("input",{ref:el=>{if(el)el.indeterminate=Boolean(indeterminate);if(typeof ref==="function")ref(el);else if(ref)ref.current=el},id,type:"checkbox",className:cn(CONTROL,CONTROL_SQUARE,indeterminate&&CONTROL_CHECKED,className),...rest}),indeterminate?jsx2(Minus,{size:12,strokeWidth:3,"aria-hidden":"true",className:cn("absolute pointer-events-none",CONTROL_MARK)}):jsx2(Check,{size:12,strokeWidth:3,"aria-hidden":"true",className:"absolute text-white opacity-0 peer-checked:opacity-100 pointer-events-none transition-opacity"})]}),(label||description)&&jsxs2("label",{htmlFor:id,className:CHOICE_LABEL,children:[label&&jsx2("span",{className:CHOICE_LABEL_TEXT,children:label}),description&&jsx2("span",{className:CHOICE_DESC,children:description})]})]})});var Radio=forwardRef2(function Radio2({label,description,className,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsxs2("span",{className:CHOICE_ROW,children:[jsxs2("span",{className:CHOICE_BOX,children:[jsx2("input",{ref,id,type:"radio",className:cn(CONTROL,CONTROL_ROUND,className),...rest}),jsx2("span",{"aria-hidden":"true",className:cn(RADIO_DOT,"opacity-0 peer-checked:opacity-100 transition-opacity")})]}),(label||description)&&jsxs2("label",{htmlFor:id,className:CHOICE_LABEL,children:[label&&jsx2("span",{className:CHOICE_LABEL_TEXT,children:label}),description&&jsx2("span",{className:CHOICE_DESC,children:description})]})]})});function RadioGroup({label,children,inline}){return jsxs2("fieldset",{className:GROUP,children:[jsx2("legend",{className:GROUP_LEGEND,children:label}),jsx2("div",{className:inline?GROUP_ROW.inline:GROUP_ROW.stacked,children})]})}function Switch({checked,onCheckedChange,label,description,disabled,id:idProp}){const auto=useId();const id=idProp??auto;const control=jsx2("button",{id,type:"button",role:"switch","aria-checked":checked,"aria-labelledby":label?`${id}-label`:void 0,disabled,onClick:()=>onCheckedChange(!checked),className:cn(SWITCH_TRACK,checked?SWITCH_TRACK_ON:SWITCH_TRACK_OFF),children:jsx2("span",{"aria-hidden":"true",className:cn(SWITCH_THUMB,checked?SWITCH_THUMB_ON:SWITCH_THUMB_OFF)})});if(!label)return control;return jsxs2("span",{className:SWITCH_ROW,children:[control,jsxs2("span",{className:SWITCH_TEXT,children:[jsx2("span",{id:`${id}-label`,className:CHOICE_LABEL_TEXT,children:label}),description&&jsx2("span",{className:CHOICE_DESC,children:description})]})]})}export{Button,Input,SearchInput,Textarea,Select,Checkbox,Radio,RadioGroup,Switch};