@qumra/fanar 0.0.12 → 0.0.14

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/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-EXX6U5BJ.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};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{Coach,useCoachOptional}from"./chunk-GMIBQMMR.js";import{LocaleCtx,cn,useMoneyLocale,useUIText}from"./chunk-ZE4S6DBP.js";import{createContext,useContext}from"react";import{Fragment,jsx,jsxs}from"react/jsx-runtime";function Glyph({children,label,w=24}){return jsx("svg",{viewBox:`0 0 ${w} 24`,width:`${w/24}em`,height:"1em",fill:"none",stroke:"currentColor",strokeWidth:2.1,strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":label,className:"inline-block shrink-0 translate-y-[0.1em]",children})}var Dollar=jsxs(Glyph,{label:"\u062F\u0648\u0644\u0627\u0631",children:[jsx("path",{d:"M12 2.5v19"}),jsx("path",{d:"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"})]});var Euro=jsxs(Glyph,{label:"\u064A\u0648\u0631\u0648",children:[jsx("path",{d:"M17.5 6.4A7 7 0 1 0 17.5 17.6"}),jsx("path",{d:"M3.5 10h10"}),jsx("path",{d:"M3.5 14h10"})]});var Pound=jsxs(Glyph,{label:"\u062C\u0646\u064A\u0647",children:[jsx("path",{d:"M16 6.2A3.7 3.7 0 0 0 9 7.8v6.4a5 5 0 0 1-2 4h11"}),jsx("path",{d:"M6 12h7"})]});var EgyptianPound=jsxs(Glyph,{label:"\u062C\u0646\u064A\u0647 \u0645\u0635\u0631\u064A",w:31,children:[jsx("path",{d:"M10.5 6H3.5v12h7"}),jsx("path",{d:"M3.5 12h5.5"}),jsx("path",{d:"M26.5 6.2A3.7 3.7 0 0 0 19.5 7.8v6.4a5 5 0 0 1-2 4h11"}),jsx("path",{d:"M16.5 12h7"})]});var Riyal=jsx("svg",{viewBox:"0 0 24 24",width:"1em",height:"1em",fill:"currentColor",role:"img","aria-label":"\u0631\u064A\u0627\u0644 \u0633\u0639\u0648\u062F\u064A",className:"inline-block shrink-0 translate-y-[0.08em]",children:jsx("path",{d:"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 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:EgyptianPound,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!!c&&c in CURRENCY}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 resolve(style,c,locale){if(style!=="best")return style;if(locale.startsWith("ar"))return c.best;return c.sign?"sign":"code"}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"};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 unit=style==="code"?c.code:style==="word"?c.word:style==="sign"?c.sign??c.short:c.short;return jsxs("span",{className:cn("inline-flex items-baseline gap-1 whitespace-nowrap",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("opacity-65",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:"text-[0.82em] text-muted2 line-through decoration-1",children:jsx("span",{"data-num":true,children:format(was,decimals,locale,{compact,trimZeros})})})]})}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 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??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";import{Fragment as Fragment2,jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";var clamp=(v,lo=0,hi=100)=>Math.min(hi,Math.max(lo,v));function BarChart({labels,series,height=180,formatValue=String,showValues,className}){const plot=useRef(null);const[at,setAt]=useState2(null);const cols=useRef([]);const[tipX,setTipX]=useState2(0);const[,setW]=useState2(0);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 peak=Math.max(1,...series.flatMap(s=>s.values));const n=labels.length;const plotH=height-26;const single=series.length===1;const numbers=showValues??single;const peakAt=at===null?0:Math.max(...series.map(s=>s.values[at]??0));function activate(i){const el=cols.current[i];if(el)setTipX(el.offsetLeft+el.offsetWidth/2);setAt(i)}function onKey(e){const step=e.key==="ArrowRight"?1:e.key==="ArrowLeft"?-1:0;if(step){e.preventDefault();activate(Math.min(n-1,Math.max(0,(at??0)+step)))}else if(e.key==="Home"){e.preventDefault();activate(0)}else if(e.key==="End"){e.preventDefault();activate(n-1)}else if(e.key==="Escape"){setAt(null)}}return jsxs3("div",{className:cn("flex flex-col gap-2.5",className),children:[series.length>1&&jsx3("div",{className:"flex items-center gap-4 text-micro text-muted",children:series.map(s=>jsxs3("span",{className:"flex items-center gap-1.5",children:[jsx3("span",{"aria-hidden":"true",className:cn("size-2.5 rounded-mark",s.muted?"bg-brand-100":"bg-brand")}),s.label]},s.label))}),jsxs3("div",{ref:plot,className:"relative outline-none focus-visible:ring-2 focus-visible:ring-brand/40 rounded-xs",style:{height},tabIndex:0,role:"img","aria-label":labels.join("\u060C "),onKeyDown:onKey,onPointerLeave:()=>setAt(null),onBlur:()=>setAt(null),children:[[1,.5,0].map(f=>jsx3("span",{"aria-hidden":"true",className:"absolute inset-x-0 border-t border-line flex items-start",style:{top:plotH-plotH*f},children:jsx3("span",{"data-num":true,dir:"auto",className:"text-micro text-muted2 -mt-2 bg-surface pe-1",children:formatValue(Math.round(peak*f))})},f)),jsx3("div",{className:"absolute inset-0 flex items-end gap-1.5",children:labels.map((label,i)=>jsxs3("div",{ref:el=>{cols.current[i]=el},onPointerEnter:()=>activate(i),className:cn("flex-1 flex flex-col items-center justify-end gap-1.5 h-full min-w-0 rounded-xs transition-colors",at===i&&"bg-hover"),children:[jsx3("span",{className:"w-full flex items-end justify-center gap-[3px]",style:{height:plotH},children:series.map(s=>jsx3("span",{className:cn("relative flex justify-center rounded-t-mark transition-[height,background-color] duration-300",series.length>1?"w-1/2":"w-3/5",s.muted?"bg-brand-100":at===null||at===i?"bg-brand":"bg-brand-100"),style:{height:Math.max(2,Math.round((s.values[i]??0)/peak*plotH))},children:numbers&&jsx3("span",{"data-num":true,className:"absolute bottom-full mb-1 text-micro font-bold text-ink whitespace-nowrap",children:formatValue(s.values[i]??0)})},s.label))}),jsx3("span",{className:cn("text-micro truncate max-w-full transition-colors",at===i?"text-ink font-bold":"text-muted2"),children:label})]},label))}),at!==null&&jsxs3(TooltipWithBounds,{unstyled:true,applyPositionStyle:true,left:tipX,top:plotH-peakAt/peak*plotH,dir:"rtl",className:"pointer-events-none rounded-sm border border-line bg-surface px-2.5 py-1.5 shadow-tip flex flex-col gap-0.5",children:[jsx3("span",{className:"text-micro text-muted2",children:labels[at]}),series.map(s=>jsxs3("span",{className:"flex items-center gap-2 text-caption text-ink",children:[series.length>1&&jsx3("span",{className:"text-micro text-muted2",children:s.label}),jsx3("span",{"data-num":true,className:"font-extrabold",children:formatValue(s.values[at]??0)})]},s.label))]})]}),jsx3("span",{className:"sr-only","aria-live":"polite",children:at!==null?[labels[at],...series.map(s=>`${s.label}: ${formatValue(s.values[at]??0)}`)].join(" \u2014 "):""}),jsx3("ul",{className:"sr-only",children:labels.map((label,i)=>jsx3("li",{children:[label,...series.map(s=>`${s.label}: ${formatValue(s.values[i]??0)}`)].join(" \u2014 ")},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-24;const PAD_T=6;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*.62;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("flex flex-col gap-2",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:"absolute inset-x-0 border-t border-line flex items-start",style:{top:y(max*f)},children:jsx3("span",{"data-num":true,dir:"auto",className:"text-micro text-muted2 -mt-2 bg-surface 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:"pointer-events-none rounded-sm border border-line bg-surface px-2.5 py-1.5 shadow-tip flex flex-col gap-0.5",children:[nameAt(at)&&jsx3("span",{className:"text-micro text-muted2",children:nameAt(at)}),jsx3("span",{"data-num":true,className:"text-caption font-extrabold text-ink",children:formatValue(values[at])}),compare?.[at]!==void 0&&jsxs3("span",{"data-num":true,className:"text-micro text-muted2",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:"flex items-center justify-between text-micro text-muted2",children:labels.map(l=>jsx3("span",{children:l},l))})]})}function FunnelChart({stages,formatValue=String,className}){const[at,setAt]=useState2(null);const top=Math.max(1,stages[0]?.value??1);const drops=stages.map((s,i)=>{if(i===0)return null;const prev=stages[i-1].value;return prev>0?(prev-s.value)/prev*100:0});const worst=drops.reduce((acc,d,i)=>d!==null&&d>acc.d?{i,d}:acc,{i:-1,d:-1});return jsxs3("div",{className:cn("flex flex-col",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",{tabIndex:0,role:"img","aria-label":`${s.label}: ${formatValue(s.value)}`,onPointerEnter:()=>setAt(i),onPointerLeave:()=>setAt(null),onFocus:()=>setAt(i),onBlur:()=>setAt(null),className:cn("flex flex-col rounded-xs outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-brand/40",at===i&&"bg-hover"),children:[drop!==null&&jsxs3("span",{className:cn("flex items-center gap-1.5 ps-1 py-1 text-micro",isWorst?"font-extrabold text-amber-ink":"text-muted2"),children:[jsx3("span",{"aria-hidden":"true",className:cn("w-px h-3",isWorst?"bg-amber":"bg-line")}),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:"flex items-center gap-3",children:[jsx3("span",{className:"w-32 sm:w-40 shrink-0 text-ui text-ink2 truncate",children:s.label}),jsx3("span",{className:"flex-1 h-8 rounded-xs bg-hover overflow-clip",children:jsx3("span",{className:cn("block h-full rounded-xs transition-[width] duration-500",isWorst?"bg-amber":"bg-brand"),style:{width:`${share}%`}})}),jsx3("span",{"data-num":true,className:"w-20 shrink-0 text-ui font-extrabold text-ink text-end",children:formatValue(s.value)})]}),at===i&&jsxs3("span",{className:"flex flex-wrap items-center gap-x-3 gap-y-0.5 ps-1 pb-1.5 text-micro text-muted",children:[jsxs3("span",{"data-num":true,children:[share.toFixed(share<10?1:0),"% ","\xB7"," ",stages[0]?.label]}),i>0&&jsxs3("span",{"data-num":true,children:["\u2212",formatValue(Math.max(0,stages[i-1].value-s.value))]})]})]},s.key)}),worst.i>0&&stages[worst.i].advice&&jsx3("span",{className:"mt-3 flex items-start gap-2 p-3 rounded-field bg-amber-bg text-caption leading-[1.7] text-amber-ink",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=>v===0?0:Math.min(3,Math.ceil(v/peak*3));const TINT=["bg-hover","bg-brand/25","bg-brand/55","bg-brand"];const grid={gridTemplateColumns:`56px repeat(${cols.length}, minmax(0,1fr))`};return jsxs3("div",{className:cn("flex flex-col gap-1",className),children:[jsxs3("span",{className:"grid gap-1",style:grid,children:[jsx3("span",{}),cols.map(c=>jsx3("span",{"data-num":true,className:"text-micro text-muted2 text-center",children:c},c))]}),rows.map((r,ri)=>jsxs3("span",{className:"grid gap-1 items-center",style:grid,children:[jsx3("span",{className:"text-micro text-muted truncate",children:r}),cols.map((c,ci)=>{const v=values[ri]?.[ci]??0;return jsx3("span",{title:formatCell(v,r,c),className:cn("h-6 rounded-mark transition-colors",TINT[step(v)])},c)})]},r)),jsxs3("span",{className:"flex items-center gap-2 pt-1 text-micro text-muted2",children:[lowLabel??ui.less,jsx3("span",{className:"flex gap-1",children:TINT.map(c=>jsx3("span",{className:cn("size-3 rounded-mark",c)},c))}),highLabel??ui.more]})]})}var SHARE_FILL={brand:"bg-brand",amber:"bg-amber",red:"bg-danger",muted:"bg-border"};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("flex flex-col",inline?"gap-1.5":"gap-3",className),children:items.map(it=>{const pct=sum>0?it.value/sum*100:0;const bar=jsx3("span",{className:cn("rounded-full bg-hover overflow-clip",inline?"flex-1 h-1.5 min-w-0":"block h-1.5"),children:jsx3("span",{className:cn("block h-full rounded-full transition-[width] duration-500",SHARE_FILL[it.tone??"brand"]),style:{width:`${clamp(pct)}%`}})});if(inline){return jsxs3("span",{className:"flex items-center gap-2.5",children:[jsx3("span",{style:{width:labelWidth},className:"shrink-0 text-micro text-muted truncate",children:it.label}),bar,jsx3("span",{"data-num":true,style:{width:labelWidth},className:"shrink-0 text-caption text-muted2 text-end truncate",children:it.trailing??formatValue(it.value)})]},it.key)}return jsxs3("span",{className:"flex flex-col gap-1.5",children:[jsxs3("span",{className:"flex items-center justify-between gap-3",children:[jsxs3("span",{className:"flex flex-col min-w-0",children:[jsx3("span",{className:"text-ui font-bold text-ink truncate",children:it.label}),it.meta&&jsx3("span",{className:"text-micro text-muted truncate",children:it.meta})]}),jsxs3("span",{className:"flex items-center gap-3 shrink-0",children:[it.trailing,jsx3("span",{"data-num":true,className:"text-ui font-extrabold text-ink min-w-[64px] text-end",children:formatValue(it.value)}),showPercent&&jsxs3("span",{"data-num":true,className:"text-micro text-muted2 w-9 text-end",children:[pct.toFixed(0),"%"]})]})]}),bar]},it.key)})})}import{useState as useState3}from"react";import{Check,Info,Lock}from"lucide-react";import{Fragment as Fragment3,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={1:"",2:"sm:grid-cols-2",3:"sm:grid-cols-3"}[columns];const picked=Array.isArray(value)?new Set(value):null;return jsx4("div",{role:multiple?"group":"radiogroup",className:cn("grid gap-2.5",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("relative flex items-start gap-3 p-3.5 rounded-card border transition-colors",off?"border-line bg-bg cursor-not-allowed opacity-70":"cursor-pointer hover:border-brand",on&&!off?"border-brand bg-soft":"border-border bg-surface"),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("mt-0.5 size-[19px] border-[1.5px] flex items-center justify-center shrink-0 transition-colors",multiple?"rounded-mark":"rounded-full","peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-brand",on&&!off?"border-brand bg-brand":"border-border bg-surface"),children:on&&!off&&jsx4(Check,{size:12,strokeWidth:3,className:"text-white"})}),o.icon&&jsx4("span",{"aria-hidden":"true",className:cn("size-9 rounded-field flex items-center justify-center shrink-0 transition-colors",on&&!off?"bg-brand text-white":"bg-hover text-muted"),children:jsx4(o.icon,{size:17,strokeWidth:2})}),jsxs4("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[jsx4("span",{className:"text-body font-extrabold text-ink",children:o.label}),o.meta&&jsx4("span",{className:"text-caption leading-[1.6] text-muted",children:o.meta}),off&&o.lockReason&&jsxs4("span",{className:"inline-flex items-center gap-1 mt-1 text-caption font-bold text-amber-ink",children:[jsx4(Lock,{size:11,"aria-hidden":"true"}),o.lockReason]})]}),o.price&&jsx4("span",{"data-num":true,className:"text-ui font-extrabold text-ink shrink-0",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:cn("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"),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,labels,formatValue=String,className}){const[at,setAt]=useState3(null);if(values.length<2)return null;const max=Math.max(...values);const min=Math.min(...values);const span=max-min||1;const step=width/(values.length-1);const points=values.map((v,i)=>{const x=i*step;const y=height-(v-min)/span*(height-3)-1.5;return[x,y]});const line=points.map(([x,y],i)=>`${i===0?"M":"L"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");const area=`${line} L${width},${height} L0,${height} Z`;const stroke={brand:"stroke-brand",green:"stroke-green",red:"stroke-danger",muted:"stroke-muted2"}[tone];const fill={brand:"fill-brand/10",green:"fill-green/10",red:"fill-danger/10",muted:"fill-muted2/10"}[tone];const pct=at===null?0:at/(values.length-1)*100;function pick(e){const el=e.currentTarget;const w=el.clientWidth||1;const x=e.clientX-el.getBoundingClientRect().left;const i=Math.round(x/w*(values.length-1));setAt(Math.min(values.length-1,Math.max(0,i)))}const text={brand:"text-brand",green:"text-green",red:"text-danger",muted:"text-muted2"}[tone];return jsxs4("span",{className:cn("relative block",text,fluid?"w-full":"inline-block w-fit"),onPointerMove:pick,onPointerLeave:()=>setAt(null),children:[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:1.5,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke",className:stroke})]}),at!==null&&jsxs4(Fragment3,{children:[jsx4("span",{"aria-hidden":"true",style:{left:`${pct}%`,top:`${points[at][1]/height*100}%`},className:"pointer-events-none absolute z-10 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-current bg-surface"}),jsxs4("span",{style:{left:`${pct}%`},className:"pointer-events-none absolute bottom-full z-10 mb-1 -translate-x-1/2 whitespace-nowrap rounded-sm border border-line bg-surface px-1.5 py-0.5 shadow-tip text-micro text-ink",children:[labels?.[at]&&jsxs4("span",{className:"text-muted2",children:[labels[at]," \xB7 "]}),jsx4("span",{"data-num":true,className:"font-bold",children:formatValue(values[at])})]})]}),labels&&jsx4("ul",{className:"sr-only",children:values.map((v,i)=>jsxs4("li",{children:[labels[i],": ",formatValue(v)]},i))})]})}export{isCurrency,MoneyProvider,useCurrency,Money,currencySymbol,currencyName,useCurrencySymbol,DataTable,BarChart,TrendChart,FunnelChart,Heatmap,ShareList,ChoiceCards,Sparkline};
package/dist/index.d.ts CHANGED
@@ -1654,12 +1654,32 @@ interface BarSeries {
1654
1654
  *
1655
1655
  * السلسلتان جنب بعضهما لا فوق بعض: التكديس يخفي أن أحدهما تراجع
1656
1656
  * حين يرتفع الآخر.
1657
+ *
1658
+ * ── ⚠️ كان رسماً يُنظر إليه، فصار رسماً يُقرأ منه ────────────────────────
1659
+ * النسخة الأولى كانت أعمدةً بلا محور ولا أرقام: تقول «الخميس أطول من
1660
+ * الاثنين» ولا تقول بكم. والفرق بين ٩٥ و٦٦ قرارٌ يُتّخذ، وبين ٩٥ و٩٣
1661
+ * لا شيء — والعين لا تفرّق بينهما في عمودين.
1662
+ *
1663
+ * فأُضيف ثلاثة:
1664
+ * ١. **علامات المحور** — الأعلى والنصف والصفر، كما في `TrendChart`.
1665
+ * ٢. **الرقم فوق كل عمود** حين تكون سلسلةً واحدة؛ فإن كانتا سلسلتين
1666
+ * فالأرقام ستّة عشر رقماً في صفّ فتُقرأ ضجيجاً، ومكانها التلميح.
1667
+ * ٣. **عمودٌ نشط** بالمؤشّر أو بالأسهم، وتلميحٌ يعرض كل السلاسل عنده.
1668
+ *
1669
+ * والتنقّل بلوحة المفاتيح ليس زينة: القيم هنا هي كلّ ما في الرسم، ومن لا
1670
+ * يستعمل الفأرة لا يصل إليها بغيره.
1657
1671
  */
1658
- declare function BarChart({ labels, series, height, formatValue, className, }: {
1672
+ declare function BarChart({ labels, series, height, formatValue, showValues, className, }: {
1659
1673
  labels: string[];
1660
1674
  series: BarSeries[];
1661
1675
  height?: number;
1662
1676
  formatValue?: (v: number) => string;
1677
+ /**
1678
+ * الرقم فوق كل عمود.
1679
+ *
1680
+ * افتراضه: نعم للسلسلة الواحدة، لا لأكثر — والشرح فوق.
1681
+ */
1682
+ showValues?: boolean;
1663
1683
  className?: string;
1664
1684
  }): react.JSX.Element;
1665
1685
  /**
@@ -2268,14 +2288,27 @@ declare function ChoiceCards({ name, value, onChange, options, columns, hideMark
2268
2288
  * و`preserveAspectRatio="none"` بيمطّ أفقياً. وعشان المطّ ده السُمك
2269
2289
  * بيتحسب من الشاشة لا من المقاس (`vectorEffect`)، وإلا الخط بيرفع
2270
2290
  * على الشاشة العريضة ويرفع أكتر على الضيقة.
2291
+ *
2292
+ * ── والقيمة تُقرأ بالمرور ───────────────────────────────────────────────
2293
+ * القاعدة فوق («مش يتقري منه قيمة») تبقى صحيحةً في **الشكل الساكن**:
2294
+ * مافيش محاور ولا أرقام مرسومة. لكن الخط اللي جوّه كرت لوحة بيجاوب
2295
+ * سؤالاً تانياً لمّا المؤشّر يقف عليه: «الجمعة كام؟» — والجواب ده كان
2296
+ * بيحتاج فتح شاشة تانية.
2297
+ *
2298
+ * فالمرور بيظهر نقطةً وفقاعةً بقيمة اليوم واسمه إن اتبعت `labels`.
2299
+ * والرسم بيفضل `aria-hidden` وجنبه قائمة `sr-only` بالقيم لمّا يكون
2300
+ * ليها أسماء — الشكل مايوصلش لقارئ الشاشة أصلاً.
2271
2301
  */
2272
- declare function Sparkline({ values, width, height, tone, fluid, className, }: {
2302
+ declare function Sparkline({ values, width, height, tone, fluid, labels, formatValue, className, }: {
2273
2303
  values: number[];
2274
2304
  width?: number;
2275
2305
  height?: number;
2276
2306
  tone?: 'brand' | 'green' | 'red' | 'muted';
2277
2307
  /** يملا عرض الحاوية بدل المقاس الثابت — `width` بيبقى نسبة الرسم */
2278
2308
  fluid?: boolean;
2309
+ /** اسم كل نقطة — بيظهر في الفقاعة وفي قائمة قارئ الشاشة */
2310
+ labels?: string[];
2311
+ formatValue?: (v: number) => string;
2279
2312
  className?: string;
2280
2313
  }): react.JSX.Element | null;
2281
2314
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{ToastHost,Tooltip,useToasts}from"./chunk-ENHEJXVH.js";import{BarChart,ChoiceCards,DataTable,FunnelChart,Heatmap,Money,MoneyProvider,ShareList,Sparkline,TrendChart,currencyName,currencySymbol,isCurrency,useCurrency,useCurrencySymbol}from"./chunk-77ZZDWR4.js";import{Button,Checkbox,Input,Radio,RadioGroup,SearchInput,Select,Switch,Textarea}from"./chunk-VAMRF7HE.js";import{AudioPlayer,Avatar,Badge,Card,CardHeader,Coach,CoachProvider,Counter,PageHeader,Progress,Scrubber,Skeleton,StatCard,VideoPlayer,coachSeconds,formatTime,useAudioLevel,useCoach,useCoachOptional,useMedia}from"./chunk-GMIBQMMR.js";import{ANIMATE_SCALE,Alert,COLOR_SCALE,CONTAINER_SCALE,DARK_TOKENS,Drawer,EmptyState,LocaleCtx,Modal,RADIUS_SCALE,SHADOW_SCALE,Sheet,TEXT_SCALE,TOKENS,TONE_SOFT,TONE_SOLID,Toast,buttonClasses,cn,toLatinDigits,useMoneyLang,useMoneyLocale,useUIText}from"./chunk-ZE4S6DBP.js";import{useEffect,useRef,useState}from"react";import{Minus,Plus,Trash2}from"lucide-react";import{jsx,jsxs}from"react/jsx-runtime";var ar=new Intl.NumberFormat("ar-EG");var BOX={sm:"h-8",md:"h-11",lg:"h-14"};var BTN={sm:"w-8",md:"w-11",lg:"w-14"};var NUM={sm:"text-ui w-10",md:"text-body w-14",lg:"text-h3 w-20"};var ICON={sm:14,md:16,lg:20};function NumberStepper({value,onChange,min=0,max=Infinity,step=1,size="md",unit,onRemove,disabled,label,className}){const[draft,setDraft]=useState(null);const timer=useRef(void 0);useEffect(()=>()=>clearTimeout(timer.current),[]);const atMin=value<=min;const atMax=value>=max;const showRemove=Boolean(onRemove)&&atMin;const bump=dir=>onChange(Math.min(max,Math.max(min,value+dir*step)));const latest=useRef(value);useEffect(()=>{latest.current=value},[value]);function hold(dir){let delay=400;const tick=()=>{const next=Math.min(max,Math.max(min,latest.current+dir*step));if(next===latest.current)return;onChange(next);delay=Math.max(60,delay*.72);timer.current=setTimeout(tick,delay)};timer.current=setTimeout(tick,delay)}const stop=()=>clearTimeout(timer.current);function commit(raw){setDraft(null);const n=Number(toLatinDigits(raw).replace(/[^\d.-]/g,""));if(Number.isNaN(n))return;onChange(Math.min(max,Math.max(min,n)))}const btn=dir=>{const off=disabled||(dir===1?atMax:atMin&&!showRemove);const Icon=dir===1?Plus:showRemove?Trash2:Minus;return jsx("button",{type:"button",disabled:off,"aria-label":dir===1?"\u0632\u064A\u0627\u062F\u0629":showRemove?"\u062D\u0630\u0641":"\u0646\u0642\u0635\u0627\u0646",onClick:()=>dir===-1&&showRemove?onRemove?.():bump(dir),onPointerDown:()=>!off&&!showRemove&&hold(dir),onPointerUp:stop,onPointerLeave:stop,className:cn("flex items-center justify-center shrink-0 self-stretch cursor-pointer select-none","transition-colors",BTN[size],off?"text-muted2/45 cursor-not-allowed":cn("text-ink2 hover:bg-hover active:bg-soft",showRemove&&dir===-1&&"text-danger hover:bg-red-bg")),children:jsx(Icon,{size:ICON[size],strokeWidth:2.4,"aria-hidden":"true"})})};return jsxs("div",{dir:"ltr",className:cn("inline-flex items-center rounded-field border border-line bg-surface overflow-clip","divide-x divide-line","hover:border-border","focus-within:border-brand focus-within:ring-2 focus-within:ring-brand/25","transition-[border-color,box-shadow]",BOX[size],disabled&&"opacity-60",className),children:[btn(-1),jsxs("span",{className:"flex items-center justify-center gap-1 px-1 self-stretch",children:[jsx("input",{"data-num":true,value:draft??ar.format(value),disabled,inputMode:"numeric","aria-label":label??"\u0627\u0644\u0642\u064A\u0645\u0629",onFocus:()=>setDraft(String(value)),onChange:e=>setDraft(toLatinDigits(e.target.value)),onBlur:e=>commit(e.target.value),onKeyDown:e=>e.key==="Enter"&&e.target.blur(),className:cn("bg-transparent outline-none text-center font-extrabold text-ink","disabled:text-muted2",NUM[size])}),unit&&jsx("span",{className:"text-micro text-muted2 select-none shrink-0",children:unit})]}),btn(1)]})}import{MessageSquare,Phone as PhoneIcon}from"lucide-react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function WhatsAppIcon({size=15,...rest}){return jsx2("svg",{viewBox:"0 0 24 24",width:size,height:size,fill:"currentColor","aria-hidden":"true",...rest,children:jsx2("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"})})}var DIAL={"20":{groups:[3,3,4],name:"\u0645\u0635\u0631"},"966":{groups:[2,3,4],name:"\u0627\u0644\u0633\u0639\u0648\u062F\u064A\u0629"},"971":{groups:[2,3,4],name:"\u0627\u0644\u0625\u0645\u0627\u0631\u0627\u062A"},"965":{groups:[4,4],name:"\u0627\u0644\u0643\u0648\u064A\u062A"},"974":{groups:[4,4],name:"\u0642\u0637\u0631"},"973":{groups:[4,4],name:"\u0627\u0644\u0628\u062D\u0631\u064A\u0646"},"968":{groups:[4,4],name:"\u0639\u064F\u0645\u0627\u0646"},"962":{groups:[1,4,4],name:"\u0627\u0644\u0623\u0631\u062F\u0646"},"964":{groups:[3,3,4],name:"\u0627\u0644\u0639\u0631\u0627\u0642"},"961":{groups:[2,3,3],name:"\u0644\u0628\u0646\u0627\u0646"},"963":{groups:[3,3,3],name:"\u0633\u0648\u0631\u064A\u0627"},"970":{groups:[2,3,4],name:"\u0641\u0644\u0633\u0637\u064A\u0646"},"967":{groups:[3,3,3],name:"\u0627\u0644\u064A\u0645\u0646"},"249":{groups:[3,3,3],name:"\u0627\u0644\u0633\u0648\u062F\u0627\u0646"},"212":{groups:[3,3,3],name:"\u0627\u0644\u0645\u063A\u0631\u0628"},"213":{groups:[3,3,3],name:"\u0627\u0644\u062C\u0632\u0627\u0626\u0631"},"216":{groups:[2,3,3],name:"\u062A\u0648\u0646\u0633"},"218":{groups:[2,3,4],name:"\u0644\u064A\u0628\u064A\u0627"},"222":{groups:[2,2,2,2],name:"\u0645\u0648\u0631\u064A\u062A\u0627\u0646\u064A\u0627"},"252":{groups:[2,3,4],name:"\u0627\u0644\u0635\u0648\u0645\u0627\u0644"},"253":{groups:[2,2,2,2],name:"\u062C\u064A\u0628\u0648\u062A\u064A"},"269":{groups:[3,4],name:"\u062C\u0632\u0631 \u0627\u0644\u0642\u0645\u0631"}};var DIALS=Object.keys(DIAL).sort((a,b)=>b.length-a.length);function parsePhone(raw,defaultDial="20"){const digits=raw.replace(/\D/g,"");let rest=digits;const intl=raw.trim().startsWith("+")||digits.startsWith("00");if(digits.startsWith("00"))rest=digits.slice(2);if(intl){for(const d of DIALS){if(rest.startsWith(d)){return{dial:d,local:rest.slice(d.length),country:DIAL[d].name}}}return{dial:"",local:rest}}const local=rest.replace(/^0/,"");return{dial:defaultDial,local,country:DIAL[defaultDial]?.name}}function join(parts,format){if(format==="spaces"||parts.length<2)return parts.join(" ");const[head,...tail]=parts;return`(${head}) ${tail.join("-")}`}function group(local,dial){const rule=DIAL[dial]?.groups;const out=[];let i=0;if(rule){for(const n of rule){if(i>=local.length)break;out.push(local.slice(i,i+n));i+=n}}while(i<local.length){out.push(local.slice(i,i+3));i+=3}return out.filter(Boolean)}var SIZE={inherit:"",sm:"text-caption",md:"text-ui"};function Phone({value,defaultDial="20",format="parens",mask,call,sms,whatsapp,size="md",className}){const{dial,local,country}=parsePhone(value,defaultDial);const e164=`+${dial}${local}`;const shown=mask?`\u2022\u2022\u2022 ${local.slice(-4)}`:dial?join(group(local,dial),format):`+${local}`;const bare=size==="inherit";return jsxs2("span",{className:cn("inline-flex items-center gap-2 min-w-0",className),children:[jsxs2("span",{dir:"ltr",className:cn("inline-flex items-baseline gap-1.5 whitespace-nowrap min-w-0",SIZE[size]),children:[dial&&!mask&&jsxs2("span",{className:cn("opacity-70",!bare&&"text-muted2 font-normal"),title:country,children:["+",dial]}),jsx2("span",{style:{unicodeBidi:"isolate",fontVariantNumeric:"tabular-nums"},className:cn("truncate",!bare&&"font-bold text-ink"),children:shown})]}),(call||sms||whatsapp)&&!mask&&jsxs2("span",{className:"inline-flex items-center gap-0.5 shrink-0",children:[call&&jsx2(Action,{href:`tel:${e164}`,label:`\u0627\u062A\u0635\u0627\u0644 \u0628\u0640${e164}`,children:jsx2(PhoneIcon,{size:14,"aria-hidden":"true"})}),sms&&jsx2(Action,{href:`sms:${e164}`,label:`\u0631\u0633\u0627\u0644\u0629 \u0646\u0635\u0651\u064A\u0629 \u0625\u0644\u0649 ${e164}`,children:jsx2(MessageSquare,{size:14,"aria-hidden":"true"})}),whatsapp&&jsx2(Action,{href:`https://wa.me/${dial}${local}`,label:`\u0648\u0627\u062A\u0633\u0627\u0628 ${e164}`,external:true,className:"hover:text-green",children:jsx2(WhatsAppIcon,{size:15})})]})]})}function Action({href,label,external,className,children}){return jsx2("a",{href,"aria-label":label,title:label,...external?{target:"_blank",rel:"noreferrer"}:{},className:cn("size-7 rounded-sm inline-flex items-center justify-center shrink-0","text-muted hover:text-brand-ink hover:bg-hover transition-colors no-underline",className),children})}import{forwardRef,useId}from"react";import{jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";var LEAD={hex:"#",url:"/"};var TechnicalInput=forwardRef(function TechnicalInput2({kind="code",className,wrapperClassName,...rest},ref){return jsx3(Input,{ref,dir:"ltr",spellCheck:false,autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",inputMode:kind==="url"?"url":"text",wrapperClassName:cn("[unicode-bidi:isolate]",wrapperClassName),className:cn("font-mono tracking-[.01em] [unicode-bidi:isolate] text-start [[dir=rtl]_&]:text-right",className),...rest})});function TechnicalText({children,className}){return jsx3("span",{dir:"ltr",className:cn("inline-block font-mono [unicode-bidi:isolate]",className),children})}function ColorField({label,note,value,onChange,disabled,id:idProp}){const auto=useId();const id=idProp??auto;return jsxs3("div",{className:"flex flex-col gap-1.5 min-w-0",children:[jsx3("label",{htmlFor:`${id}-hex`,className:"text-ui font-bold text-ink2",children:label}),note&&jsx3("span",{className:"text-caption leading-[1.6] text-muted",children:note}),jsxs3("div",{className:"flex items-center gap-2 min-w-0",children:[jsxs3("span",{className:"relative shrink-0 size-11",children:[jsx3("input",{id,type:"color",value:normalizeHex(value)??"#000000",disabled,onChange:e=>onChange(e.target.value.toUpperCase()),"aria-label":typeof label==="string"?label:void 0,className:"absolute inset-0 size-full opacity-0 cursor-pointer disabled:cursor-not-allowed"}),jsx3("span",{"aria-hidden":"true",className:"pointer-events-none block size-11 rounded-field border border-border",style:{background:normalizeHex(value)??"transparent"}})]}),jsx3(TechnicalInput,{id:`${id}-hex`,kind:"hex",hideLabel:true,size:"md",maxLength:7,disabled,value,onChange:e=>onChange(e.target.value),onBlur:()=>{const fixed=normalizeHex(value);if(fixed&&fixed!==value)onChange(fixed);else if(!fixed&&value&&!value.startsWith(LEAD.hex))onChange(`#${value}`)},wrapperClassName:"flex-1 min-w-0"})]})]})}function normalizeHex(input){const raw=input.trim().replace(/^#/,"");if(/^[0-9a-fA-F]{3}$/.test(raw)){return`#${raw.split("").map(c=>c+c).join("").toUpperCase()}`}if(/^[0-9a-fA-F]{6}$/.test(raw))return`#${raw.toUpperCase()}`;return null}import{useCallback,useEffect as useEffect2,useRef as useRef2,useState as useState2}from"react";import{Box,Loader2}from"lucide-react";import{jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";function detailOf(e){return e.detail??{}}function Product3DViewer({src,iosSrc,poster,alt,autoRotate=true,onLoad,onError,onARLaunch,className}){const en=useMoneyLang();const host=useRef2(null);const slot=useRef2(null);const viewer=useRef2(null);const[phase,setPhase]=useState2("idle");const[progress,setProgress]=useState2(0);const[canAR,setCanAR]=useState2(false);const cb=useRef2({onLoad,onError,onARLaunch});useEffect2(()=>{cb.current={onLoad,onError,onARLaunch}},[onLoad,onError,onARLaunch]);useEffect2(()=>{const mount=slot.current;const box=host.current;if(!mount||!box)return;let dead=false;let el=null;setPhase("idle");setProgress(0);setCanAR(false);async function build(target){try{await import("@google/model-viewer");await customElements.whenDefined("model-viewer");if(dead)return;el=document.createElement("model-viewer");viewer.current=el;el.setAttribute("src",src);if(iosSrc)el.setAttribute("ios-src",iosSrc);el.setAttribute("alt",alt);el.setAttribute("camera-controls","");el.setAttribute("touch-action","pan-y");el.setAttribute("shadow-intensity","1");el.setAttribute("ar","");el.setAttribute("ar-modes","webxr scene-viewer quick-look");el.setAttribute("loading","eager");el.style.width="100%";el.style.height="100%";el.style.backgroundColor="transparent";const silence=document.createElement("button");silence.slot="ar-button";silence.style.display="none";silence.tabIndex=-1;silence.setAttribute("aria-hidden","true");el.appendChild(silence);const reduce=typeof matchMedia!=="undefined"&&matchMedia("(prefers-reduced-motion: reduce)").matches;if(autoRotate&&!reduce)el.setAttribute("auto-rotate","");el.addEventListener("progress",e=>{const total=detailOf(e).totalProgress??0;if(!dead)setProgress(total)});el.addEventListener("load",()=>{if(dead)return;setPhase("ready");setCanAR(Boolean(el?.canActivateAR));cb.current.onLoad?.()});el.addEventListener("error",e=>{if(dead)return;setPhase("error");cb.current.onError?.(detailOf(e).type??"load-failed")});target.appendChild(el);setPhase("loading")}catch{if(dead)return;setPhase("error");cb.current.onError?.("viewer-unavailable")}}const io=new IntersectionObserver(entries=>{if(entries.some(x=>x.isIntersecting)){io.disconnect();void build(mount)}},{rootMargin:"200px"});io.observe(box);return()=>{dead=true;io.disconnect();el?.remove();viewer.current=null}},[src,iosSrc,alt,autoRotate]);const launchAR=useCallback(()=>{cb.current.onARLaunch?.();void viewer.current?.activateAR().catch(()=>{})},[]);const pct=Math.round(progress*100);const showPoster=phase!=="ready";return jsxs4("div",{ref:host,className:cn("relative aspect-square w-full overflow-clip rounded-card bg-hover border border-line",className),children:[showPoster&&jsx4("img",{src:poster,alt,loading:"lazy",decoding:"async",draggable:false,className:"absolute inset-0 size-full object-contain"}),jsx4("div",{ref:slot,className:cn("absolute inset-0",showPoster&&"opacity-0"),"aria-hidden":showPoster}),phase==="loading"&&jsxs4("div",{className:"absolute inset-x-0 bottom-0 flex flex-col gap-1.5 p-3",children:[jsxs4("span",{className:"flex items-center gap-2 text-micro font-bold text-ink2",children:[jsx4(Loader2,{size:12,className:"animate-spin shrink-0","aria-hidden":"true"}),en?"Loading 3D model":"\u062C\u0627\u0631\u064A \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062C\u0633\u0651\u0645",jsxs4("span",{dir:"ltr","data-num":true,className:"ms-auto text-muted",children:[pct,"%"]})]}),jsx4("span",{role:"progressbar","aria-valuenow":pct,"aria-valuemin":0,"aria-valuemax":100,"aria-label":en?"Model loading progress":"\u062A\u0642\u062F\u0651\u0645 \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062C\u0633\u0651\u0645",className:"h-1 w-full rounded-full bg-line overflow-clip",children:jsx4("span",{className:"block h-full rounded-full bg-brand transition-[width] duration-200",style:{width:`${pct}%`}})})]}),phase==="ready"&&canAR&&jsxs4("button",{type:"button",onClick:launchAR,className:cn("absolute bottom-3 end-3 inline-flex items-center gap-2 h-9 px-3.5 rounded-full","bg-surface/92 backdrop-blur border border-line shadow-pop","text-ui font-bold text-ink2 cursor-pointer transition-colors hover:text-brand-ink"),children:[jsx4(Box,{size:15,"aria-hidden":"true"}),en?"See it in your space":"\u0634\u0648\u0641\u0647 \u0641\u064A \u0645\u0643\u0627\u0646\u0643"]})]})}import{X}from"lucide-react";import{jsx as jsx5,jsxs as jsxs5}from"react/jsx-runtime";function Tabs({items,value,onChange,variant="pill",label,className}){if(variant==="segmented"){return jsx5("div",{role:"tablist","aria-label":label,className:cn("flex flex-wrap gap-0.5 p-0.5 rounded-field bg-bg self-start","max-w-full overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",className),children:items.map(it=>{const on=it.key===value;return jsxs5("button",{role:"tab",type:"button","aria-selected":on,onClick:()=>onChange(it.key),className:cn("h-9 px-2 sm:px-3.5 rounded-sm inline-flex items-center gap-2 text-ui font-bold cursor-pointer transition-colors","shrink-0 whitespace-nowrap","focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",on?"bg-surface text-ink shadow-raise":"text-muted hover:text-ink"),children:[it.icon&&jsx5(it.icon,{size:14}),it.label,typeof it.count==="number"&&jsx5("span",{"data-num":true,className:"opacity-60",children:it.count})]},it.key)})})}return jsx5("div",{role:"tablist","aria-label":label,className:cn("flex items-center gap-2.5 flex-wrap",className),children:items.map(it=>{const on=it.key===value;return jsxs5("button",{role:"tab",type:"button","aria-selected":on,onClick:()=>onChange(it.key),className:cn("h-10 px-3.5 rounded-field border inline-flex items-center gap-1.5 text-ui font-bold cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",on?"border-brand bg-soft text-brand-ink":"border-border bg-surface text-ink2 hover:border-brand"),children:[it.icon&&jsx5(it.icon,{size:14}),it.label,typeof it.count==="number"&&jsx5("span",{"data-num":true,className:"text-micro opacity-70",children:it.count})]},it.key)})})}function FilterChips({chips,onClearAll,label,clearAllLabel}){const ui=useUIText();if(chips.length===0)return null;return jsxs5("div",{className:"flex items-center gap-2 flex-wrap",children:[jsx5("span",{className:"text-caption text-muted",children:label??ui.activeFilters}),chips.map(c=>jsxs5("button",{type:"button",onClick:c.onClear,className:"inline-flex items-center gap-1.5 h-7 ps-3 pe-2 rounded-full bg-soft text-brand-ink text-caption font-bold cursor-pointer transition-colors hover:bg-soft2",children:[c.label,jsx5(X,{size:12,strokeWidth:2.5,"aria-hidden":"true"})]},c.label)),onClearAll&&jsx5("button",{type:"button",onClick:onClearAll,className:"text-caption font-bold text-muted cursor-pointer hover:text-ink transition-colors",children:clearAllLabel??ui.clearAll})]})}import{useEffect as useEffect3,useId as useId2,useMemo,useRef as useRef3,useState as useState3}from"react";import{Check,ChevronDown,Plus as Plus2,Search,X as X2}from"lucide-react";import{jsx as jsx6,jsxs as jsxs6}from"react/jsx-runtime";function useDismiss(open,close){const ref=useRef3(null);useEffect3(()=>{if(!open)return;function onDown(e){if(ref.current&&!ref.current.contains(e.target))close()}function onKey(e){if(e.key==="Escape")close()}document.addEventListener("mousedown",onDown);document.addEventListener("keydown",onKey);return()=>{document.removeEventListener("mousedown",onDown);document.removeEventListener("keydown",onKey)}},[open,close]);return ref}var TRIGGER="w-full h-10 px-3.5 rounded-field border bg-surface flex items-center gap-2.5 text-body cursor-pointer transition-colors outline-none focus-visible:border-brand";var PANEL="absolute z-30 top-[calc(100%+6px)] inset-x-0 bg-surface border border-line rounded-card shadow-panel overflow-clip animate-[fade-in_.14s_ease-out]";var ITEM="w-full px-3 py-2.5 flex items-center gap-2.5 text-start text-ui cursor-pointer transition-colors hover:bg-hover disabled:opacity-45 disabled:cursor-not-allowed";function Label({id,children}){if(!children)return null;return jsx6("label",{htmlFor:id,className:"text-ui font-bold text-ink2",children})}function Dropdown({label,value,onChange,options,placeholder,className}){const ui=useUIText();const id=useId2();const[open,setOpen]=useState3(false);const ref=useDismiss(open,()=>setOpen(false));const current=options.find(o=>o.value===value);return jsxs6("div",{className:cn("flex flex-col gap-1.5",className),children:[jsx6(Label,{id,children:label}),jsxs6("div",{ref,className:"relative",children:[jsxs6("button",{id,type:"button","aria-haspopup":"listbox","aria-expanded":open,onClick:()=>setOpen(v=>!v),className:cn(TRIGGER,open?"border-brand":"border-border hover:border-brand"),children:[current?.icon,jsx6("span",{className:cn("flex-1 min-w-0 text-start truncate",!current&&"text-muted2"),children:current?.label??placeholder??ui.select}),current?.meta&&jsx6("span",{className:"text-caption text-muted shrink-0",children:current.meta}),jsx6(ChevronDown,{size:15,"aria-hidden":"true",className:cn("text-muted2 shrink-0 transition-transform",open&&"rotate-180")})]}),open&&jsx6("div",{role:"listbox",className:cn(PANEL,"max-h-72 overflow-y-auto py-1"),children:options.map(o=>jsxs6("button",{type:"button",role:"option","aria-selected":o.value===value,disabled:o.disabled,onClick:()=>{onChange(o.value);setOpen(false)},className:cn(ITEM,o.value===value&&"bg-soft"),children:[o.icon,jsxs6("span",{className:"flex-1 min-w-0 flex flex-col",children:[jsx6("span",{className:"font-bold truncate",children:o.label}),o.meta&&jsx6("span",{className:"text-caption text-muted",children:o.meta})]}),o.value===value&&jsx6(Check,{size:14,className:"text-brand-ink shrink-0","aria-hidden":"true"})]},o.value))})]})]})}function Combobox({label,value,onChange,options,placeholder,searchPlaceholder,emptyText,className}){const ui=useUIText();const id=useId2();const[open,setOpen]=useState3(false);const[query,setQuery]=useState3("");const ref=useDismiss(open,()=>setOpen(false));const current=options.find(o=>o.value===value);const results=useMemo(()=>{const q=query.trim();if(!q)return options;return options.filter(o=>o.label.includes(q)||o.meta?.includes(q))},[options,query]);return jsxs6("div",{className:cn("flex flex-col gap-1.5",className),children:[jsx6(Label,{id,children:label}),jsxs6("div",{ref,className:"relative",children:[jsxs6("button",{id,type:"button","aria-haspopup":"listbox","aria-expanded":open,onClick:()=>{setOpen(v=>!v);setQuery("")},className:cn(TRIGGER,open?"border-brand":"border-border hover:border-brand"),children:[jsx6("span",{className:cn("flex-1 min-w-0 text-start truncate",!current&&"text-muted2"),children:current?.label??placeholder??ui.select}),current?.meta&&jsx6("span",{className:"text-caption text-muted shrink-0",children:current.meta}),jsx6(ChevronDown,{size:15,"aria-hidden":"true",className:cn("text-muted2 shrink-0 transition-transform",open&&"rotate-180")})]}),open&&jsxs6("div",{className:PANEL,children:[jsxs6("div",{className:"flex items-center gap-2.5 px-3 h-11 border-b border-line",children:[jsx6(Search,{size:15,className:"text-muted2 shrink-0","aria-hidden":"true"}),jsx6("input",{autoFocus:true,value:query,onChange:e=>setQuery(e.target.value),placeholder:searchPlaceholder??ui.search,"aria-label":searchPlaceholder??ui.search,className:"flex-1 min-w-0 bg-transparent border-none outline-none text-ui text-ink placeholder:text-muted2"}),query&&jsx6("button",{type:"button",onClick:()=>setQuery(""),"aria-label":ui.clearSearch,className:"shrink-0 text-muted2 hover:text-ink cursor-pointer transition-colors",children:jsx6(X2,{size:14,"aria-hidden":"true"})}),jsx6("kbd",{dir:"ltr",className:"shrink-0 px-1.5 py-0.5 rounded-xs bg-bg border border-line text-micro font-bold text-muted2",children:"Esc"})]}),jsxs6("div",{role:"listbox",className:"max-h-64 overflow-y-auto py-1",children:[results.map(o=>jsxs6("button",{type:"button",role:"option","aria-selected":o.value===value,onClick:()=>{onChange(o.value);setOpen(false)},className:cn(ITEM,o.value===value&&"bg-soft"),children:[jsxs6("span",{className:"flex-1 min-w-0 flex flex-col",children:[jsx6("span",{className:"font-bold truncate",children:o.label}),o.meta&&jsx6("span",{className:"text-caption text-muted",children:o.meta})]}),o.value===value&&jsx6(Check,{size:14,className:"text-brand-ink shrink-0","aria-hidden":"true"})]},o.value)),results.length===0&&jsx6("span",{className:"block px-3 py-6 text-center text-ui text-muted2",children:emptyText??ui.noResults})]})]})]})]})}function MultiSelect({label,values,onChange,options,placeholder,createLabel,onCreate,className}){const ui=useUIText();const id=useId2();const[open,setOpen]=useState3(false);const[query,setQuery]=useState3("");const ref=useDismiss(open,()=>setOpen(false));const results=useMemo(()=>{const q=query.trim();if(!q)return options;return options.filter(o=>o.label.includes(q))},[options,query]);const exact=results.some(o=>o.label===query.trim());const canCreate=Boolean(onCreate&&query.trim()&&!exact);function toggle(v){onChange(values.includes(v)?values.filter(x=>x!==v):[...values,v])}return jsxs6("div",{className:cn("flex flex-col gap-1.5",className),children:[jsxs6("div",{className:"flex items-center justify-between gap-3",children:[jsx6(Label,{id,children:label}),values.length>0&&jsx6("button",{type:"button",onClick:()=>onChange([]),className:"text-caption font-bold text-muted cursor-pointer hover:text-ink transition-colors",children:"\u0645\u0633\u062D \u0627\u0644\u0643\u0644"})]}),jsxs6("div",{ref,className:"relative",children:[jsxs6("button",{id,type:"button","aria-haspopup":"listbox","aria-expanded":open,onClick:()=>setOpen(v=>!v),className:cn(TRIGGER,"h-auto min-h-10 py-1.5 flex-wrap",open?"border-brand":"border-border hover:border-brand"),children:[values.length===0&&jsx6("span",{className:"text-muted2 flex-1 text-start",children:placeholder??ui.select}),values.map(v=>{const o=options.find(x=>x.value===v);return jsxs6("span",{className:"inline-flex items-center gap-1 h-7 ps-2.5 pe-1.5 rounded-full bg-soft text-brand-ink text-caption font-bold",children:[o?.label??v,jsx6("button",{type:"button","aria-label":`\u0625\u0632\u0627\u0644\u0629 ${o?.label??v}`,onClick:e=>{e.stopPropagation();toggle(v)},className:"flex text-brand-ink/60 hover:text-brand-ink cursor-pointer",children:jsx6(X2,{size:12,strokeWidth:2.5,"aria-hidden":"true"})})]},v)}),jsx6(ChevronDown,{size:15,"aria-hidden":"true",className:cn("text-muted2 shrink-0 ms-auto transition-transform",open&&"rotate-180")})]}),open&&jsxs6("div",{className:PANEL,children:[jsxs6("div",{className:"flex items-center gap-2.5 px-3 h-11 border-b border-line",children:[jsx6(Search,{size:15,className:"text-muted2 shrink-0","aria-hidden":"true"}),jsx6("input",{autoFocus:true,value:query,onChange:e=>setQuery(e.target.value),placeholder:ui.searchOrAdd,"aria-label":ui.searchOrAdd,className:"flex-1 min-w-0 bg-transparent border-none outline-none text-ui text-ink placeholder:text-muted2"})]}),jsxs6("div",{role:"listbox","aria-multiselectable":true,className:"max-h-56 overflow-y-auto py-1",children:[results.map(o=>{const on=values.includes(o.value);return jsxs6("button",{type:"button",role:"option","aria-selected":on,onClick:()=>toggle(o.value),className:ITEM,children:[jsx6("span",{"aria-hidden":"true",className:cn("size-[18px] rounded-xs border-[1.5px] flex items-center justify-center shrink-0 transition-colors",on?"bg-brand border-brand":"bg-surface border-border"),children:jsx6(Check,{size:11,strokeWidth:3,className:cn("text-white",!on&&"opacity-0")})}),jsx6("span",{className:"flex-1 min-w-0 truncate",children:o.label}),o.meta&&jsx6("span",{className:"text-caption text-muted2 shrink-0",children:o.meta})]},o.value)}),canCreate&&jsxs6("button",{type:"button",onClick:()=>{onCreate?.(query.trim());setQuery("")},className:cn(ITEM,"text-brand-ink font-bold border-t border-line mt-1 pt-3"),children:[jsx6(Plus2,{size:14,"aria-hidden":"true",className:"shrink-0"}),createLabel?createLabel(query.trim()):`\u0623\u0636\u0641 \xAB${query.trim()}\xBB`]}),results.length===0&&!canCreate&&jsx6("span",{className:"block px-3 py-6 text-center text-ui text-muted2",children:ui.noResults})]})]})]})]})}function CommandPalette({open,onClose,items,placeholder,emptyText}){const ui=useUIText();const[query,setQuery]=useState3("");useEffect3(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);const groups=useMemo(()=>{const q=query.trim();const hits=q?items.filter(i=>i.title.includes(q)||i.meta?.includes(q)):items;const out=new Map;for(const i of hits)out.set(i.group,[...out.get(i.group)??[],i]);return[...out.entries()]},[items,query]);if(!open)return null;return jsxs6("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[12vh] px-4",role:"dialog","aria-modal":"true",children:[jsx6("button",{type:"button","aria-label":ui.close,onClick:onClose,className:"absolute inset-0 bg-black/40 backdrop-blur-[2px] cursor-default"}),jsxs6("div",{className:"relative w-full max-w-[560px] bg-surface border border-line rounded-lg shadow-modal overflow-clip animate-[fade-in_.16s_ease-out]",children:[jsxs6("div",{className:"flex items-center gap-3 px-4 h-14 border-b border-line",children:[jsx6(Search,{size:17,className:"text-muted2 shrink-0","aria-hidden":"true"}),jsx6("input",{autoFocus:true,value:query,onChange:e=>setQuery(e.target.value),placeholder:placeholder??ui.searchEverything,"aria-label":placeholder??ui.searchEverything,className:"flex-1 min-w-0 bg-transparent border-none outline-none text-body text-ink placeholder:text-muted2"}),jsx6("kbd",{dir:"ltr",className:"shrink-0 px-1.5 py-0.5 rounded-xs bg-bg border border-line text-micro font-bold text-muted2",children:"Esc"})]}),jsxs6("div",{className:"max-h-[52vh] overflow-y-auto py-2",children:[groups.map(([group2,list])=>jsxs6("div",{className:"flex flex-col",children:[jsx6("span",{className:"px-4 pt-2 pb-1 text-micro font-extrabold text-muted2 tracking-wide",children:group2}),list.map(i=>jsxs6("button",{type:"button",onClick:()=>{i.onRun?.();onClose()},className:"px-4 py-2.5 flex items-center gap-3 text-start cursor-pointer transition-colors hover:bg-hover",children:[i.icon&&jsx6("span",{className:"text-muted shrink-0",children:i.icon}),jsx6("span",{className:"flex-1 min-w-0 text-body font-bold text-ink truncate",children:i.title}),i.meta&&jsx6("span",{className:"text-caption text-muted2 shrink-0",children:i.meta})]},i.id))]},group2)),groups.length===0&&jsx6("span",{className:"block px-4 py-10 text-center text-ui text-muted2",children:emptyText??ui.noResults})]})]})]})}import{useState as useState4}from"react";import{Check as Check2,ChevronDown as ChevronDown2}from"lucide-react";import{Fragment,jsx as jsx7,jsxs as jsxs7}from"react/jsx-runtime";function Accordion({items,mode="single",defaultOpen=[],className}){const[open,setOpen]=useState4(defaultOpen);function toggle(key){setOpen(prev=>{if(prev.includes(key))return prev.filter(k=>k!==key);return mode==="single"?[key]:[...prev,key]})}return jsx7("div",{className:cn("bg-surface border border-line rounded-card overflow-clip",className),children:items.map(it=>{const on=open.includes(it.key);return jsxs7("div",{className:"border-b border-line last:border-0",children:[jsxs7("button",{type:"button","aria-expanded":on,onClick:()=>toggle(it.key),className:"w-full px-4 py-3.5 flex items-center gap-3 text-start cursor-pointer transition-colors hover:bg-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",children:[it.icon&&jsx7("span",{"aria-hidden":"true",className:"size-8 rounded-sm bg-soft text-brand-ink flex items-center justify-center shrink-0",children:jsx7(it.icon,{size:15})}),jsxs7("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[jsx7("span",{className:"text-body font-extrabold text-ink",children:it.title}),it.description&&jsx7("span",{className:"text-caption text-muted",children:it.description})]}),jsx7(ChevronDown2,{size:16,"aria-hidden":"true",className:cn("text-muted2 shrink-0 transition-transform duration-200",on&&"rotate-180")})]}),jsx7("div",{className:cn("grid transition-[grid-template-rows] duration-200 ease-out",on?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx7("div",{className:"overflow-clip",children:jsx7("div",{className:"px-4 pb-4 pt-0.5 text-ui leading-[1.85] text-ink2",children:it.children})})})]},it.key)})})}function Timeline({steps,current,nowLabel,className}){const ui=useUIText();return jsx7("ol",{className:cn("flex flex-col m-0 p-0 list-none",className),children:steps.map((s,i)=>{const done=i<current;const active=i===current;const last=i===steps.length-1;return jsxs7("li",{className:"flex gap-3",children:[jsxs7("span",{className:"flex flex-col items-center shrink-0",children:[jsx7("span",{"aria-hidden":"true",className:cn("size-7 rounded-full flex items-center justify-center border-2 transition-colors",done&&"bg-brand border-brand text-white",active&&"bg-surface border-brand text-brand-ink",!done&&!active&&"bg-surface border-border text-muted2"),children:done?jsx7(Check2,{size:14,strokeWidth:3}):jsx7("span",{className:cn("size-2 rounded-full",active?"bg-brand":"bg-border")})}),!last&&jsx7("span",{"aria-hidden":"true",className:cn("w-0.5 flex-1 min-h-8 transition-colors",done?"bg-brand":"bg-line")})]}),jsxs7("span",{className:cn("flex flex-col gap-0.5 min-w-0",last?"pb-0":"pb-5"),children:[jsxs7("span",{className:"flex items-center gap-2.5 flex-wrap",children:[jsx7("span",{className:cn("text-body font-extrabold",done||active?"text-ink":"text-muted2"),children:s.title}),s.time&&jsx7("span",{"data-num":true,className:"text-micro text-muted2",children:s.time}),active&&jsx7("span",{className:cn("px-2 py-0.5 rounded-full text-micro font-extrabold",TONE_SOFT[s.tone??"brand"]),children:nowLabel??ui.now})]}),s.note&&jsx7("span",{className:"text-caption leading-[1.7] text-muted",children:s.note})]})]},s.key)})})}function Stepper({steps,done,onPick,className}){return jsx7("ol",{className:cn("flex items-start gap-1 m-0 p-0 list-none",className),children:steps.map((s,i)=>{const on=done.includes(s.key);const isCurrent=!on&&steps.slice(0,i).every(x=>done.includes(x.key));const last=i===steps.length-1;const Tag=onPick?"button":"div";return jsxs7("li",{className:"flex-1 flex flex-col items-center gap-2 min-w-0",children:[jsxs7("span",{className:"w-full flex items-center gap-1",children:[jsx7("span",{"aria-hidden":"true",className:cn("h-0.5 flex-1 rounded-full",i===0?"bg-transparent":on?"bg-brand":"bg-line")}),jsx7(Tag,{...onPick?{type:"button",onClick:()=>onPick(s.key)}:{},"aria-current":isCurrent?"step":void 0,className:cn("size-8 rounded-full flex items-center justify-center shrink-0 border-2 transition-colors",on?"bg-brand border-brand text-white":"bg-surface border-border text-muted",onPick&&"cursor-pointer hover:border-brand"),children:on?jsxs7(Fragment,{children:[jsx7(Check2,{size:15,strokeWidth:3,"aria-hidden":"true"}),jsx7("span",{className:"sr-only",children:"\u0645\u0643\u062A\u0645\u0644\u0629"})]}):jsx7("span",{"data-num":true,className:"text-caption font-extrabold",children:i+1})}),jsx7("span",{"aria-hidden":"true",className:cn("h-0.5 flex-1 rounded-full",last?"bg-transparent":on?"bg-brand":"bg-line")})]}),jsx7("span",{className:cn("text-caption font-bold text-center leading-tight [text-wrap:balance]",on?"text-ink":"text-muted"),children:s.title})]},s.key)})})}import{Star}from"lucide-react";import{jsx as jsx8,jsxs as jsxs8}from"react/jsx-runtime";var MAX=5;function Stars({value,size=13,className}){const n=Math.max(0,Math.min(MAX,Math.round(value)));return jsxs8("span",{className:cn("flex items-center gap-0.5 shrink-0",className),children:[jsx8("span",{className:"sr-only",children:`${n} / ${MAX}`}),Array.from({length:MAX},(_,i)=>jsx8(Star,{size,"aria-hidden":"true",className:cn("shrink-0",i<n?"fill-amber text-amber":"text-muted2")},i))]})}function RatingInput({value,onChange,disabled,hideValue,className}){const ui=useUIText();return jsxs8("span",{className:cn("flex items-center gap-1",className),children:[Array.from({length:MAX},(_,i)=>{const n=i+1;return jsx8("button",{type:"button",disabled,"aria-pressed":value===n,"aria-label":`${n} / ${MAX} \u2014 ${ui.rating}`,onClick:()=>onChange(n),className:cn("size-9 rounded-sm flex items-center justify-center transition-colors","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",disabled?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-hover"),children:jsx8(Star,{size:22,"aria-hidden":"true",className:cn("shrink-0",n<=value?"fill-amber text-amber":"text-muted2")})},n)}),!hideValue&&value>0&&jsx8("span",{"data-numeric":true,className:"ms-2 text-caption font-bold text-muted",children:`${value}/${MAX}`})]})}import{useMemo as useMemo2,useState as useState5}from"react";import{ChevronLeft,ChevronRight}from"lucide-react";import{jsx as jsx9,jsxs as jsxs9}from"react/jsx-runtime";var MONTHS_AR=["\u064A\u0646\u0627\u064A\u0631","\u0641\u0628\u0631\u0627\u064A\u0631","\u0645\u0627\u0631\u0633","\u0623\u0628\u0631\u064A\u0644","\u0645\u0627\u064A\u0648","\u064A\u0648\u0646\u064A\u0648","\u064A\u0648\u0644\u064A\u0648","\u0623\u063A\u0633\u0637\u0633","\u0633\u0628\u062A\u0645\u0628\u0631","\u0623\u0643\u062A\u0648\u0628\u0631","\u0646\u0648\u0641\u0645\u0628\u0631","\u062F\u064A\u0633\u0645\u0628\u0631"];var WEEKDAYS_AR=["\u0633","\u062D","\u0646","\u062B","\u0631","\u062E","\u062C"];var weekIndex=d=>(d.getDay()+1)%7;var sameDay=(a,b)=>a.getFullYear()===b.getFullYear()&&a.getMonth()===b.getMonth()&&a.getDate()===b.getDate();var startOfDay=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate());function daysBetween(from,to){return Math.round((startOfDay(to).getTime()-startOfDay(from).getTime())/864e5)+1}function formatDate(d){return`${d.getDate()} ${MONTHS_AR[d.getMonth()]}`}function formatRange(r){if(!r.from)return"\u0627\u062E\u062A\u0631 \u064A\u0648\u0645 \u0627\u0644\u0628\u062F\u0627\u064A\u0629";if(!r.to)return`${formatDate(r.from)} \u2014 \u0627\u062E\u062A\u0631 \u064A\u0648\u0645 \u0627\u0644\u0646\u0647\u0627\u064A\u0629`;if(sameDay(r.from,r.to))return formatDate(r.from);return`${formatDate(r.from)} \u2014 ${formatDate(r.to)}`}function presets(today){const mk=backDays=>{const to=startOfDay(today);const from=new Date(to);from.setDate(from.getDate()-backDays+1);return{from,to}};return[{key:"today",label:"\u0627\u0644\u0646\u0647\u0627\u0631\u062F\u0647",range:mk(1)},{key:"d7",label:"\u0622\u062E\u0631 \u0667 \u0623\u064A\u0627\u0645",range:mk(7)},{key:"d30",label:"\u0622\u062E\u0631 \u0663\u0660 \u064A\u0648\u0645",range:mk(30)},{key:"month",label:"\u0627\u0644\u0634\u0647\u0631 \u062F\u0647",range:{from:new Date(today.getFullYear(),today.getMonth(),1),to:startOfDay(today)}}]}function DateRangePicker({value,onChange,month,onMonthChange,today,className}){const ui=useUIText();const[hover,setHover]=useState5(null);const cells=useMemo2(()=>{const first=new Date(month.getFullYear(),month.getMonth(),1);const total=new Date(month.getFullYear(),month.getMonth()+1,0).getDate();const pad=weekIndex(first);return[...Array.from({length:pad},()=>null),...Array.from({length:total},(_,i)=>new Date(month.getFullYear(),month.getMonth(),i+1))]},[month]);const provisionalTo=value.from&&!value.to?hover:value.to;function inRange(d){if(!value.from||!provisionalTo)return false;const[a,b]=value.from<=provisionalTo?[value.from,provisionalTo]:[provisionalTo,value.from];return d>=startOfDay(a)&&d<=startOfDay(b)}function pick(d){if(!value.from||value.to)return onChange({from:d,to:null});if(d<value.from)return onChange({from:d,to:value.from});onChange({from:value.from,to:d})}const shift=by=>onMonthChange(new Date(month.getFullYear(),month.getMonth()+by,1));return jsxs9("div",{className:cn("flex flex-col gap-3",className),children:[jsxs9("div",{className:"flex items-center justify-between gap-3",children:[jsx9("button",{type:"button",onClick:()=>shift(-1),"aria-label":ui.previousMonth,className:"size-8 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx9(ChevronRight,{size:16,"aria-hidden":"true"})}),jsxs9("span",{className:"text-body font-extrabold text-ink",children:[MONTHS_AR[month.getMonth()]," ",jsx9("span",{"data-num":true,children:month.getFullYear()})]}),jsx9("button",{type:"button",onClick:()=>shift(1),"aria-label":ui.nextMonth,className:"size-8 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx9(ChevronLeft,{size:16,"aria-hidden":"true"})})]}),jsxs9("div",{className:"grid grid-cols-7 gap-0.5",role:"grid",children:[WEEKDAYS_AR.map((w,i)=>jsx9("span",{className:"h-7 flex items-center justify-center text-micro font-bold text-muted2",children:w},i)),cells.map((d,i)=>{if(!d)return jsx9("span",{},`p${i}`);const isFrom=value.from&&sameDay(d,value.from);const isTo=provisionalTo&&sameDay(d,provisionalTo);const edge=isFrom||isTo;const mid=inRange(d)&&!edge;const isToday=sameDay(d,today);return jsxs9("button",{type:"button",onClick:()=>pick(d),onMouseEnter:()=>setHover(d),"aria-pressed":Boolean(edge||mid),className:cn("h-9 flex items-center justify-center text-ui font-bold cursor-pointer transition-colors relative",mid&&"bg-soft text-brand-ink rounded-none",edge&&"bg-brand text-white rounded-sm z-10",!edge&&!mid&&"text-ink2 rounded-sm hover:bg-hover",isToday&&!edge&&"text-brand-ink"),children:[jsx9("span",{"data-num":true,children:d.getDate()}),isToday&&!edge&&jsx9("span",{"aria-hidden":"true",className:"absolute bottom-1 size-1 rounded-full bg-brand"})]},d.toISOString())})]})]})}import{useRef as useRef4,useState as useState6}from"react";import{AlertCircle,Check as Check3,Image as ImageIcon,Loader2 as Loader22,UploadCloud,X as X3}from"lucide-react";import{jsx as jsx10,jsxs as jsxs10}from"react/jsx-runtime";function formatBytes(bytes){if(bytes<1024)return`${bytes} \u0628\u0627\u064A\u062A`;if(bytes<1024*1024)return`${Math.round(bytes/1024)} \u0643.\u0628`;return`${(bytes/(1024*1024)).toFixed(1)} \u0645\u064A\u062C\u0627`}function Dropzone({onFiles,accept="image/*",multiple=true,disabled,title,hint,buttonLabel,className}){const ui=useUIText();const input=useRef4(null);const[over,setOver]=useState6(false);function take(list){if(!list||disabled)return;onFiles(Array.from(list))}function onDrop(e){e.preventDefault();setOver(false);take(e.dataTransfer.files)}return jsxs10("div",{onDragOver:e=>{e.preventDefault();if(!disabled)setOver(true)},onDragLeave:()=>setOver(false),onDrop,className:cn("flex flex-col items-center justify-center gap-2.5 px-5 py-9 rounded-card border-2 border-dashed transition-colors text-center",disabled&&"opacity-55 cursor-not-allowed border-border bg-bg",!disabled&&over&&"border-brand bg-soft",!disabled&&!over&&"border-border bg-bg hover:border-brand",className),children:[jsx10("span",{"aria-hidden":"true",className:cn("size-12 rounded-card flex items-center justify-center transition-colors",over?"bg-brand text-white":"bg-surface text-muted border border-line"),children:jsx10(UploadCloud,{size:22,strokeWidth:1.8})}),jsx10("span",{className:"text-body font-extrabold text-ink",children:title??ui.dropImages}),hint&&jsx10("span",{className:"text-caption leading-[1.7] text-muted max-w-note",children:hint}),jsx10("button",{type:"button",disabled,onClick:()=>input.current?.click(),className:"mt-1 h-9 px-4 rounded-sm bg-surface border border-border text-ui font-bold text-ink2 cursor-pointer transition-colors hover:border-brand hover:text-brand-ink disabled:cursor-not-allowed",children:buttonLabel??ui.chooseFromDevice}),jsx10("input",{ref:input,type:"file",accept,multiple,hidden:true,onChange:e=>{take(e.target.files);e.target.value=""}})]})}var STATE_STYLE={uploading:{box:"bg-soft text-brand-ink",icon:jsx10(Loader22,{size:13,className:"animate-spin","aria-hidden":"true"}),label:"\u062C\u0627\u0631\u064A \u0627\u0644\u0631\u0641\u0639"},done:{box:"bg-green-bg2 text-green",icon:jsx10(Check3,{size:13,"aria-hidden":"true"}),label:"\u062A\u0645 \u0627\u0644\u0631\u0641\u0639"},rejected:{box:"bg-red-bg text-red",icon:jsx10(AlertCircle,{size:13,"aria-hidden":"true"}),label:"\u0645\u0631\u0641\u0648\u0636"}};function FileRow({file,onRemove,coverLabel,isCover}){const s=STATE_STYLE[file.state];return jsxs10("div",{className:"flex items-center gap-3 p-2.5 rounded-card border border-line bg-surface",children:[jsxs10("span",{className:"relative size-11 rounded-sm overflow-clip bg-hover border border-line shrink-0",children:[file.preview?jsx10("img",{src:file.preview,alt:"",className:"w-full h-full object-cover"}):jsx10("span",{className:"w-full h-full flex items-center justify-center text-muted2",children:jsx10(ImageIcon,{size:17,"aria-hidden":"true"})}),isCover&&coverLabel&&jsx10("span",{className:"absolute inset-x-0 bottom-0 bg-brand/90 text-white text-micro font-extrabold text-center py-px",children:coverLabel})]}),jsxs10("span",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[jsxs10("span",{className:"flex items-center gap-2 min-w-0",children:[jsx10("span",{dir:"auto",className:"text-ui font-bold text-ink truncate",children:file.name}),jsxs10("span",{className:cn("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-micro font-extrabold shrink-0",s.box),children:[s.icon,s.label]})]}),file.state==="uploading"?jsx10("span",{className:"h-1 rounded-full bg-hover overflow-clip block",children:jsx10("span",{className:"block h-full rounded-full bg-brand transition-[width] duration-200",style:{width:`${file.progress??0}%`}})}):jsx10("span",{className:cn("text-caption",file.state==="rejected"?"text-red":"text-muted"),children:file.state==="rejected"?file.error:formatBytes(file.size)})]}),onRemove&&jsx10("button",{type:"button",onClick:onRemove,"aria-label":`\u0625\u0632\u0627\u0644\u0629 ${file.name}`,className:"shrink-0 size-8 rounded-sm flex items-center justify-center text-muted2 cursor-pointer transition-colors hover:bg-hover hover:text-red",children:jsx10(X3,{size:15,"aria-hidden":"true"})})]})}import{useCallback as useCallback2,useEffect as useEffect4,useLayoutEffect,useRef as useRef5,useState as useState7}from"react";import{jsx as jsx11}from"react/jsx-runtime";function reducedMotion(){return typeof window!=="undefined"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function useSortable({count,onMove,disabled,threshold=4,itemLabel}){const ui=useUIText();const nodes=useRef5([]);const rects=useRef5([]);const[dragging,setDragging]=useState7(null);const[over,setOver]=useState7(null);const[grabbed,setGrabbed]=useState7(null);const[message,setMessage]=useState7("");const run=useRef5({active:false,from:0,to:0,startY:0,dy:0,slot:0,raf:0,pointerId:-1});const overRef=useRef5(null);useEffect4(()=>{overRef.current=over},[over]);const detach=useRef5(null);const finishRef=useRef5(()=>{});const countRef=useRef5(count);useEffect4(()=>{countRef.current=count},[count]);const soft=!reducedMotion();const EASE="cubic-bezier(.2,.8,.2,1)";const measure=useCallback2(()=>{const list=nodes.current.slice(0,count);rects.current=list.map(el=>{const r=el?.getBoundingClientRect();return{top:r?.top??0,height:r?.height??0}});const gap=rects.current.length>1?Math.max(0,rects.current[1].top-(rects.current[0].top+rects.current[0].height)):0;return gap},[count]);const finish=useCallback2(()=>{const s=run.current;if(!s.active)return;s.active=false;cancelAnimationFrame(s.raf);detach.current?.();detach.current=null;const from=s.from;const to=overRef.current??from;const el=nodes.current[from];const settle=()=>{setDragging(null);setOver(null);overRef.current=null;if(el){el.style.transition="";el.style.removeProperty("--drag-y")}if(to!==from){onMove(from,to);setMessage(`${itemLabel?.(from)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0627\u0646\u062A\u0642\u0644 \u0625\u0644\u0649 \u0627\u0644\u0645\u0648\u0636\u0639 ${to+1} \u0645\u0646 ${count}.`)}};if(!el||!soft||to===from)return settle();const r=rects.current;const target=to>from?r[to].top+r[to].height-(r[from].top+r[from].height):r[to].top-r[from].top;el.style.transition=`transform 190ms ${EASE}`;el.style.setProperty("--drag-y",`${target}px`);window.setTimeout(settle,200)},[count,itemLabel,onMove,soft]);useEffect4(()=>{finishRef.current=finish},[finish]);const attach=useCallback2(()=>{function onPointerMove(e){const s=run.current;if(!s.active||e.pointerId!==s.pointerId)return;s.dy=e.clientY-s.startY;const r=rects.current;const n=countRef.current;const center=r[s.from].top+r[s.from].height/2+s.dy;let next=s.from;if(s.dy>0){for(let i=s.from+1;i<n;i++){if(center>r[i].top+r[i].height/2)next=i}}else{for(let i=s.from-1;i>=0;i--){if(center<r[i].top+r[i].height/2)next=i}}if(next!==overRef.current){overRef.current=next;setOver(next)}cancelAnimationFrame(s.raf);s.raf=requestAnimationFrame(()=>{nodes.current[s.from]?.style.setProperty("--drag-y",`${s.dy}px`)})}function onUp(e){if(e.pointerId!==run.current.pointerId)return;finishRef.current()}function onKey(e){if(e.key==="Escape"){overRef.current=run.current.from;finishRef.current()}}window.addEventListener("pointermove",onPointerMove,{passive:true});window.addEventListener("pointerup",onUp);window.addEventListener("pointercancel",onUp);window.addEventListener("keydown",onKey);detach.current=()=>{window.removeEventListener("pointermove",onPointerMove);window.removeEventListener("pointerup",onUp);window.removeEventListener("pointercancel",onUp);window.removeEventListener("keydown",onKey)}},[]);useEffect4(()=>()=>detach.current?.(),[]);useLayoutEffect(()=>{if(grabbed!==null)nodes.current[grabbed]?.focus()},[grabbed]);const item=useCallback2(index=>{const isDragged=dragging===index;const isGrabbed=grabbed===index;let shift=0;if(dragging!==null&&over!==null&&!isDragged){const slot=run.current.slot;if(over>dragging&&index>dragging&&index<=over)shift=-slot;else if(over<dragging&&index>=over&&index<dragging)shift=slot}const style=isDragged?{transform:"translate3d(0, var(--drag-y, 0px), 0)",position:"relative",zIndex:20,cursor:"grabbing",touchAction:"none",willChange:"transform"}:{transform:shift?`translate3d(0, ${shift}px, 0)`:void 0,transition:dragging!==null&&soft?`transform 160ms ${EASE}`:void 0,touchAction:disabled?void 0:"none"};return{ref:el=>{nodes.current[index]=el},style,tabIndex:disabled?-1:0,"aria-roledescription":ui.grabHint,"data-dragging":isDragged?"":void 0,"data-grabbed":isGrabbed?"":void 0,onPointerDown:e=>{if(disabled||e.button!==0)return;const startY=e.clientY;const el=e.currentTarget;const begin=ev=>{if(Math.abs(ev.clientY-startY)<threshold)return;window.removeEventListener("pointermove",begin);const gap=measure();const s=run.current;s.active=true;s.from=index;s.startY=startY;s.dy=ev.clientY-startY;s.slot=rects.current[index].height+gap;s.pointerId=ev.pointerId;el.setPointerCapture?.(ev.pointerId);el.style.setProperty("--drag-y",`${s.dy}px`);overRef.current=index;attach();setOver(index);setDragging(index);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0642\u064A\u062F \u0627\u0644\u062A\u062D\u0631\u064A\u0643.`)};const stop=()=>{window.removeEventListener("pointermove",begin);window.removeEventListener("pointerup",stop)};window.addEventListener("pointermove",begin);window.addEventListener("pointerup",stop)},onKeyDown:e=>{if(disabled)return;if(e.key===" "||e.key==="Enter"){e.preventDefault();if(grabbed===index){setGrabbed(null);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0627\u0633\u062A\u0642\u0631\u0651 \u0641\u064A \u0627\u0644\u0645\u0648\u0636\u0639 ${index+1}.`)}else{setGrabbed(index);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0645\u0645\u0633\u0648\u0643. \u062D\u0631\u0651\u0643\u0647 \u0628\u0627\u0644\u0623\u0633\u0647\u0645.`)}return}if(grabbed!==index)return;const dir=e.key==="ArrowUp"?-1:e.key==="ArrowDown"?1:0;if(dir){e.preventDefault();const to=index+dir;if(to<0||to>=count)return;onMove(index,to);setGrabbed(to);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0641\u064A \u0627\u0644\u0645\u0648\u0636\u0639 ${to+1} \u0645\u0646 ${count}.`)}if(e.key==="Escape"){e.preventDefault();setGrabbed(null);setMessage("\u0623\u064F\u0644\u063A\u064A \u0627\u0644\u062A\u062D\u0631\u064A\u0643.")}}}},[attach,count,disabled,dragging,grabbed,itemLabel,measure,onMove,over,soft,threshold,ui.grabHint]);return{item,dragging,grabbed,over,message}}function SortableStatus({message}){return jsx11("span",{role:"status","aria-live":"polite",className:"sr-only",children:message})}import{Children,useCallback as useCallback3,useEffect as useEffect5,useRef as useRef6,useState as useState8}from"react";import{ChevronLeft as ChevronLeft2,ChevronRight as ChevronRight2,Pause,Play,X as X4,ZoomIn}from"lucide-react";import{jsx as jsx12,jsxs as jsxs11}from"react/jsx-runtime";function axis(track){const rtl=getComputedStyle(track).direction==="rtl";return{rtl,start:r=>rtl?-r.right:r.left,end:r=>rtl?-r.left:r.right}}var EDGE=1;function readTrack(track){const slides=Array.from(track.children);if(slides.length===0)return{index:0,atStart:true,atEnd:true};const{start,end}=axis(track);const box=track.getBoundingClientRect();const from=start(box);let index=0;let best=Infinity;slides.forEach((el,i)=>{const d=start(el.getBoundingClientRect())-from;const score=d<0?-d:d;if(score<best){best=score;index=i}});return{index,atStart:start(slides[0].getBoundingClientRect())>=from-EDGE,atEnd:end(slides[slides.length-1].getBoundingClientRect())<=end(box)+EDGE}}function scrollToIndex(track,i,behavior){const el=track.children[i];if(!el)return;const{rtl}=axis(track);const box=track.getBoundingClientRect();const r=el.getBoundingClientRect();track.scrollBy({left:rtl?r.right-box.right:r.left-box.left,behavior})}function ease(){return typeof matchMedia!=="undefined"&&matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"}var BASIS="calc((100% - (var(--per) - 1) * var(--gap)) / var(--per))";function Carousel({label,children,perView,gap=12,arrows=true,dots=false,counter=false,autoplay,index,onIndexChange,className,trackClassName}){const en=useMoneyLang();const trackRef=useRef6(null);const[state,setState]=useState8({index:0,atStart:true,atEnd:true});const[paused,setPaused]=useState8(false);const[held,setHeld]=useState8(false);const slides=Children.toArray(children);const count=slides.length;const latest=useRef6(state);const notify=useRef6(onIndexChange);useEffect5(()=>{latest.current=state},[state]);useEffect5(()=>{notify.current=onIndexChange},[onIndexChange]);const measure=useCallback3(()=>{const track=trackRef.current;if(!track)return;const next=readTrack(track);setState(prev=>prev.index===next.index&&prev.atStart===next.atStart&&prev.atEnd===next.atEnd?prev:next)},[]);const target=useRef6(0);const go=useCallback3(to=>{const track=trackRef.current;if(!track)return;const i=Math.min(Math.max(to,0),track.children.length-1);target.current=i;scrollToIndex(track,i,ease())},[]);const first=useRef6(true);const told=useRef6(null);useEffect5(()=>{const track=trackRef.current;if(index==null||!track)return;if(index===told.current)return;target.current=index;scrollToIndex(track,index,first.current?"auto":ease())},[index]);useEffect5(()=>{const track=trackRef.current;if(!track)return;let frame=0;let idle;const onScroll=()=>{cancelAnimationFrame(frame);frame=requestAnimationFrame(measure);clearTimeout(idle);idle=setTimeout(()=>{const t=trackRef.current;if(t)target.current=readTrack(t).index},140)};track.addEventListener("scroll",onScroll,{passive:true});const ro=new ResizeObserver(onScroll);ro.observe(track);measure();first.current=false;return()=>{cancelAnimationFrame(frame);clearTimeout(idle);track.removeEventListener("scroll",onScroll);ro.disconnect()}},[measure,count]);useEffect5(()=>{if(told.current===state.index)return;const knew=told.current!==null;told.current=state.index;if(knew||state.index!==(index??0))notify.current?.(state.index)},[state.index,index]);useEffect5(()=>{if(!autoplay||paused||held||count<2)return;if(typeof matchMedia!=="undefined"&&matchMedia("(prefers-reduced-motion: reduce)").matches){return}const id=setInterval(()=>{const track=trackRef.current;if(!track||document.hidden)return;const now=latest.current;scrollToIndex(track,now.atEnd?0:now.index+1,ease())},autoplay);return()=>clearInterval(id)},[autoplay,paused,held,count]);function onKeyDown(e){const track=trackRef.current;if(!track)return;const{rtl}=axis(track);const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";const to=e.key===forward?target.current+1:e.key===back?target.current-1:e.key==="Home"?0:e.key==="End"?count-1:null;if(to===null)return;e.preventDefault();go(to)}const many=count>1;const showArrows=arrows&&many;const showBar=many&&(dots||counter||Boolean(autoplay));const arrow=back=>jsx12("button",{type:"button",disabled:back?state.atStart:state.atEnd,"aria-label":back?en?"Previous":"\u0627\u0644\u0633\u0627\u0628\u0642":en?"Next":"\u0627\u0644\u062A\u0627\u0644\u064A",onClick:()=>go(back?target.current-1:target.current+1),className:cn("absolute top-1/2 -translate-y-1/2 z-10 size-9 rounded-full flex items-center justify-center","bg-surface/92 backdrop-blur border border-line shadow-pop text-ink2","transition-opacity cursor-pointer hover:text-brand-ink","disabled:opacity-0 disabled:pointer-events-none",back?"start-2":"end-2"),children:back?jsx12(ChevronRight2,{size:17,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"}):jsx12(ChevronLeft2,{size:17,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"})});return jsxs11("section",{"aria-roledescription":en?"carousel":"\u0639\u0627\u0631\u0636 \u0634\u0631\u0627\u0626\u062D","aria-label":label,onPointerEnter:()=>autoplay&&setHeld(true),onPointerLeave:()=>autoplay&&setHeld(false),onFocusCapture:()=>autoplay&&setHeld(true),onBlurCapture:()=>autoplay&&setHeld(false),className:cn("flex flex-col gap-3 [--per:1]",className),style:{"--gap":`${gap}px`,...perView===void 0?null:{"--per":String(perView)}},children:[jsxs11("div",{className:"relative",children:[jsx12("div",{ref:trackRef,tabIndex:0,role:"group","aria-label":en?"Slides":"\u0627\u0644\u0634\u0631\u0627\u0626\u062D",onKeyDown,className:cn("flex overflow-x-auto overscroll-x-contain snap-x snap-mandatory","[scrollbar-width:none] [&::-webkit-scrollbar]:hidden","rounded-card focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",trackClassName),style:{gap:"var(--gap)"},children:slides.map((slide,i)=>jsx12("div",{role:"group","aria-roledescription":en?"slide":"\u0634\u0631\u064A\u062D\u0629","aria-label":en?`${i+1} of ${count}`:`${i+1} \u0645\u0646 ${count}`,className:"snap-start shrink-0 grow-0 min-w-0 relative",style:{flexBasis:BASIS},children:slide},i))}),showArrows&&arrow(true),showArrows&&arrow(false)]}),showBar&&jsxs11("div",{className:"flex items-center justify-center gap-3",children:[autoplay&&jsx12("button",{type:"button",onClick:()=>setPaused(p=>!p),"aria-label":paused?en?"Start auto-rotation":"\u0634\u063A\u0651\u0644 \u0627\u0644\u062A\u0628\u062F\u064A\u0644 \u0627\u0644\u062A\u0644\u0642\u0627\u0626\u064A":en?"Stop auto-rotation":"\u0623\u0648\u0642\u0641 \u0627\u0644\u062A\u0628\u062F\u064A\u0644 \u0627\u0644\u062A\u0644\u0642\u0627\u0626\u064A",className:"size-7 rounded-full flex items-center justify-center text-muted hover:bg-hover hover:text-ink transition-colors cursor-pointer",children:paused?jsx12(Play,{size:13,"aria-hidden":"true"}):jsx12(Pause,{size:13,"aria-hidden":"true"})}),dots&&jsx12("span",{className:"flex items-center gap-1.5",children:slides.map((_,i)=>jsx12("button",{type:"button",onClick:()=>go(i),"aria-label":en?`Go to slide ${i+1}`:`\u0627\u0630\u0647\u0628 \u0644\u0644\u0634\u0631\u064A\u062D\u0629 ${i+1}`,"aria-current":i===state.index||void 0,className:cn("h-1.5 rounded-full transition-all duration-200 cursor-pointer","before:absolute before:-inset-2 relative",i===state.index?"w-5 bg-brand":"w-1.5 bg-border hover:bg-muted2")},i))}),counter&&jsxs11("span",{dir:"ltr","data-num":true,"aria-live":autoplay?void 0:"polite",className:"text-caption font-bold text-muted tabular-nums",children:[state.index+1," / ",count]})]})]})}function Gallery({label,images,ratio="4/3",fit="cover",thumbs=true,zoom=true,className}){const en=useMoneyLang();const[index,setIndex]=useState8(0);const[open,setOpen]=useState8(false);const activeThumb=useRef6(null);useEffect5(()=>{activeThumb.current?.scrollIntoView({inline:"nearest",block:"nearest",behavior:ease()})},[index]);if(images.length===0)return null;const frame={aspectRatio:ratio};const img=(im,decorative)=>jsx12("img",{src:im.src,alt:decorative?"":im.alt,loading:"lazy",decoding:"async",draggable:false,className:cn("w-full h-full",fit==="cover"?"object-cover":"object-contain")});return jsxs11("div",{className:cn("flex flex-col gap-2.5",className),children:[jsx12(Carousel,{label,index,onIndexChange:setIndex,counter:images.length>1,dots:!thumbs&&images.length>1,gap:8,children:images.map((im,i)=>zoom?jsxs11("button",{type:"button",onClick:()=>setOpen(true),"aria-label":`${im.alt} \u2014 ${en?"open viewer":"\u0641\u062A\u062D \u0627\u0644\u0639\u0627\u0631\u0636"}`,style:frame,className:"group relative block w-full overflow-clip rounded-card bg-hover cursor-zoom-in",children:[img(im,true),jsx12("span",{"aria-hidden":"true",className:"absolute top-2 end-2 size-7 rounded-full bg-black/45 backdrop-blur text-white flex items-center justify-center opacity-70 transition-opacity group-hover:opacity-100",children:jsx12(ZoomIn,{size:14})})]},i):jsx12("div",{style:frame,className:"overflow-clip rounded-card bg-hover",children:img(im,false)},i))}),thumbs&&images.length>1&&jsx12("div",{role:"group","aria-label":en?"Thumbnails":"\u0627\u0644\u0645\u0635\u063A\u0651\u0631\u0627\u062A",className:"flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:images.map((im,i)=>jsx12("button",{ref:i===index?activeThumb:void 0,type:"button",onClick:()=>setIndex(i),"aria-current":i===index||void 0,"aria-label":en?`Image ${i+1}`:`\u0627\u0644\u0635\u0648\u0631\u0629 ${i+1}`,className:cn("shrink-0 size-14 rounded-sm overflow-clip border-2 bg-hover cursor-pointer transition-colors",i===index?"border-brand":"border-line hover:border-border"),children:jsx12("img",{src:im.src,alt:"",loading:"lazy",decoding:"async",draggable:false,className:"w-full h-full object-cover"})},i))}),zoom&&jsx12(Lightbox,{open,images,index,onIndexChange:setIndex,onClose:()=>setOpen(false),label})]})}function Lightbox({open,images,index,onIndexChange,onClose,label,closeLabel}){const ui=useUIText();const en=useMoneyLang();const panel=useRef6(null);const count=images.length;useEffect5(()=>{if(!open)return;const from=document.activeElement;panel.current?.focus();return()=>from?.focus?.()},[open]);useEffect5(()=>{if(!open)return;function onKey(e){const rtl=getComputedStyle(document.documentElement).direction==="rtl";const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";if(e.key==="Escape")onClose();else if(e.key===forward)onIndexChange(Math.min(index+1,count-1));else if(e.key===back)onIndexChange(Math.max(index-1,0));else if(e.key==="Home")onIndexChange(0);else if(e.key==="End")onIndexChange(count-1)}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,index,count,onClose,onIndexChange]);if(!open||count===0)return null;const current=images[Math.min(Math.max(index,0),count-1)];const step=back=>jsx12("button",{type:"button",disabled:back?index===0:index>=count-1,onClick:()=>onIndexChange(back?index-1:index+1),"aria-label":back?en?"Previous":"\u0627\u0644\u0633\u0627\u0628\u0642":en?"Next":"\u0627\u0644\u062A\u0627\u0644\u064A",className:cn("absolute top-1/2 -translate-y-1/2 z-10 size-11 rounded-full flex items-center justify-center","bg-white/10 backdrop-blur text-white transition-opacity cursor-pointer hover:bg-white/20","disabled:opacity-0 disabled:pointer-events-none",back?"start-3":"end-3"),children:back?jsx12(ChevronRight2,{size:20,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"}):jsx12(ChevronLeft2,{size:20,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"})});return jsxs11("div",{ref:panel,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":label??(en?"Image viewer":"\u0639\u0627\u0631\u0636 \u0627\u0644\u0635\u0648\u0631"),className:"fixed inset-0 z-50 bg-night/95 flex flex-col animate-[fade-in_0.18s_ease-out] outline-none",children:[jsxs11("header",{className:"shrink-0 h-14 px-4 flex items-center justify-between gap-3",children:[jsxs11("span",{dir:"ltr","data-num":true,className:"text-caption font-bold text-white/70 tabular-nums",children:[index+1," / ",count]}),jsx12("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:"size-9 rounded-full bg-white/10 backdrop-blur flex items-center justify-center text-white transition-colors cursor-pointer hover:bg-white/20",children:jsx12(X4,{size:18,"aria-hidden":"true"})})]}),jsxs11("div",{className:"relative flex-1 min-h-0 flex items-center justify-center p-4 pb-8",children:[jsx12("img",{src:current.src,alt:current.alt,decoding:"async",draggable:false,className:"max-w-full max-h-full object-contain rounded-card animate-qfade"},current.src),count>1&&step(true),count>1&&step(false)]})]})}import{useEffect as useEffect6,useLayoutEffect as useLayoutEffect2,useRef as useRef7,useState as useState9}from"react";import{ChevronLeft as ChevronLeft3,ChevronRight as ChevronRight3,Lock,RotateCw,Signal,Wifi}from"lucide-react";import{jsx as jsx13,jsxs as jsxs12}from"react/jsx-runtime";function BrowserFrame({url,device="desktop",tab,nav,loading,contentWidth,onScale,onReload,children,className}){const ui=useUIText();const mobile=device==="mobile";const viewport=useRef7(null);const[scale,setScale]=useState9(1);const[rtl,setRtl]=useState9(true);useLayoutEffect2(()=>{const box=viewport.current;if(!box||!contentWidth)return setScale(1);setRtl(getComputedStyle(box).direction==="rtl");const read=()=>{const w=box.clientWidth;setScale(w>0?Math.min(1,w/contentWidth):1)};read();const ro=new ResizeObserver(read);ro.observe(box);return()=>ro.disconnect()},[contentWidth]);useEffect6(()=>{onScale?.(scale)},[scale,onScale]);const control="shrink-0 size-6 rounded-full flex items-center justify-center transition-colors";return jsxs12("div",{className:cn("flex flex-col overflow-clip bg-surface border border-line shadow-panel",mobile?"rounded-[30px] border-[7px] border-night":"rounded-lg",className),children:[mobile&&jsxs12("div",{className:"shrink-0 h-7 px-5 flex items-center justify-between bg-bg","aria-hidden":"true",children:[jsxs12("span",{className:"flex items-center gap-1 text-muted2",children:[jsx13(Signal,{size:11}),jsx13(Wifi,{size:11}),jsx13("span",{className:"w-4 h-2 rounded-[2px] border border-muted2"})]}),jsx13("span",{className:"w-16 h-4 rounded-full bg-night"})]}),tab&&!mobile&&jsx13("div",{className:"shrink-0 flex items-end gap-1 px-2.5 pt-2 bg-bg border-b border-line",children:jsxs12("span",{className:"flex items-center gap-2 h-8 max-w-[220px] px-3 rounded-t-sm bg-surface border border-line border-b-0",children:[jsx13("span",{"aria-hidden":"true",className:"size-3 rounded-[3px] bg-soft2 shrink-0"}),jsx13("span",{className:"text-micro text-ink2 truncate",children:tab})]})}),jsxs12("div",{className:cn("relative shrink-0 flex items-center gap-2 bg-bg border-b border-line",mobile?"px-2.5 py-2":"px-3 py-2.5"),children:[!mobile&&!tab&&jsx13("span",{"aria-hidden":"true",className:"flex items-center gap-1.5 shrink-0 me-1",children:[0,1,2].map(i=>jsx13("span",{className:"size-2.5 rounded-full bg-line border border-border/40"},i))}),nav&&!mobile&&jsxs12("span",{className:"flex items-center gap-0.5 shrink-0 text-muted2/60",children:[jsx13("span",{className:cn(control,"cursor-not-allowed"),"aria-hidden":"true",children:jsx13(ChevronRight3,{size:13})}),jsx13("span",{className:cn(control,"cursor-not-allowed"),"aria-hidden":"true",children:jsx13(ChevronLeft3,{size:13})})]}),jsxs12("span",{className:cn("flex-1 min-w-0 flex items-center gap-1.5 rounded-full bg-surface border border-line",mobile?"h-6 px-2.5":"h-7 px-3"),children:[jsx13(Lock,{size:mobile?9:10,className:"text-green shrink-0","aria-hidden":"true"}),jsx13(TechnicalText,{className:cn("truncate text-muted",mobile?"text-[9.5px]":"text-micro"),children:url})]}),onReload&&!mobile&&jsx13("button",{type:"button",onClick:onReload,"aria-label":ui.reloadPreview,className:cn(control,"text-muted2 hover:bg-hover hover:text-ink cursor-pointer"),children:jsx13(RotateCw,{size:12,"aria-hidden":"true",className:cn(loading&&"animate-spin")})}),loading&&jsx13("span",{"aria-hidden":"true",className:"absolute bottom-0 inset-x-0 h-[2px] overflow-clip",children:jsx13("span",{className:"absolute top-0 h-full w-[35%] bg-brand animate-[qload_1.1s_ease-in-out_infinite]"})})]}),jsx13("div",{ref:viewport,className:"relative flex-1 min-h-0 overflow-clip bg-surface",children:contentWidth?jsx13("div",{style:{width:contentWidth,height:`${100/scale}%`,transform:`scale(${scale})`,transformOrigin:`top ${rtl?"right":"left"}`},children}):children}),mobile&&jsx13("span",{"aria-hidden":"true",className:"shrink-0 h-4 bg-bg flex items-center justify-center",children:jsx13("span",{className:"w-24 h-1 rounded-full bg-border/50"})})]})}import"react";import{jsx as jsx14,jsxs as jsxs13}from"react/jsx-runtime";var clamp=(v,lo=0,hi=100)=>Math.min(hi,Math.max(lo,v));var signedString=v=>(v<0?"\u2212":"")+String(Math.abs(v));function WaterfallChart({total,steps,totalLabel,netLabel,formatValue=signedString,className}){const ui=useUIText();const top=Math.max(1,total);const bars=steps.reduce((acc,s)=>{const from=acc.length?acc[acc.length-1].to:total;acc.push({...s,from,to:from+s.value});return acc},[]);const net=bars.length?bars[bars.length-1].to:total;const biggest=bars.reduce((acc,b,i)=>b.value<acc.v?{i,v:b.value}:acc,{i:-1,v:0});return jsxs13("div",{className:cn("flex flex-col",className),children:[jsx14(Line,{label:totalLabel??ui.totalSales,value:total,formatValue,strong:true,children:jsx14("span",{className:"block h-2.5 rounded-full bg-brand"})}),bars.map((b,i)=>{const drop=b.value<0;const lo=clamp(Math.min(b.from,b.to)/top*100);const span=clamp(Math.abs(b.value)/top*100);const worst=i===biggest.i;return jsx14(Line,{label:b.label,meta:b.meta,value:b.value,formatValue,flag:worst?"\u0623\u0643\u0628\u0631 \u062E\u0635\u0645":void 0,children:jsx14("span",{dir:"ltr",className:"relative block h-2.5 rounded-full bg-hover overflow-clip",children:jsx14("span",{className:cn("absolute inset-y-0 rounded-full",drop?worst?"bg-danger":"bg-brand-100":"bg-green-solid"),style:{insetInlineStart:`${lo}%`,width:`${span}%`}})})},b.key)}),jsx14(Line,{label:netLabel??ui.netToYou,value:net,formatValue,strong:true,net:true,children:jsx14("span",{dir:"ltr",className:"block h-2.5 rounded-full bg-hover overflow-clip",children:jsx14("span",{className:"block h-full rounded-full bg-green-solid",style:{width:`${clamp(net/top*100)}%`}})})})]})}function Line({label,meta,value,formatValue,flag,strong,net,children}){return jsxs13("div",{className:cn("flex flex-col gap-1.5 py-2.5",net&&"border-t border-line mt-1 pt-3.5"),children:[jsxs13("span",{className:"flex items-baseline justify-between gap-3",children:[jsxs13("span",{className:"flex items-baseline gap-2 min-w-0",children:[jsx14("span",{className:cn("truncate",strong?"text-ui font-extrabold text-ink":"text-ui text-muted"),children:label}),flag&&jsx14("span",{className:"shrink-0 text-micro font-bold text-red bg-red-bg px-1.5 py-0.5 rounded-mark",children:flag})]}),jsx14("span",{"data-num":true,className:cn("shrink-0",strong?"text-body font-black text-ink":"text-ui font-bold text-ink2"),children:formatValue(value)})]}),children,meta&&jsx14("span",{className:"text-micro text-muted2",children:meta})]})}function GoalBar({value,goal,pace,label,formatValue=String,className}){const ui=useUIText();const top=Math.max(value,goal)*1.06;const pct=clamp(value/top*100);const goalAt=clamp(goal/top*100);const paceAt=pace===void 0?null:clamp(goalAt*clamp(pace,0,1));const behind=paceAt!==null&&pct<paceAt;return jsxs13("div",{className:cn("flex flex-col gap-2",className),children:[jsxs13("span",{className:"flex items-baseline justify-between gap-3",children:[label&&jsx14("span",{className:"text-ui font-bold text-ink2 truncate",children:label}),jsxs13("span",{className:"flex items-baseline gap-1.5 shrink-0",children:[jsx14("span",{"data-num":true,className:"text-body font-black text-ink",children:formatValue(value)}),jsxs13("span",{className:"text-micro text-muted2",children:["\u0645\u0646 ",jsx14("span",{"data-num":true,children:formatValue(goal)})]})]})]}),jsxs13("span",{dir:"ltr",className:"relative block h-3 rounded-full bg-hover",children:[jsx14("span",{className:cn("absolute inset-y-0 start-0 rounded-full transition-[width] duration-500",behind?"bg-amber":"bg-brand"),style:{width:`${pct}%`}}),paceAt!==null&&jsx14("span",{"aria-hidden":"true",title:ui.shouldBeHere,className:"absolute -top-1 -bottom-1 w-0.5 bg-muted2 rounded-full",style:{insetInlineStart:`${paceAt}%`}}),jsx14("span",{"aria-hidden":"true",className:"absolute -top-1.5 -bottom-1.5 w-1 bg-ink rounded-full",style:{insetInlineStart:`${goalAt}%`}})]}),paceAt!==null&&jsx14("span",{className:cn("text-micro",behind?"text-amber-ink":"text-muted2"),children:behind?"\u0648\u0631\u0627 \u0627\u0644\u0625\u064A\u0642\u0627\u0639 \u0627\u0644\u0645\u0637\u0644\u0648\u0628":"\u0642\u062F\u0651\u0627\u0645 \u0627\u0644\u0625\u064A\u0642\u0627\u0639 \u0627\u0644\u0645\u0637\u0644\u0648\u0628"})]})}function ParetoChart({items,height=140,threshold=80,formatValue=String,className}){const sorted=[...items].sort((a,b)=>b.value-a.value);const sum=sorted.reduce((s,i)=>s+i.value,0)||1;const top=Math.max(1,sorted[0]?.value??1);const rows=sorted.reduce((out,it)=>{const acc=(out.length?out[out.length-1].cum*sum/100:0)+it.value;out.push({...it,cum:acc/sum*100});return out},[]);const vital=rows.findIndex(r=>r.cum>=threshold)+1;return jsxs13("div",{className:cn("flex flex-col gap-2.5",className),children:[jsxs13("span",{className:"text-caption text-muted [text-wrap:pretty]",children:[jsx14("span",{"data-num":true,className:"font-extrabold text-ink",children:vital})," ","\u0645\u0646"," ",jsx14("span",{"data-num":true,className:"font-extrabold text-ink",children:rows.length})," ","\u0628\u064A\u0639\u0645\u0644\u0648\u0627"," ",jsx14("span",{"data-num":true,className:"font-extrabold text-ink",children:threshold}),"\u066A \u0645\u0646 \u0627\u0644\u0625\u062C\u0645\u0627\u0644\u064A"]}),jsxs13("div",{className:"relative flex items-end gap-1.5",style:{height},children:[jsx14("span",{"aria-hidden":"true",className:"absolute inset-x-0 border-t border-dashed border-muted2",style:{top:`${100-threshold}%`}}),rows.map((r,i)=>jsx14("span",{className:"flex-1 min-w-0 flex flex-col justify-end items-center gap-1 h-full",children:jsx14("span",{title:`${String(r.label)} \xB7 ${formatValue(r.value)}`,className:cn("w-full rounded-t-mark transition-[height] duration-500",i<vital?"bg-brand":"bg-brand-100"),style:{height:`${clamp(r.value/top*100)}%`}})},r.key))]}),jsx14("div",{className:"flex items-center gap-1.5",children:rows.map((r,i)=>jsx14("span",{className:cn("flex-1 min-w-0 text-micro text-center truncate",i<vital?"text-ink2 font-bold":"text-muted2"),children:r.label},r.key))})]})}function StockRunway({items,urgentDays=7,horizonDays=30,className}){const rows=items.map(it=>({...it,days:it.perDay>0?it.stock/it.perDay:Infinity})).sort((a,b)=>a.days-b.days);return jsx14("div",{className:cn("flex flex-col gap-2.5",className),children:rows.map(r=>{const urgent=r.days<=urgentDays;const soon=!urgent&&r.days<=horizonDays/2;const pct=Number.isFinite(r.days)?clamp(r.days/horizonDays*100):100;return jsxs13("span",{className:"flex flex-col gap-1.5",children:[jsxs13("span",{className:"flex items-baseline justify-between gap-3",children:[jsx14("span",{className:"text-ui text-ink2 truncate min-w-0",children:r.label}),jsxs13("span",{className:"flex items-baseline gap-2 shrink-0",children:[jsxs13("span",{"data-num":true,className:"text-micro text-muted2",children:[r.stock," \u0642\u0637\u0639\u0629"]}),jsx14("span",{"data-num":true,className:cn("text-ui font-extrabold",urgent?"text-red":soon?"text-amber-ink":"text-ink"),children:Number.isFinite(r.days)?`${Math.floor(r.days)} \u064A\u0648\u0645`:"\u2014"})]})]}),jsx14("span",{dir:"ltr",className:"block h-1.5 rounded-full bg-hover overflow-clip",children:jsx14("span",{className:cn("block h-full rounded-full transition-[width] duration-500",urgent?"bg-danger":soon?"bg-amber":"bg-brand"),style:{width:`${pct}%`}})})]},r.key)})})}import{BadgeCheck}from"lucide-react";import{jsx as jsx15}from"react/jsx-runtime";var PROVIDER_LEVEL_LABEL={1:"\u0645\u0642\u062F\u0651\u0645 \u062C\u062F\u064A\u062F",2:"\u0645\u0642\u062F\u0651\u0645 \u0645\u062D\u062A\u0631\u0641",3:"\u0645\u0642\u062F\u0651\u0645 \u062E\u0628\u064A\u0631"};var PROVIDER_LEVEL_LABEL_EN={1:"New provider",2:"Pro provider",3:"Expert provider"};var CHEVRONS=[1.7,6,10.3];var DIM=.28;function ProviderMark({level,size=16,className}){return jsx15("svg",{width:size,height:size,viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:cn("shrink-0",className),children:CHEVRONS.map((y,i)=>jsx15("path",{d:`M3.2 ${y+4}L8 ${y}L12.8 ${y+4}`,stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",opacity:i>=CHEVRONS.length-level?1:DIM},y))})}var LEVEL_TONE={1:"bg-hover text-ink2",2:"bg-soft text-brand-ink",3:TONE_SOLID.brand};var SIZES={sm:{box:"size-6",mark:14},md:{box:"size-7",mark:16}};function MarkChip({label,size,tone,className,children}){return jsx15(Tooltip,{content:label,children:jsx15("span",{role:"img","aria-label":label,tabIndex:0,className:cn("inline-flex items-center justify-center rounded-sm shrink-0 cursor-pointer","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",SIZES[size].box,tone,className),children})})}function ProviderBadge({level,size="sm",className}){const en=useMoneyLang();const label=en?PROVIDER_LEVEL_LABEL_EN[level]:PROVIDER_LEVEL_LABEL[level];return jsx15(MarkChip,{label,size,tone:LEVEL_TONE[level],className,children:jsx15(ProviderMark,{level,size:SIZES[size].mark})})}var VERIFIED_LABEL="\u062D\u0633\u0627\u0628 \u0645\u0648\u062B\u0651\u0642";var VERIFIED_LABEL_EN="Verified account";function VerifiedBadge({size="sm",className}){const en=useMoneyLang();return jsx15(MarkChip,{label:en?VERIFIED_LABEL_EN:VERIFIED_LABEL,size,tone:TONE_SOFT.green,className,children:jsx15(BadgeCheck,{size:SIZES[size].mark,strokeWidth:2,"aria-hidden":"true"})})}export{ANIMATE_SCALE,Accordion,Alert,AudioPlayer,Avatar,Badge,BarChart,BrowserFrame,Button,COLOR_SCALE,CONTAINER_SCALE,Card,CardHeader,Carousel,Checkbox,ChoiceCards,Coach,CoachProvider,ColorField,Combobox,CommandPalette,Counter,DARK_TOKENS,DataTable,DateRangePicker,Drawer,Dropdown,Dropzone,EmptyState,FileRow,FilterChips,FunnelChart,Gallery,GoalBar,Heatmap,Input,Lightbox,LocaleCtx,Modal,Money,MoneyProvider,MultiSelect,NumberStepper,PROVIDER_LEVEL_LABEL,PROVIDER_LEVEL_LABEL_EN,PageHeader,ParetoChart,Phone,Product3DViewer,Progress,ProviderBadge,ProviderMark,RADIUS_SCALE,Radio,RadioGroup,RatingInput,SHADOW_SCALE,Scrubber,SearchInput,Select,ShareList,Sheet,Skeleton,SortableStatus,Sparkline,Stars,StatCard,Stepper,StockRunway,Switch,TEXT_SCALE,TOKENS,TONE_SOFT,TONE_SOLID,Tabs,TechnicalInput,TechnicalText,Textarea,Timeline,Toast,ToastHost,Tooltip,TrendChart,VerifiedBadge,VideoPlayer,WaterfallChart,WhatsAppIcon,buttonClasses,cn,coachSeconds,currencyName,currencySymbol,daysBetween,formatBytes,formatDate,formatRange,formatTime,isCurrency,normalizeHex,parsePhone,presets,toLatinDigits,useAudioLevel,useCoach,useCoachOptional,useCurrency,useCurrencySymbol,useMedia,useMoneyLang,useMoneyLocale,useSortable,useToasts,useUIText};
2
+ import{ToastHost,Tooltip,useToasts}from"./chunk-ENHEJXVH.js";import{BarChart,ChoiceCards,DataTable,FunnelChart,Heatmap,Money,MoneyProvider,ShareList,Sparkline,TrendChart,currencyName,currencySymbol,isCurrency,useCurrency,useCurrencySymbol}from"./chunk-EXX6U5BJ.js";import{Button,Checkbox,Input,Radio,RadioGroup,SearchInput,Select,Switch,Textarea}from"./chunk-VAMRF7HE.js";import{AudioPlayer,Avatar,Badge,Card,CardHeader,Coach,CoachProvider,Counter,PageHeader,Progress,Scrubber,Skeleton,StatCard,VideoPlayer,coachSeconds,formatTime,useAudioLevel,useCoach,useCoachOptional,useMedia}from"./chunk-GMIBQMMR.js";import{ANIMATE_SCALE,Alert,COLOR_SCALE,CONTAINER_SCALE,DARK_TOKENS,Drawer,EmptyState,LocaleCtx,Modal,RADIUS_SCALE,SHADOW_SCALE,Sheet,TEXT_SCALE,TOKENS,TONE_SOFT,TONE_SOLID,Toast,buttonClasses,cn,toLatinDigits,useMoneyLang,useMoneyLocale,useUIText}from"./chunk-ZE4S6DBP.js";import{useEffect,useRef,useState}from"react";import{Minus,Plus,Trash2}from"lucide-react";import{jsx,jsxs}from"react/jsx-runtime";var ar=new Intl.NumberFormat("ar-EG");var BOX={sm:"h-8",md:"h-11",lg:"h-14"};var BTN={sm:"w-8",md:"w-11",lg:"w-14"};var NUM={sm:"text-ui w-10",md:"text-body w-14",lg:"text-h3 w-20"};var ICON={sm:14,md:16,lg:20};function NumberStepper({value,onChange,min=0,max=Infinity,step=1,size="md",unit,onRemove,disabled,label,className}){const[draft,setDraft]=useState(null);const timer=useRef(void 0);useEffect(()=>()=>clearTimeout(timer.current),[]);const atMin=value<=min;const atMax=value>=max;const showRemove=Boolean(onRemove)&&atMin;const bump=dir=>onChange(Math.min(max,Math.max(min,value+dir*step)));const latest=useRef(value);useEffect(()=>{latest.current=value},[value]);function hold(dir){let delay=400;const tick=()=>{const next=Math.min(max,Math.max(min,latest.current+dir*step));if(next===latest.current)return;onChange(next);delay=Math.max(60,delay*.72);timer.current=setTimeout(tick,delay)};timer.current=setTimeout(tick,delay)}const stop=()=>clearTimeout(timer.current);function commit(raw){setDraft(null);const n=Number(toLatinDigits(raw).replace(/[^\d.-]/g,""));if(Number.isNaN(n))return;onChange(Math.min(max,Math.max(min,n)))}const btn=dir=>{const off=disabled||(dir===1?atMax:atMin&&!showRemove);const Icon=dir===1?Plus:showRemove?Trash2:Minus;return jsx("button",{type:"button",disabled:off,"aria-label":dir===1?"\u0632\u064A\u0627\u062F\u0629":showRemove?"\u062D\u0630\u0641":"\u0646\u0642\u0635\u0627\u0646",onClick:()=>dir===-1&&showRemove?onRemove?.():bump(dir),onPointerDown:()=>!off&&!showRemove&&hold(dir),onPointerUp:stop,onPointerLeave:stop,className:cn("flex items-center justify-center shrink-0 self-stretch cursor-pointer select-none","transition-colors",BTN[size],off?"text-muted2/45 cursor-not-allowed":cn("text-ink2 hover:bg-hover active:bg-soft",showRemove&&dir===-1&&"text-danger hover:bg-red-bg")),children:jsx(Icon,{size:ICON[size],strokeWidth:2.4,"aria-hidden":"true"})})};return jsxs("div",{dir:"ltr",className:cn("inline-flex items-center rounded-field border border-line bg-surface overflow-clip","divide-x divide-line","hover:border-border","focus-within:border-brand focus-within:ring-2 focus-within:ring-brand/25","transition-[border-color,box-shadow]",BOX[size],disabled&&"opacity-60",className),children:[btn(-1),jsxs("span",{className:"flex items-center justify-center gap-1 px-1 self-stretch",children:[jsx("input",{"data-num":true,value:draft??ar.format(value),disabled,inputMode:"numeric","aria-label":label??"\u0627\u0644\u0642\u064A\u0645\u0629",onFocus:()=>setDraft(String(value)),onChange:e=>setDraft(toLatinDigits(e.target.value)),onBlur:e=>commit(e.target.value),onKeyDown:e=>e.key==="Enter"&&e.target.blur(),className:cn("bg-transparent outline-none text-center font-extrabold text-ink","disabled:text-muted2",NUM[size])}),unit&&jsx("span",{className:"text-micro text-muted2 select-none shrink-0",children:unit})]}),btn(1)]})}import{MessageSquare,Phone as PhoneIcon}from"lucide-react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function WhatsAppIcon({size=15,...rest}){return jsx2("svg",{viewBox:"0 0 24 24",width:size,height:size,fill:"currentColor","aria-hidden":"true",...rest,children:jsx2("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"})})}var DIAL={"20":{groups:[3,3,4],name:"\u0645\u0635\u0631"},"966":{groups:[2,3,4],name:"\u0627\u0644\u0633\u0639\u0648\u062F\u064A\u0629"},"971":{groups:[2,3,4],name:"\u0627\u0644\u0625\u0645\u0627\u0631\u0627\u062A"},"965":{groups:[4,4],name:"\u0627\u0644\u0643\u0648\u064A\u062A"},"974":{groups:[4,4],name:"\u0642\u0637\u0631"},"973":{groups:[4,4],name:"\u0627\u0644\u0628\u062D\u0631\u064A\u0646"},"968":{groups:[4,4],name:"\u0639\u064F\u0645\u0627\u0646"},"962":{groups:[1,4,4],name:"\u0627\u0644\u0623\u0631\u062F\u0646"},"964":{groups:[3,3,4],name:"\u0627\u0644\u0639\u0631\u0627\u0642"},"961":{groups:[2,3,3],name:"\u0644\u0628\u0646\u0627\u0646"},"963":{groups:[3,3,3],name:"\u0633\u0648\u0631\u064A\u0627"},"970":{groups:[2,3,4],name:"\u0641\u0644\u0633\u0637\u064A\u0646"},"967":{groups:[3,3,3],name:"\u0627\u0644\u064A\u0645\u0646"},"249":{groups:[3,3,3],name:"\u0627\u0644\u0633\u0648\u062F\u0627\u0646"},"212":{groups:[3,3,3],name:"\u0627\u0644\u0645\u063A\u0631\u0628"},"213":{groups:[3,3,3],name:"\u0627\u0644\u062C\u0632\u0627\u0626\u0631"},"216":{groups:[2,3,3],name:"\u062A\u0648\u0646\u0633"},"218":{groups:[2,3,4],name:"\u0644\u064A\u0628\u064A\u0627"},"222":{groups:[2,2,2,2],name:"\u0645\u0648\u0631\u064A\u062A\u0627\u0646\u064A\u0627"},"252":{groups:[2,3,4],name:"\u0627\u0644\u0635\u0648\u0645\u0627\u0644"},"253":{groups:[2,2,2,2],name:"\u062C\u064A\u0628\u0648\u062A\u064A"},"269":{groups:[3,4],name:"\u062C\u0632\u0631 \u0627\u0644\u0642\u0645\u0631"}};var DIALS=Object.keys(DIAL).sort((a,b)=>b.length-a.length);function parsePhone(raw,defaultDial="20"){const digits=raw.replace(/\D/g,"");let rest=digits;const intl=raw.trim().startsWith("+")||digits.startsWith("00");if(digits.startsWith("00"))rest=digits.slice(2);if(intl){for(const d of DIALS){if(rest.startsWith(d)){return{dial:d,local:rest.slice(d.length),country:DIAL[d].name}}}return{dial:"",local:rest}}const local=rest.replace(/^0/,"");return{dial:defaultDial,local,country:DIAL[defaultDial]?.name}}function join(parts,format){if(format==="spaces"||parts.length<2)return parts.join(" ");const[head,...tail]=parts;return`(${head}) ${tail.join("-")}`}function group(local,dial){const rule=DIAL[dial]?.groups;const out=[];let i=0;if(rule){for(const n of rule){if(i>=local.length)break;out.push(local.slice(i,i+n));i+=n}}while(i<local.length){out.push(local.slice(i,i+3));i+=3}return out.filter(Boolean)}var SIZE={inherit:"",sm:"text-caption",md:"text-ui"};function Phone({value,defaultDial="20",format="parens",mask,call,sms,whatsapp,size="md",className}){const{dial,local,country}=parsePhone(value,defaultDial);const e164=`+${dial}${local}`;const shown=mask?`\u2022\u2022\u2022 ${local.slice(-4)}`:dial?join(group(local,dial),format):`+${local}`;const bare=size==="inherit";return jsxs2("span",{className:cn("inline-flex items-center gap-2 min-w-0",className),children:[jsxs2("span",{dir:"ltr",className:cn("inline-flex items-baseline gap-1.5 whitespace-nowrap min-w-0",SIZE[size]),children:[dial&&!mask&&jsxs2("span",{className:cn("opacity-70",!bare&&"text-muted2 font-normal"),title:country,children:["+",dial]}),jsx2("span",{style:{unicodeBidi:"isolate",fontVariantNumeric:"tabular-nums"},className:cn("truncate",!bare&&"font-bold text-ink"),children:shown})]}),(call||sms||whatsapp)&&!mask&&jsxs2("span",{className:"inline-flex items-center gap-0.5 shrink-0",children:[call&&jsx2(Action,{href:`tel:${e164}`,label:`\u0627\u062A\u0635\u0627\u0644 \u0628\u0640${e164}`,children:jsx2(PhoneIcon,{size:14,"aria-hidden":"true"})}),sms&&jsx2(Action,{href:`sms:${e164}`,label:`\u0631\u0633\u0627\u0644\u0629 \u0646\u0635\u0651\u064A\u0629 \u0625\u0644\u0649 ${e164}`,children:jsx2(MessageSquare,{size:14,"aria-hidden":"true"})}),whatsapp&&jsx2(Action,{href:`https://wa.me/${dial}${local}`,label:`\u0648\u0627\u062A\u0633\u0627\u0628 ${e164}`,external:true,className:"hover:text-green",children:jsx2(WhatsAppIcon,{size:15})})]})]})}function Action({href,label,external,className,children}){return jsx2("a",{href,"aria-label":label,title:label,...external?{target:"_blank",rel:"noreferrer"}:{},className:cn("size-7 rounded-sm inline-flex items-center justify-center shrink-0","text-muted hover:text-brand-ink hover:bg-hover transition-colors no-underline",className),children})}import{forwardRef,useId}from"react";import{jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";var LEAD={hex:"#",url:"/"};var TechnicalInput=forwardRef(function TechnicalInput2({kind="code",className,wrapperClassName,...rest},ref){return jsx3(Input,{ref,dir:"ltr",spellCheck:false,autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",inputMode:kind==="url"?"url":"text",wrapperClassName:cn("[unicode-bidi:isolate]",wrapperClassName),className:cn("font-mono tracking-[.01em] [unicode-bidi:isolate] text-start [[dir=rtl]_&]:text-right",className),...rest})});function TechnicalText({children,className}){return jsx3("span",{dir:"ltr",className:cn("inline-block font-mono [unicode-bidi:isolate]",className),children})}function ColorField({label,note,value,onChange,disabled,id:idProp}){const auto=useId();const id=idProp??auto;return jsxs3("div",{className:"flex flex-col gap-1.5 min-w-0",children:[jsx3("label",{htmlFor:`${id}-hex`,className:"text-ui font-bold text-ink2",children:label}),note&&jsx3("span",{className:"text-caption leading-[1.6] text-muted",children:note}),jsxs3("div",{className:"flex items-center gap-2 min-w-0",children:[jsxs3("span",{className:"relative shrink-0 size-11",children:[jsx3("input",{id,type:"color",value:normalizeHex(value)??"#000000",disabled,onChange:e=>onChange(e.target.value.toUpperCase()),"aria-label":typeof label==="string"?label:void 0,className:"absolute inset-0 size-full opacity-0 cursor-pointer disabled:cursor-not-allowed"}),jsx3("span",{"aria-hidden":"true",className:"pointer-events-none block size-11 rounded-field border border-border",style:{background:normalizeHex(value)??"transparent"}})]}),jsx3(TechnicalInput,{id:`${id}-hex`,kind:"hex",hideLabel:true,size:"md",maxLength:7,disabled,value,onChange:e=>onChange(e.target.value),onBlur:()=>{const fixed=normalizeHex(value);if(fixed&&fixed!==value)onChange(fixed);else if(!fixed&&value&&!value.startsWith(LEAD.hex))onChange(`#${value}`)},wrapperClassName:"flex-1 min-w-0"})]})]})}function normalizeHex(input){const raw=input.trim().replace(/^#/,"");if(/^[0-9a-fA-F]{3}$/.test(raw)){return`#${raw.split("").map(c=>c+c).join("").toUpperCase()}`}if(/^[0-9a-fA-F]{6}$/.test(raw))return`#${raw.toUpperCase()}`;return null}import{useCallback,useEffect as useEffect2,useRef as useRef2,useState as useState2}from"react";import{Box,Loader2}from"lucide-react";import{jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";function detailOf(e){return e.detail??{}}function Product3DViewer({src,iosSrc,poster,alt,autoRotate=true,onLoad,onError,onARLaunch,className}){const en=useMoneyLang();const host=useRef2(null);const slot=useRef2(null);const viewer=useRef2(null);const[phase,setPhase]=useState2("idle");const[progress,setProgress]=useState2(0);const[canAR,setCanAR]=useState2(false);const cb=useRef2({onLoad,onError,onARLaunch});useEffect2(()=>{cb.current={onLoad,onError,onARLaunch}},[onLoad,onError,onARLaunch]);useEffect2(()=>{const mount=slot.current;const box=host.current;if(!mount||!box)return;let dead=false;let el=null;setPhase("idle");setProgress(0);setCanAR(false);async function build(target){try{await import("@google/model-viewer");await customElements.whenDefined("model-viewer");if(dead)return;el=document.createElement("model-viewer");viewer.current=el;el.setAttribute("src",src);if(iosSrc)el.setAttribute("ios-src",iosSrc);el.setAttribute("alt",alt);el.setAttribute("camera-controls","");el.setAttribute("touch-action","pan-y");el.setAttribute("shadow-intensity","1");el.setAttribute("ar","");el.setAttribute("ar-modes","webxr scene-viewer quick-look");el.setAttribute("loading","eager");el.style.width="100%";el.style.height="100%";el.style.backgroundColor="transparent";const silence=document.createElement("button");silence.slot="ar-button";silence.style.display="none";silence.tabIndex=-1;silence.setAttribute("aria-hidden","true");el.appendChild(silence);const reduce=typeof matchMedia!=="undefined"&&matchMedia("(prefers-reduced-motion: reduce)").matches;if(autoRotate&&!reduce)el.setAttribute("auto-rotate","");el.addEventListener("progress",e=>{const total=detailOf(e).totalProgress??0;if(!dead)setProgress(total)});el.addEventListener("load",()=>{if(dead)return;setPhase("ready");setCanAR(Boolean(el?.canActivateAR));cb.current.onLoad?.()});el.addEventListener("error",e=>{if(dead)return;setPhase("error");cb.current.onError?.(detailOf(e).type??"load-failed")});target.appendChild(el);setPhase("loading")}catch{if(dead)return;setPhase("error");cb.current.onError?.("viewer-unavailable")}}const io=new IntersectionObserver(entries=>{if(entries.some(x=>x.isIntersecting)){io.disconnect();void build(mount)}},{rootMargin:"200px"});io.observe(box);return()=>{dead=true;io.disconnect();el?.remove();viewer.current=null}},[src,iosSrc,alt,autoRotate]);const launchAR=useCallback(()=>{cb.current.onARLaunch?.();void viewer.current?.activateAR().catch(()=>{})},[]);const pct=Math.round(progress*100);const showPoster=phase!=="ready";return jsxs4("div",{ref:host,className:cn("relative aspect-square w-full overflow-clip rounded-card bg-hover border border-line",className),children:[showPoster&&jsx4("img",{src:poster,alt,loading:"lazy",decoding:"async",draggable:false,className:"absolute inset-0 size-full object-contain"}),jsx4("div",{ref:slot,className:cn("absolute inset-0",showPoster&&"opacity-0"),"aria-hidden":showPoster}),phase==="loading"&&jsxs4("div",{className:"absolute inset-x-0 bottom-0 flex flex-col gap-1.5 p-3",children:[jsxs4("span",{className:"flex items-center gap-2 text-micro font-bold text-ink2",children:[jsx4(Loader2,{size:12,className:"animate-spin shrink-0","aria-hidden":"true"}),en?"Loading 3D model":"\u062C\u0627\u0631\u064A \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062C\u0633\u0651\u0645",jsxs4("span",{dir:"ltr","data-num":true,className:"ms-auto text-muted",children:[pct,"%"]})]}),jsx4("span",{role:"progressbar","aria-valuenow":pct,"aria-valuemin":0,"aria-valuemax":100,"aria-label":en?"Model loading progress":"\u062A\u0642\u062F\u0651\u0645 \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062C\u0633\u0651\u0645",className:"h-1 w-full rounded-full bg-line overflow-clip",children:jsx4("span",{className:"block h-full rounded-full bg-brand transition-[width] duration-200",style:{width:`${pct}%`}})})]}),phase==="ready"&&canAR&&jsxs4("button",{type:"button",onClick:launchAR,className:cn("absolute bottom-3 end-3 inline-flex items-center gap-2 h-9 px-3.5 rounded-full","bg-surface/92 backdrop-blur border border-line shadow-pop","text-ui font-bold text-ink2 cursor-pointer transition-colors hover:text-brand-ink"),children:[jsx4(Box,{size:15,"aria-hidden":"true"}),en?"See it in your space":"\u0634\u0648\u0641\u0647 \u0641\u064A \u0645\u0643\u0627\u0646\u0643"]})]})}import{X}from"lucide-react";import{jsx as jsx5,jsxs as jsxs5}from"react/jsx-runtime";function Tabs({items,value,onChange,variant="pill",label,className}){if(variant==="segmented"){return jsx5("div",{role:"tablist","aria-label":label,className:cn("flex flex-wrap gap-0.5 p-0.5 rounded-field bg-bg self-start","max-w-full overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",className),children:items.map(it=>{const on=it.key===value;return jsxs5("button",{role:"tab",type:"button","aria-selected":on,onClick:()=>onChange(it.key),className:cn("h-9 px-2 sm:px-3.5 rounded-sm inline-flex items-center gap-2 text-ui font-bold cursor-pointer transition-colors","shrink-0 whitespace-nowrap","focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",on?"bg-surface text-ink shadow-raise":"text-muted hover:text-ink"),children:[it.icon&&jsx5(it.icon,{size:14}),it.label,typeof it.count==="number"&&jsx5("span",{"data-num":true,className:"opacity-60",children:it.count})]},it.key)})})}return jsx5("div",{role:"tablist","aria-label":label,className:cn("flex items-center gap-2.5 flex-wrap",className),children:items.map(it=>{const on=it.key===value;return jsxs5("button",{role:"tab",type:"button","aria-selected":on,onClick:()=>onChange(it.key),className:cn("h-10 px-3.5 rounded-field border inline-flex items-center gap-1.5 text-ui font-bold cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",on?"border-brand bg-soft text-brand-ink":"border-border bg-surface text-ink2 hover:border-brand"),children:[it.icon&&jsx5(it.icon,{size:14}),it.label,typeof it.count==="number"&&jsx5("span",{"data-num":true,className:"text-micro opacity-70",children:it.count})]},it.key)})})}function FilterChips({chips,onClearAll,label,clearAllLabel}){const ui=useUIText();if(chips.length===0)return null;return jsxs5("div",{className:"flex items-center gap-2 flex-wrap",children:[jsx5("span",{className:"text-caption text-muted",children:label??ui.activeFilters}),chips.map(c=>jsxs5("button",{type:"button",onClick:c.onClear,className:"inline-flex items-center gap-1.5 h-7 ps-3 pe-2 rounded-full bg-soft text-brand-ink text-caption font-bold cursor-pointer transition-colors hover:bg-soft2",children:[c.label,jsx5(X,{size:12,strokeWidth:2.5,"aria-hidden":"true"})]},c.label)),onClearAll&&jsx5("button",{type:"button",onClick:onClearAll,className:"text-caption font-bold text-muted cursor-pointer hover:text-ink transition-colors",children:clearAllLabel??ui.clearAll})]})}import{useEffect as useEffect3,useId as useId2,useMemo,useRef as useRef3,useState as useState3}from"react";import{Check,ChevronDown,Plus as Plus2,Search,X as X2}from"lucide-react";import{jsx as jsx6,jsxs as jsxs6}from"react/jsx-runtime";function useDismiss(open,close){const ref=useRef3(null);useEffect3(()=>{if(!open)return;function onDown(e){if(ref.current&&!ref.current.contains(e.target))close()}function onKey(e){if(e.key==="Escape")close()}document.addEventListener("mousedown",onDown);document.addEventListener("keydown",onKey);return()=>{document.removeEventListener("mousedown",onDown);document.removeEventListener("keydown",onKey)}},[open,close]);return ref}var TRIGGER="w-full h-10 px-3.5 rounded-field border bg-surface flex items-center gap-2.5 text-body cursor-pointer transition-colors outline-none focus-visible:border-brand";var PANEL="absolute z-30 top-[calc(100%+6px)] inset-x-0 bg-surface border border-line rounded-card shadow-panel overflow-clip animate-[fade-in_.14s_ease-out]";var ITEM="w-full px-3 py-2.5 flex items-center gap-2.5 text-start text-ui cursor-pointer transition-colors hover:bg-hover disabled:opacity-45 disabled:cursor-not-allowed";function Label({id,children}){if(!children)return null;return jsx6("label",{htmlFor:id,className:"text-ui font-bold text-ink2",children})}function Dropdown({label,value,onChange,options,placeholder,className}){const ui=useUIText();const id=useId2();const[open,setOpen]=useState3(false);const ref=useDismiss(open,()=>setOpen(false));const current=options.find(o=>o.value===value);return jsxs6("div",{className:cn("flex flex-col gap-1.5",className),children:[jsx6(Label,{id,children:label}),jsxs6("div",{ref,className:"relative",children:[jsxs6("button",{id,type:"button","aria-haspopup":"listbox","aria-expanded":open,onClick:()=>setOpen(v=>!v),className:cn(TRIGGER,open?"border-brand":"border-border hover:border-brand"),children:[current?.icon,jsx6("span",{className:cn("flex-1 min-w-0 text-start truncate",!current&&"text-muted2"),children:current?.label??placeholder??ui.select}),current?.meta&&jsx6("span",{className:"text-caption text-muted shrink-0",children:current.meta}),jsx6(ChevronDown,{size:15,"aria-hidden":"true",className:cn("text-muted2 shrink-0 transition-transform",open&&"rotate-180")})]}),open&&jsx6("div",{role:"listbox",className:cn(PANEL,"max-h-72 overflow-y-auto py-1"),children:options.map(o=>jsxs6("button",{type:"button",role:"option","aria-selected":o.value===value,disabled:o.disabled,onClick:()=>{onChange(o.value);setOpen(false)},className:cn(ITEM,o.value===value&&"bg-soft"),children:[o.icon,jsxs6("span",{className:"flex-1 min-w-0 flex flex-col",children:[jsx6("span",{className:"font-bold truncate",children:o.label}),o.meta&&jsx6("span",{className:"text-caption text-muted",children:o.meta})]}),o.value===value&&jsx6(Check,{size:14,className:"text-brand-ink shrink-0","aria-hidden":"true"})]},o.value))})]})]})}function Combobox({label,value,onChange,options,placeholder,searchPlaceholder,emptyText,className}){const ui=useUIText();const id=useId2();const[open,setOpen]=useState3(false);const[query,setQuery]=useState3("");const ref=useDismiss(open,()=>setOpen(false));const current=options.find(o=>o.value===value);const results=useMemo(()=>{const q=query.trim();if(!q)return options;return options.filter(o=>o.label.includes(q)||o.meta?.includes(q))},[options,query]);return jsxs6("div",{className:cn("flex flex-col gap-1.5",className),children:[jsx6(Label,{id,children:label}),jsxs6("div",{ref,className:"relative",children:[jsxs6("button",{id,type:"button","aria-haspopup":"listbox","aria-expanded":open,onClick:()=>{setOpen(v=>!v);setQuery("")},className:cn(TRIGGER,open?"border-brand":"border-border hover:border-brand"),children:[jsx6("span",{className:cn("flex-1 min-w-0 text-start truncate",!current&&"text-muted2"),children:current?.label??placeholder??ui.select}),current?.meta&&jsx6("span",{className:"text-caption text-muted shrink-0",children:current.meta}),jsx6(ChevronDown,{size:15,"aria-hidden":"true",className:cn("text-muted2 shrink-0 transition-transform",open&&"rotate-180")})]}),open&&jsxs6("div",{className:PANEL,children:[jsxs6("div",{className:"flex items-center gap-2.5 px-3 h-11 border-b border-line",children:[jsx6(Search,{size:15,className:"text-muted2 shrink-0","aria-hidden":"true"}),jsx6("input",{autoFocus:true,value:query,onChange:e=>setQuery(e.target.value),placeholder:searchPlaceholder??ui.search,"aria-label":searchPlaceholder??ui.search,className:"flex-1 min-w-0 bg-transparent border-none outline-none text-ui text-ink placeholder:text-muted2"}),query&&jsx6("button",{type:"button",onClick:()=>setQuery(""),"aria-label":ui.clearSearch,className:"shrink-0 text-muted2 hover:text-ink cursor-pointer transition-colors",children:jsx6(X2,{size:14,"aria-hidden":"true"})}),jsx6("kbd",{dir:"ltr",className:"shrink-0 px-1.5 py-0.5 rounded-xs bg-bg border border-line text-micro font-bold text-muted2",children:"Esc"})]}),jsxs6("div",{role:"listbox",className:"max-h-64 overflow-y-auto py-1",children:[results.map(o=>jsxs6("button",{type:"button",role:"option","aria-selected":o.value===value,onClick:()=>{onChange(o.value);setOpen(false)},className:cn(ITEM,o.value===value&&"bg-soft"),children:[jsxs6("span",{className:"flex-1 min-w-0 flex flex-col",children:[jsx6("span",{className:"font-bold truncate",children:o.label}),o.meta&&jsx6("span",{className:"text-caption text-muted",children:o.meta})]}),o.value===value&&jsx6(Check,{size:14,className:"text-brand-ink shrink-0","aria-hidden":"true"})]},o.value)),results.length===0&&jsx6("span",{className:"block px-3 py-6 text-center text-ui text-muted2",children:emptyText??ui.noResults})]})]})]})]})}function MultiSelect({label,values,onChange,options,placeholder,createLabel,onCreate,className}){const ui=useUIText();const id=useId2();const[open,setOpen]=useState3(false);const[query,setQuery]=useState3("");const ref=useDismiss(open,()=>setOpen(false));const results=useMemo(()=>{const q=query.trim();if(!q)return options;return options.filter(o=>o.label.includes(q))},[options,query]);const exact=results.some(o=>o.label===query.trim());const canCreate=Boolean(onCreate&&query.trim()&&!exact);function toggle(v){onChange(values.includes(v)?values.filter(x=>x!==v):[...values,v])}return jsxs6("div",{className:cn("flex flex-col gap-1.5",className),children:[jsxs6("div",{className:"flex items-center justify-between gap-3",children:[jsx6(Label,{id,children:label}),values.length>0&&jsx6("button",{type:"button",onClick:()=>onChange([]),className:"text-caption font-bold text-muted cursor-pointer hover:text-ink transition-colors",children:"\u0645\u0633\u062D \u0627\u0644\u0643\u0644"})]}),jsxs6("div",{ref,className:"relative",children:[jsxs6("button",{id,type:"button","aria-haspopup":"listbox","aria-expanded":open,onClick:()=>setOpen(v=>!v),className:cn(TRIGGER,"h-auto min-h-10 py-1.5 flex-wrap",open?"border-brand":"border-border hover:border-brand"),children:[values.length===0&&jsx6("span",{className:"text-muted2 flex-1 text-start",children:placeholder??ui.select}),values.map(v=>{const o=options.find(x=>x.value===v);return jsxs6("span",{className:"inline-flex items-center gap-1 h-7 ps-2.5 pe-1.5 rounded-full bg-soft text-brand-ink text-caption font-bold",children:[o?.label??v,jsx6("button",{type:"button","aria-label":`\u0625\u0632\u0627\u0644\u0629 ${o?.label??v}`,onClick:e=>{e.stopPropagation();toggle(v)},className:"flex text-brand-ink/60 hover:text-brand-ink cursor-pointer",children:jsx6(X2,{size:12,strokeWidth:2.5,"aria-hidden":"true"})})]},v)}),jsx6(ChevronDown,{size:15,"aria-hidden":"true",className:cn("text-muted2 shrink-0 ms-auto transition-transform",open&&"rotate-180")})]}),open&&jsxs6("div",{className:PANEL,children:[jsxs6("div",{className:"flex items-center gap-2.5 px-3 h-11 border-b border-line",children:[jsx6(Search,{size:15,className:"text-muted2 shrink-0","aria-hidden":"true"}),jsx6("input",{autoFocus:true,value:query,onChange:e=>setQuery(e.target.value),placeholder:ui.searchOrAdd,"aria-label":ui.searchOrAdd,className:"flex-1 min-w-0 bg-transparent border-none outline-none text-ui text-ink placeholder:text-muted2"})]}),jsxs6("div",{role:"listbox","aria-multiselectable":true,className:"max-h-56 overflow-y-auto py-1",children:[results.map(o=>{const on=values.includes(o.value);return jsxs6("button",{type:"button",role:"option","aria-selected":on,onClick:()=>toggle(o.value),className:ITEM,children:[jsx6("span",{"aria-hidden":"true",className:cn("size-[18px] rounded-xs border-[1.5px] flex items-center justify-center shrink-0 transition-colors",on?"bg-brand border-brand":"bg-surface border-border"),children:jsx6(Check,{size:11,strokeWidth:3,className:cn("text-white",!on&&"opacity-0")})}),jsx6("span",{className:"flex-1 min-w-0 truncate",children:o.label}),o.meta&&jsx6("span",{className:"text-caption text-muted2 shrink-0",children:o.meta})]},o.value)}),canCreate&&jsxs6("button",{type:"button",onClick:()=>{onCreate?.(query.trim());setQuery("")},className:cn(ITEM,"text-brand-ink font-bold border-t border-line mt-1 pt-3"),children:[jsx6(Plus2,{size:14,"aria-hidden":"true",className:"shrink-0"}),createLabel?createLabel(query.trim()):`\u0623\u0636\u0641 \xAB${query.trim()}\xBB`]}),results.length===0&&!canCreate&&jsx6("span",{className:"block px-3 py-6 text-center text-ui text-muted2",children:ui.noResults})]})]})]})]})}function CommandPalette({open,onClose,items,placeholder,emptyText}){const ui=useUIText();const[query,setQuery]=useState3("");useEffect3(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);const groups=useMemo(()=>{const q=query.trim();const hits=q?items.filter(i=>i.title.includes(q)||i.meta?.includes(q)):items;const out=new Map;for(const i of hits)out.set(i.group,[...out.get(i.group)??[],i]);return[...out.entries()]},[items,query]);if(!open)return null;return jsxs6("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[12vh] px-4",role:"dialog","aria-modal":"true",children:[jsx6("button",{type:"button","aria-label":ui.close,onClick:onClose,className:"absolute inset-0 bg-black/40 backdrop-blur-[2px] cursor-default"}),jsxs6("div",{className:"relative w-full max-w-[560px] bg-surface border border-line rounded-lg shadow-modal overflow-clip animate-[fade-in_.16s_ease-out]",children:[jsxs6("div",{className:"flex items-center gap-3 px-4 h-14 border-b border-line",children:[jsx6(Search,{size:17,className:"text-muted2 shrink-0","aria-hidden":"true"}),jsx6("input",{autoFocus:true,value:query,onChange:e=>setQuery(e.target.value),placeholder:placeholder??ui.searchEverything,"aria-label":placeholder??ui.searchEverything,className:"flex-1 min-w-0 bg-transparent border-none outline-none text-body text-ink placeholder:text-muted2"}),jsx6("kbd",{dir:"ltr",className:"shrink-0 px-1.5 py-0.5 rounded-xs bg-bg border border-line text-micro font-bold text-muted2",children:"Esc"})]}),jsxs6("div",{className:"max-h-[52vh] overflow-y-auto py-2",children:[groups.map(([group2,list])=>jsxs6("div",{className:"flex flex-col",children:[jsx6("span",{className:"px-4 pt-2 pb-1 text-micro font-extrabold text-muted2 tracking-wide",children:group2}),list.map(i=>jsxs6("button",{type:"button",onClick:()=>{i.onRun?.();onClose()},className:"px-4 py-2.5 flex items-center gap-3 text-start cursor-pointer transition-colors hover:bg-hover",children:[i.icon&&jsx6("span",{className:"text-muted shrink-0",children:i.icon}),jsx6("span",{className:"flex-1 min-w-0 text-body font-bold text-ink truncate",children:i.title}),i.meta&&jsx6("span",{className:"text-caption text-muted2 shrink-0",children:i.meta})]},i.id))]},group2)),groups.length===0&&jsx6("span",{className:"block px-4 py-10 text-center text-ui text-muted2",children:emptyText??ui.noResults})]})]})]})}import{useState as useState4}from"react";import{Check as Check2,ChevronDown as ChevronDown2}from"lucide-react";import{Fragment,jsx as jsx7,jsxs as jsxs7}from"react/jsx-runtime";function Accordion({items,mode="single",defaultOpen=[],className}){const[open,setOpen]=useState4(defaultOpen);function toggle(key){setOpen(prev=>{if(prev.includes(key))return prev.filter(k=>k!==key);return mode==="single"?[key]:[...prev,key]})}return jsx7("div",{className:cn("bg-surface border border-line rounded-card overflow-clip",className),children:items.map(it=>{const on=open.includes(it.key);return jsxs7("div",{className:"border-b border-line last:border-0",children:[jsxs7("button",{type:"button","aria-expanded":on,onClick:()=>toggle(it.key),className:"w-full px-4 py-3.5 flex items-center gap-3 text-start cursor-pointer transition-colors hover:bg-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",children:[it.icon&&jsx7("span",{"aria-hidden":"true",className:"size-8 rounded-sm bg-soft text-brand-ink flex items-center justify-center shrink-0",children:jsx7(it.icon,{size:15})}),jsxs7("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[jsx7("span",{className:"text-body font-extrabold text-ink",children:it.title}),it.description&&jsx7("span",{className:"text-caption text-muted",children:it.description})]}),jsx7(ChevronDown2,{size:16,"aria-hidden":"true",className:cn("text-muted2 shrink-0 transition-transform duration-200",on&&"rotate-180")})]}),jsx7("div",{className:cn("grid transition-[grid-template-rows] duration-200 ease-out",on?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx7("div",{className:"overflow-clip",children:jsx7("div",{className:"px-4 pb-4 pt-0.5 text-ui leading-[1.85] text-ink2",children:it.children})})})]},it.key)})})}function Timeline({steps,current,nowLabel,className}){const ui=useUIText();return jsx7("ol",{className:cn("flex flex-col m-0 p-0 list-none",className),children:steps.map((s,i)=>{const done=i<current;const active=i===current;const last=i===steps.length-1;return jsxs7("li",{className:"flex gap-3",children:[jsxs7("span",{className:"flex flex-col items-center shrink-0",children:[jsx7("span",{"aria-hidden":"true",className:cn("size-7 rounded-full flex items-center justify-center border-2 transition-colors",done&&"bg-brand border-brand text-white",active&&"bg-surface border-brand text-brand-ink",!done&&!active&&"bg-surface border-border text-muted2"),children:done?jsx7(Check2,{size:14,strokeWidth:3}):jsx7("span",{className:cn("size-2 rounded-full",active?"bg-brand":"bg-border")})}),!last&&jsx7("span",{"aria-hidden":"true",className:cn("w-0.5 flex-1 min-h-8 transition-colors",done?"bg-brand":"bg-line")})]}),jsxs7("span",{className:cn("flex flex-col gap-0.5 min-w-0",last?"pb-0":"pb-5"),children:[jsxs7("span",{className:"flex items-center gap-2.5 flex-wrap",children:[jsx7("span",{className:cn("text-body font-extrabold",done||active?"text-ink":"text-muted2"),children:s.title}),s.time&&jsx7("span",{"data-num":true,className:"text-micro text-muted2",children:s.time}),active&&jsx7("span",{className:cn("px-2 py-0.5 rounded-full text-micro font-extrabold",TONE_SOFT[s.tone??"brand"]),children:nowLabel??ui.now})]}),s.note&&jsx7("span",{className:"text-caption leading-[1.7] text-muted",children:s.note})]})]},s.key)})})}function Stepper({steps,done,onPick,className}){return jsx7("ol",{className:cn("flex items-start gap-1 m-0 p-0 list-none",className),children:steps.map((s,i)=>{const on=done.includes(s.key);const isCurrent=!on&&steps.slice(0,i).every(x=>done.includes(x.key));const last=i===steps.length-1;const Tag=onPick?"button":"div";return jsxs7("li",{className:"flex-1 flex flex-col items-center gap-2 min-w-0",children:[jsxs7("span",{className:"w-full flex items-center gap-1",children:[jsx7("span",{"aria-hidden":"true",className:cn("h-0.5 flex-1 rounded-full",i===0?"bg-transparent":on?"bg-brand":"bg-line")}),jsx7(Tag,{...onPick?{type:"button",onClick:()=>onPick(s.key)}:{},"aria-current":isCurrent?"step":void 0,className:cn("size-8 rounded-full flex items-center justify-center shrink-0 border-2 transition-colors",on?"bg-brand border-brand text-white":"bg-surface border-border text-muted",onPick&&"cursor-pointer hover:border-brand"),children:on?jsxs7(Fragment,{children:[jsx7(Check2,{size:15,strokeWidth:3,"aria-hidden":"true"}),jsx7("span",{className:"sr-only",children:"\u0645\u0643\u062A\u0645\u0644\u0629"})]}):jsx7("span",{"data-num":true,className:"text-caption font-extrabold",children:i+1})}),jsx7("span",{"aria-hidden":"true",className:cn("h-0.5 flex-1 rounded-full",last?"bg-transparent":on?"bg-brand":"bg-line")})]}),jsx7("span",{className:cn("text-caption font-bold text-center leading-tight [text-wrap:balance]",on?"text-ink":"text-muted"),children:s.title})]},s.key)})})}import{Star}from"lucide-react";import{jsx as jsx8,jsxs as jsxs8}from"react/jsx-runtime";var MAX=5;function Stars({value,size=13,className}){const n=Math.max(0,Math.min(MAX,Math.round(value)));return jsxs8("span",{className:cn("flex items-center gap-0.5 shrink-0",className),children:[jsx8("span",{className:"sr-only",children:`${n} / ${MAX}`}),Array.from({length:MAX},(_,i)=>jsx8(Star,{size,"aria-hidden":"true",className:cn("shrink-0",i<n?"fill-amber text-amber":"text-muted2")},i))]})}function RatingInput({value,onChange,disabled,hideValue,className}){const ui=useUIText();return jsxs8("span",{className:cn("flex items-center gap-1",className),children:[Array.from({length:MAX},(_,i)=>{const n=i+1;return jsx8("button",{type:"button",disabled,"aria-pressed":value===n,"aria-label":`${n} / ${MAX} \u2014 ${ui.rating}`,onClick:()=>onChange(n),className:cn("size-9 rounded-sm flex items-center justify-center transition-colors","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",disabled?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-hover"),children:jsx8(Star,{size:22,"aria-hidden":"true",className:cn("shrink-0",n<=value?"fill-amber text-amber":"text-muted2")})},n)}),!hideValue&&value>0&&jsx8("span",{"data-numeric":true,className:"ms-2 text-caption font-bold text-muted",children:`${value}/${MAX}`})]})}import{useMemo as useMemo2,useState as useState5}from"react";import{ChevronLeft,ChevronRight}from"lucide-react";import{jsx as jsx9,jsxs as jsxs9}from"react/jsx-runtime";var MONTHS_AR=["\u064A\u0646\u0627\u064A\u0631","\u0641\u0628\u0631\u0627\u064A\u0631","\u0645\u0627\u0631\u0633","\u0623\u0628\u0631\u064A\u0644","\u0645\u0627\u064A\u0648","\u064A\u0648\u0646\u064A\u0648","\u064A\u0648\u0644\u064A\u0648","\u0623\u063A\u0633\u0637\u0633","\u0633\u0628\u062A\u0645\u0628\u0631","\u0623\u0643\u062A\u0648\u0628\u0631","\u0646\u0648\u0641\u0645\u0628\u0631","\u062F\u064A\u0633\u0645\u0628\u0631"];var WEEKDAYS_AR=["\u0633","\u062D","\u0646","\u062B","\u0631","\u062E","\u062C"];var weekIndex=d=>(d.getDay()+1)%7;var sameDay=(a,b)=>a.getFullYear()===b.getFullYear()&&a.getMonth()===b.getMonth()&&a.getDate()===b.getDate();var startOfDay=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate());function daysBetween(from,to){return Math.round((startOfDay(to).getTime()-startOfDay(from).getTime())/864e5)+1}function formatDate(d){return`${d.getDate()} ${MONTHS_AR[d.getMonth()]}`}function formatRange(r){if(!r.from)return"\u0627\u062E\u062A\u0631 \u064A\u0648\u0645 \u0627\u0644\u0628\u062F\u0627\u064A\u0629";if(!r.to)return`${formatDate(r.from)} \u2014 \u0627\u062E\u062A\u0631 \u064A\u0648\u0645 \u0627\u0644\u0646\u0647\u0627\u064A\u0629`;if(sameDay(r.from,r.to))return formatDate(r.from);return`${formatDate(r.from)} \u2014 ${formatDate(r.to)}`}function presets(today){const mk=backDays=>{const to=startOfDay(today);const from=new Date(to);from.setDate(from.getDate()-backDays+1);return{from,to}};return[{key:"today",label:"\u0627\u0644\u0646\u0647\u0627\u0631\u062F\u0647",range:mk(1)},{key:"d7",label:"\u0622\u062E\u0631 \u0667 \u0623\u064A\u0627\u0645",range:mk(7)},{key:"d30",label:"\u0622\u062E\u0631 \u0663\u0660 \u064A\u0648\u0645",range:mk(30)},{key:"month",label:"\u0627\u0644\u0634\u0647\u0631 \u062F\u0647",range:{from:new Date(today.getFullYear(),today.getMonth(),1),to:startOfDay(today)}}]}function DateRangePicker({value,onChange,month,onMonthChange,today,className}){const ui=useUIText();const[hover,setHover]=useState5(null);const cells=useMemo2(()=>{const first=new Date(month.getFullYear(),month.getMonth(),1);const total=new Date(month.getFullYear(),month.getMonth()+1,0).getDate();const pad=weekIndex(first);return[...Array.from({length:pad},()=>null),...Array.from({length:total},(_,i)=>new Date(month.getFullYear(),month.getMonth(),i+1))]},[month]);const provisionalTo=value.from&&!value.to?hover:value.to;function inRange(d){if(!value.from||!provisionalTo)return false;const[a,b]=value.from<=provisionalTo?[value.from,provisionalTo]:[provisionalTo,value.from];return d>=startOfDay(a)&&d<=startOfDay(b)}function pick(d){if(!value.from||value.to)return onChange({from:d,to:null});if(d<value.from)return onChange({from:d,to:value.from});onChange({from:value.from,to:d})}const shift=by=>onMonthChange(new Date(month.getFullYear(),month.getMonth()+by,1));return jsxs9("div",{className:cn("flex flex-col gap-3",className),children:[jsxs9("div",{className:"flex items-center justify-between gap-3",children:[jsx9("button",{type:"button",onClick:()=>shift(-1),"aria-label":ui.previousMonth,className:"size-8 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx9(ChevronRight,{size:16,"aria-hidden":"true"})}),jsxs9("span",{className:"text-body font-extrabold text-ink",children:[MONTHS_AR[month.getMonth()]," ",jsx9("span",{"data-num":true,children:month.getFullYear()})]}),jsx9("button",{type:"button",onClick:()=>shift(1),"aria-label":ui.nextMonth,className:"size-8 rounded-sm flex items-center justify-center text-muted cursor-pointer transition-colors hover:bg-hover hover:text-ink",children:jsx9(ChevronLeft,{size:16,"aria-hidden":"true"})})]}),jsxs9("div",{className:"grid grid-cols-7 gap-0.5",role:"grid",children:[WEEKDAYS_AR.map((w,i)=>jsx9("span",{className:"h-7 flex items-center justify-center text-micro font-bold text-muted2",children:w},i)),cells.map((d,i)=>{if(!d)return jsx9("span",{},`p${i}`);const isFrom=value.from&&sameDay(d,value.from);const isTo=provisionalTo&&sameDay(d,provisionalTo);const edge=isFrom||isTo;const mid=inRange(d)&&!edge;const isToday=sameDay(d,today);return jsxs9("button",{type:"button",onClick:()=>pick(d),onMouseEnter:()=>setHover(d),"aria-pressed":Boolean(edge||mid),className:cn("h-9 flex items-center justify-center text-ui font-bold cursor-pointer transition-colors relative",mid&&"bg-soft text-brand-ink rounded-none",edge&&"bg-brand text-white rounded-sm z-10",!edge&&!mid&&"text-ink2 rounded-sm hover:bg-hover",isToday&&!edge&&"text-brand-ink"),children:[jsx9("span",{"data-num":true,children:d.getDate()}),isToday&&!edge&&jsx9("span",{"aria-hidden":"true",className:"absolute bottom-1 size-1 rounded-full bg-brand"})]},d.toISOString())})]})]})}import{useRef as useRef4,useState as useState6}from"react";import{AlertCircle,Check as Check3,Image as ImageIcon,Loader2 as Loader22,UploadCloud,X as X3}from"lucide-react";import{jsx as jsx10,jsxs as jsxs10}from"react/jsx-runtime";function formatBytes(bytes){if(bytes<1024)return`${bytes} \u0628\u0627\u064A\u062A`;if(bytes<1024*1024)return`${Math.round(bytes/1024)} \u0643.\u0628`;return`${(bytes/(1024*1024)).toFixed(1)} \u0645\u064A\u062C\u0627`}function Dropzone({onFiles,accept="image/*",multiple=true,disabled,title,hint,buttonLabel,className}){const ui=useUIText();const input=useRef4(null);const[over,setOver]=useState6(false);function take(list){if(!list||disabled)return;onFiles(Array.from(list))}function onDrop(e){e.preventDefault();setOver(false);take(e.dataTransfer.files)}return jsxs10("div",{onDragOver:e=>{e.preventDefault();if(!disabled)setOver(true)},onDragLeave:()=>setOver(false),onDrop,className:cn("flex flex-col items-center justify-center gap-2.5 px-5 py-9 rounded-card border-2 border-dashed transition-colors text-center",disabled&&"opacity-55 cursor-not-allowed border-border bg-bg",!disabled&&over&&"border-brand bg-soft",!disabled&&!over&&"border-border bg-bg hover:border-brand",className),children:[jsx10("span",{"aria-hidden":"true",className:cn("size-12 rounded-card flex items-center justify-center transition-colors",over?"bg-brand text-white":"bg-surface text-muted border border-line"),children:jsx10(UploadCloud,{size:22,strokeWidth:1.8})}),jsx10("span",{className:"text-body font-extrabold text-ink",children:title??ui.dropImages}),hint&&jsx10("span",{className:"text-caption leading-[1.7] text-muted max-w-note",children:hint}),jsx10("button",{type:"button",disabled,onClick:()=>input.current?.click(),className:"mt-1 h-9 px-4 rounded-sm bg-surface border border-border text-ui font-bold text-ink2 cursor-pointer transition-colors hover:border-brand hover:text-brand-ink disabled:cursor-not-allowed",children:buttonLabel??ui.chooseFromDevice}),jsx10("input",{ref:input,type:"file",accept,multiple,hidden:true,onChange:e=>{take(e.target.files);e.target.value=""}})]})}var STATE_STYLE={uploading:{box:"bg-soft text-brand-ink",icon:jsx10(Loader22,{size:13,className:"animate-spin","aria-hidden":"true"}),label:"\u062C\u0627\u0631\u064A \u0627\u0644\u0631\u0641\u0639"},done:{box:"bg-green-bg2 text-green",icon:jsx10(Check3,{size:13,"aria-hidden":"true"}),label:"\u062A\u0645 \u0627\u0644\u0631\u0641\u0639"},rejected:{box:"bg-red-bg text-red",icon:jsx10(AlertCircle,{size:13,"aria-hidden":"true"}),label:"\u0645\u0631\u0641\u0648\u0636"}};function FileRow({file,onRemove,coverLabel,isCover}){const s=STATE_STYLE[file.state];return jsxs10("div",{className:"flex items-center gap-3 p-2.5 rounded-card border border-line bg-surface",children:[jsxs10("span",{className:"relative size-11 rounded-sm overflow-clip bg-hover border border-line shrink-0",children:[file.preview?jsx10("img",{src:file.preview,alt:"",className:"w-full h-full object-cover"}):jsx10("span",{className:"w-full h-full flex items-center justify-center text-muted2",children:jsx10(ImageIcon,{size:17,"aria-hidden":"true"})}),isCover&&coverLabel&&jsx10("span",{className:"absolute inset-x-0 bottom-0 bg-brand/90 text-white text-micro font-extrabold text-center py-px",children:coverLabel})]}),jsxs10("span",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[jsxs10("span",{className:"flex items-center gap-2 min-w-0",children:[jsx10("span",{dir:"auto",className:"text-ui font-bold text-ink truncate",children:file.name}),jsxs10("span",{className:cn("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-micro font-extrabold shrink-0",s.box),children:[s.icon,s.label]})]}),file.state==="uploading"?jsx10("span",{className:"h-1 rounded-full bg-hover overflow-clip block",children:jsx10("span",{className:"block h-full rounded-full bg-brand transition-[width] duration-200",style:{width:`${file.progress??0}%`}})}):jsx10("span",{className:cn("text-caption",file.state==="rejected"?"text-red":"text-muted"),children:file.state==="rejected"?file.error:formatBytes(file.size)})]}),onRemove&&jsx10("button",{type:"button",onClick:onRemove,"aria-label":`\u0625\u0632\u0627\u0644\u0629 ${file.name}`,className:"shrink-0 size-8 rounded-sm flex items-center justify-center text-muted2 cursor-pointer transition-colors hover:bg-hover hover:text-red",children:jsx10(X3,{size:15,"aria-hidden":"true"})})]})}import{useCallback as useCallback2,useEffect as useEffect4,useLayoutEffect,useRef as useRef5,useState as useState7}from"react";import{jsx as jsx11}from"react/jsx-runtime";function reducedMotion(){return typeof window!=="undefined"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function useSortable({count,onMove,disabled,threshold=4,itemLabel}){const ui=useUIText();const nodes=useRef5([]);const rects=useRef5([]);const[dragging,setDragging]=useState7(null);const[over,setOver]=useState7(null);const[grabbed,setGrabbed]=useState7(null);const[message,setMessage]=useState7("");const run=useRef5({active:false,from:0,to:0,startY:0,dy:0,slot:0,raf:0,pointerId:-1});const overRef=useRef5(null);useEffect4(()=>{overRef.current=over},[over]);const detach=useRef5(null);const finishRef=useRef5(()=>{});const countRef=useRef5(count);useEffect4(()=>{countRef.current=count},[count]);const soft=!reducedMotion();const EASE="cubic-bezier(.2,.8,.2,1)";const measure=useCallback2(()=>{const list=nodes.current.slice(0,count);rects.current=list.map(el=>{const r=el?.getBoundingClientRect();return{top:r?.top??0,height:r?.height??0}});const gap=rects.current.length>1?Math.max(0,rects.current[1].top-(rects.current[0].top+rects.current[0].height)):0;return gap},[count]);const finish=useCallback2(()=>{const s=run.current;if(!s.active)return;s.active=false;cancelAnimationFrame(s.raf);detach.current?.();detach.current=null;const from=s.from;const to=overRef.current??from;const el=nodes.current[from];const settle=()=>{setDragging(null);setOver(null);overRef.current=null;if(el){el.style.transition="";el.style.removeProperty("--drag-y")}if(to!==from){onMove(from,to);setMessage(`${itemLabel?.(from)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0627\u0646\u062A\u0642\u0644 \u0625\u0644\u0649 \u0627\u0644\u0645\u0648\u0636\u0639 ${to+1} \u0645\u0646 ${count}.`)}};if(!el||!soft||to===from)return settle();const r=rects.current;const target=to>from?r[to].top+r[to].height-(r[from].top+r[from].height):r[to].top-r[from].top;el.style.transition=`transform 190ms ${EASE}`;el.style.setProperty("--drag-y",`${target}px`);window.setTimeout(settle,200)},[count,itemLabel,onMove,soft]);useEffect4(()=>{finishRef.current=finish},[finish]);const attach=useCallback2(()=>{function onPointerMove(e){const s=run.current;if(!s.active||e.pointerId!==s.pointerId)return;s.dy=e.clientY-s.startY;const r=rects.current;const n=countRef.current;const center=r[s.from].top+r[s.from].height/2+s.dy;let next=s.from;if(s.dy>0){for(let i=s.from+1;i<n;i++){if(center>r[i].top+r[i].height/2)next=i}}else{for(let i=s.from-1;i>=0;i--){if(center<r[i].top+r[i].height/2)next=i}}if(next!==overRef.current){overRef.current=next;setOver(next)}cancelAnimationFrame(s.raf);s.raf=requestAnimationFrame(()=>{nodes.current[s.from]?.style.setProperty("--drag-y",`${s.dy}px`)})}function onUp(e){if(e.pointerId!==run.current.pointerId)return;finishRef.current()}function onKey(e){if(e.key==="Escape"){overRef.current=run.current.from;finishRef.current()}}window.addEventListener("pointermove",onPointerMove,{passive:true});window.addEventListener("pointerup",onUp);window.addEventListener("pointercancel",onUp);window.addEventListener("keydown",onKey);detach.current=()=>{window.removeEventListener("pointermove",onPointerMove);window.removeEventListener("pointerup",onUp);window.removeEventListener("pointercancel",onUp);window.removeEventListener("keydown",onKey)}},[]);useEffect4(()=>()=>detach.current?.(),[]);useLayoutEffect(()=>{if(grabbed!==null)nodes.current[grabbed]?.focus()},[grabbed]);const item=useCallback2(index=>{const isDragged=dragging===index;const isGrabbed=grabbed===index;let shift=0;if(dragging!==null&&over!==null&&!isDragged){const slot=run.current.slot;if(over>dragging&&index>dragging&&index<=over)shift=-slot;else if(over<dragging&&index>=over&&index<dragging)shift=slot}const style=isDragged?{transform:"translate3d(0, var(--drag-y, 0px), 0)",position:"relative",zIndex:20,cursor:"grabbing",touchAction:"none",willChange:"transform"}:{transform:shift?`translate3d(0, ${shift}px, 0)`:void 0,transition:dragging!==null&&soft?`transform 160ms ${EASE}`:void 0,touchAction:disabled?void 0:"none"};return{ref:el=>{nodes.current[index]=el},style,tabIndex:disabled?-1:0,"aria-roledescription":ui.grabHint,"data-dragging":isDragged?"":void 0,"data-grabbed":isGrabbed?"":void 0,onPointerDown:e=>{if(disabled||e.button!==0)return;const startY=e.clientY;const el=e.currentTarget;const begin=ev=>{if(Math.abs(ev.clientY-startY)<threshold)return;window.removeEventListener("pointermove",begin);const gap=measure();const s=run.current;s.active=true;s.from=index;s.startY=startY;s.dy=ev.clientY-startY;s.slot=rects.current[index].height+gap;s.pointerId=ev.pointerId;el.setPointerCapture?.(ev.pointerId);el.style.setProperty("--drag-y",`${s.dy}px`);overRef.current=index;attach();setOver(index);setDragging(index);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0642\u064A\u062F \u0627\u0644\u062A\u062D\u0631\u064A\u0643.`)};const stop=()=>{window.removeEventListener("pointermove",begin);window.removeEventListener("pointerup",stop)};window.addEventListener("pointermove",begin);window.addEventListener("pointerup",stop)},onKeyDown:e=>{if(disabled)return;if(e.key===" "||e.key==="Enter"){e.preventDefault();if(grabbed===index){setGrabbed(null);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0627\u0633\u062A\u0642\u0631\u0651 \u0641\u064A \u0627\u0644\u0645\u0648\u0636\u0639 ${index+1}.`)}else{setGrabbed(index);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0645\u0645\u0633\u0648\u0643. \u062D\u0631\u0651\u0643\u0647 \u0628\u0627\u0644\u0623\u0633\u0647\u0645.`)}return}if(grabbed!==index)return;const dir=e.key==="ArrowUp"?-1:e.key==="ArrowDown"?1:0;if(dir){e.preventDefault();const to=index+dir;if(to<0||to>=count)return;onMove(index,to);setGrabbed(to);setMessage(`${itemLabel?.(index)??"\u0627\u0644\u0639\u0646\u0635\u0631"} \u0641\u064A \u0627\u0644\u0645\u0648\u0636\u0639 ${to+1} \u0645\u0646 ${count}.`)}if(e.key==="Escape"){e.preventDefault();setGrabbed(null);setMessage("\u0623\u064F\u0644\u063A\u064A \u0627\u0644\u062A\u062D\u0631\u064A\u0643.")}}}},[attach,count,disabled,dragging,grabbed,itemLabel,measure,onMove,over,soft,threshold,ui.grabHint]);return{item,dragging,grabbed,over,message}}function SortableStatus({message}){return jsx11("span",{role:"status","aria-live":"polite",className:"sr-only",children:message})}import{Children,useCallback as useCallback3,useEffect as useEffect5,useRef as useRef6,useState as useState8}from"react";import{ChevronLeft as ChevronLeft2,ChevronRight as ChevronRight2,Pause,Play,X as X4,ZoomIn}from"lucide-react";import{jsx as jsx12,jsxs as jsxs11}from"react/jsx-runtime";function axis(track){const rtl=getComputedStyle(track).direction==="rtl";return{rtl,start:r=>rtl?-r.right:r.left,end:r=>rtl?-r.left:r.right}}var EDGE=1;function readTrack(track){const slides=Array.from(track.children);if(slides.length===0)return{index:0,atStart:true,atEnd:true};const{start,end}=axis(track);const box=track.getBoundingClientRect();const from=start(box);let index=0;let best=Infinity;slides.forEach((el,i)=>{const d=start(el.getBoundingClientRect())-from;const score=d<0?-d:d;if(score<best){best=score;index=i}});return{index,atStart:start(slides[0].getBoundingClientRect())>=from-EDGE,atEnd:end(slides[slides.length-1].getBoundingClientRect())<=end(box)+EDGE}}function scrollToIndex(track,i,behavior){const el=track.children[i];if(!el)return;const{rtl}=axis(track);const box=track.getBoundingClientRect();const r=el.getBoundingClientRect();track.scrollBy({left:rtl?r.right-box.right:r.left-box.left,behavior})}function ease(){return typeof matchMedia!=="undefined"&&matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"}var BASIS="calc((100% - (var(--per) - 1) * var(--gap)) / var(--per))";function Carousel({label,children,perView,gap=12,arrows=true,dots=false,counter=false,autoplay,index,onIndexChange,className,trackClassName}){const en=useMoneyLang();const trackRef=useRef6(null);const[state,setState]=useState8({index:0,atStart:true,atEnd:true});const[paused,setPaused]=useState8(false);const[held,setHeld]=useState8(false);const slides=Children.toArray(children);const count=slides.length;const latest=useRef6(state);const notify=useRef6(onIndexChange);useEffect5(()=>{latest.current=state},[state]);useEffect5(()=>{notify.current=onIndexChange},[onIndexChange]);const measure=useCallback3(()=>{const track=trackRef.current;if(!track)return;const next=readTrack(track);setState(prev=>prev.index===next.index&&prev.atStart===next.atStart&&prev.atEnd===next.atEnd?prev:next)},[]);const target=useRef6(0);const go=useCallback3(to=>{const track=trackRef.current;if(!track)return;const i=Math.min(Math.max(to,0),track.children.length-1);target.current=i;scrollToIndex(track,i,ease())},[]);const first=useRef6(true);const told=useRef6(null);useEffect5(()=>{const track=trackRef.current;if(index==null||!track)return;if(index===told.current)return;target.current=index;scrollToIndex(track,index,first.current?"auto":ease())},[index]);useEffect5(()=>{const track=trackRef.current;if(!track)return;let frame=0;let idle;const onScroll=()=>{cancelAnimationFrame(frame);frame=requestAnimationFrame(measure);clearTimeout(idle);idle=setTimeout(()=>{const t=trackRef.current;if(t)target.current=readTrack(t).index},140)};track.addEventListener("scroll",onScroll,{passive:true});const ro=new ResizeObserver(onScroll);ro.observe(track);measure();first.current=false;return()=>{cancelAnimationFrame(frame);clearTimeout(idle);track.removeEventListener("scroll",onScroll);ro.disconnect()}},[measure,count]);useEffect5(()=>{if(told.current===state.index)return;const knew=told.current!==null;told.current=state.index;if(knew||state.index!==(index??0))notify.current?.(state.index)},[state.index,index]);useEffect5(()=>{if(!autoplay||paused||held||count<2)return;if(typeof matchMedia!=="undefined"&&matchMedia("(prefers-reduced-motion: reduce)").matches){return}const id=setInterval(()=>{const track=trackRef.current;if(!track||document.hidden)return;const now=latest.current;scrollToIndex(track,now.atEnd?0:now.index+1,ease())},autoplay);return()=>clearInterval(id)},[autoplay,paused,held,count]);function onKeyDown(e){const track=trackRef.current;if(!track)return;const{rtl}=axis(track);const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";const to=e.key===forward?target.current+1:e.key===back?target.current-1:e.key==="Home"?0:e.key==="End"?count-1:null;if(to===null)return;e.preventDefault();go(to)}const many=count>1;const showArrows=arrows&&many;const showBar=many&&(dots||counter||Boolean(autoplay));const arrow=back=>jsx12("button",{type:"button",disabled:back?state.atStart:state.atEnd,"aria-label":back?en?"Previous":"\u0627\u0644\u0633\u0627\u0628\u0642":en?"Next":"\u0627\u0644\u062A\u0627\u0644\u064A",onClick:()=>go(back?target.current-1:target.current+1),className:cn("absolute top-1/2 -translate-y-1/2 z-10 size-9 rounded-full flex items-center justify-center","bg-surface/92 backdrop-blur border border-line shadow-pop text-ink2","transition-opacity cursor-pointer hover:text-brand-ink","disabled:opacity-0 disabled:pointer-events-none",back?"start-2":"end-2"),children:back?jsx12(ChevronRight2,{size:17,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"}):jsx12(ChevronLeft2,{size:17,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"})});return jsxs11("section",{"aria-roledescription":en?"carousel":"\u0639\u0627\u0631\u0636 \u0634\u0631\u0627\u0626\u062D","aria-label":label,onPointerEnter:()=>autoplay&&setHeld(true),onPointerLeave:()=>autoplay&&setHeld(false),onFocusCapture:()=>autoplay&&setHeld(true),onBlurCapture:()=>autoplay&&setHeld(false),className:cn("flex flex-col gap-3 [--per:1]",className),style:{"--gap":`${gap}px`,...perView===void 0?null:{"--per":String(perView)}},children:[jsxs11("div",{className:"relative",children:[jsx12("div",{ref:trackRef,tabIndex:0,role:"group","aria-label":en?"Slides":"\u0627\u0644\u0634\u0631\u0627\u0626\u062D",onKeyDown,className:cn("flex overflow-x-auto overscroll-x-contain snap-x snap-mandatory","[scrollbar-width:none] [&::-webkit-scrollbar]:hidden","rounded-card focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",trackClassName),style:{gap:"var(--gap)"},children:slides.map((slide,i)=>jsx12("div",{role:"group","aria-roledescription":en?"slide":"\u0634\u0631\u064A\u062D\u0629","aria-label":en?`${i+1} of ${count}`:`${i+1} \u0645\u0646 ${count}`,className:"snap-start shrink-0 grow-0 min-w-0 relative",style:{flexBasis:BASIS},children:slide},i))}),showArrows&&arrow(true),showArrows&&arrow(false)]}),showBar&&jsxs11("div",{className:"flex items-center justify-center gap-3",children:[autoplay&&jsx12("button",{type:"button",onClick:()=>setPaused(p=>!p),"aria-label":paused?en?"Start auto-rotation":"\u0634\u063A\u0651\u0644 \u0627\u0644\u062A\u0628\u062F\u064A\u0644 \u0627\u0644\u062A\u0644\u0642\u0627\u0626\u064A":en?"Stop auto-rotation":"\u0623\u0648\u0642\u0641 \u0627\u0644\u062A\u0628\u062F\u064A\u0644 \u0627\u0644\u062A\u0644\u0642\u0627\u0626\u064A",className:"size-7 rounded-full flex items-center justify-center text-muted hover:bg-hover hover:text-ink transition-colors cursor-pointer",children:paused?jsx12(Play,{size:13,"aria-hidden":"true"}):jsx12(Pause,{size:13,"aria-hidden":"true"})}),dots&&jsx12("span",{className:"flex items-center gap-1.5",children:slides.map((_,i)=>jsx12("button",{type:"button",onClick:()=>go(i),"aria-label":en?`Go to slide ${i+1}`:`\u0627\u0630\u0647\u0628 \u0644\u0644\u0634\u0631\u064A\u062D\u0629 ${i+1}`,"aria-current":i===state.index||void 0,className:cn("h-1.5 rounded-full transition-all duration-200 cursor-pointer","before:absolute before:-inset-2 relative",i===state.index?"w-5 bg-brand":"w-1.5 bg-border hover:bg-muted2")},i))}),counter&&jsxs11("span",{dir:"ltr","data-num":true,"aria-live":autoplay?void 0:"polite",className:"text-caption font-bold text-muted tabular-nums",children:[state.index+1," / ",count]})]})]})}function Gallery({label,images,ratio="4/3",fit="cover",thumbs=true,zoom=true,className}){const en=useMoneyLang();const[index,setIndex]=useState8(0);const[open,setOpen]=useState8(false);const activeThumb=useRef6(null);useEffect5(()=>{activeThumb.current?.scrollIntoView({inline:"nearest",block:"nearest",behavior:ease()})},[index]);if(images.length===0)return null;const frame={aspectRatio:ratio};const img=(im,decorative)=>jsx12("img",{src:im.src,alt:decorative?"":im.alt,loading:"lazy",decoding:"async",draggable:false,className:cn("w-full h-full",fit==="cover"?"object-cover":"object-contain")});return jsxs11("div",{className:cn("flex flex-col gap-2.5",className),children:[jsx12(Carousel,{label,index,onIndexChange:setIndex,counter:images.length>1,dots:!thumbs&&images.length>1,gap:8,children:images.map((im,i)=>zoom?jsxs11("button",{type:"button",onClick:()=>setOpen(true),"aria-label":`${im.alt} \u2014 ${en?"open viewer":"\u0641\u062A\u062D \u0627\u0644\u0639\u0627\u0631\u0636"}`,style:frame,className:"group relative block w-full overflow-clip rounded-card bg-hover cursor-zoom-in",children:[img(im,true),jsx12("span",{"aria-hidden":"true",className:"absolute top-2 end-2 size-7 rounded-full bg-black/45 backdrop-blur text-white flex items-center justify-center opacity-70 transition-opacity group-hover:opacity-100",children:jsx12(ZoomIn,{size:14})})]},i):jsx12("div",{style:frame,className:"overflow-clip rounded-card bg-hover",children:img(im,false)},i))}),thumbs&&images.length>1&&jsx12("div",{role:"group","aria-label":en?"Thumbnails":"\u0627\u0644\u0645\u0635\u063A\u0651\u0631\u0627\u062A",className:"flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:images.map((im,i)=>jsx12("button",{ref:i===index?activeThumb:void 0,type:"button",onClick:()=>setIndex(i),"aria-current":i===index||void 0,"aria-label":en?`Image ${i+1}`:`\u0627\u0644\u0635\u0648\u0631\u0629 ${i+1}`,className:cn("shrink-0 size-14 rounded-sm overflow-clip border-2 bg-hover cursor-pointer transition-colors",i===index?"border-brand":"border-line hover:border-border"),children:jsx12("img",{src:im.src,alt:"",loading:"lazy",decoding:"async",draggable:false,className:"w-full h-full object-cover"})},i))}),zoom&&jsx12(Lightbox,{open,images,index,onIndexChange:setIndex,onClose:()=>setOpen(false),label})]})}function Lightbox({open,images,index,onIndexChange,onClose,label,closeLabel}){const ui=useUIText();const en=useMoneyLang();const panel=useRef6(null);const count=images.length;useEffect5(()=>{if(!open)return;const from=document.activeElement;panel.current?.focus();return()=>from?.focus?.()},[open]);useEffect5(()=>{if(!open)return;function onKey(e){const rtl=getComputedStyle(document.documentElement).direction==="rtl";const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";if(e.key==="Escape")onClose();else if(e.key===forward)onIndexChange(Math.min(index+1,count-1));else if(e.key===back)onIndexChange(Math.max(index-1,0));else if(e.key==="Home")onIndexChange(0);else if(e.key==="End")onIndexChange(count-1)}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,index,count,onClose,onIndexChange]);if(!open||count===0)return null;const current=images[Math.min(Math.max(index,0),count-1)];const step=back=>jsx12("button",{type:"button",disabled:back?index===0:index>=count-1,onClick:()=>onIndexChange(back?index-1:index+1),"aria-label":back?en?"Previous":"\u0627\u0644\u0633\u0627\u0628\u0642":en?"Next":"\u0627\u0644\u062A\u0627\u0644\u064A",className:cn("absolute top-1/2 -translate-y-1/2 z-10 size-11 rounded-full flex items-center justify-center","bg-white/10 backdrop-blur text-white transition-opacity cursor-pointer hover:bg-white/20","disabled:opacity-0 disabled:pointer-events-none",back?"start-3":"end-3"),children:back?jsx12(ChevronRight2,{size:20,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"}):jsx12(ChevronLeft2,{size:20,className:"rtl:rotate-0 ltr:rotate-180","aria-hidden":"true"})});return jsxs11("div",{ref:panel,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":label??(en?"Image viewer":"\u0639\u0627\u0631\u0636 \u0627\u0644\u0635\u0648\u0631"),className:"fixed inset-0 z-50 bg-night/95 flex flex-col animate-[fade-in_0.18s_ease-out] outline-none",children:[jsxs11("header",{className:"shrink-0 h-14 px-4 flex items-center justify-between gap-3",children:[jsxs11("span",{dir:"ltr","data-num":true,className:"text-caption font-bold text-white/70 tabular-nums",children:[index+1," / ",count]}),jsx12("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:"size-9 rounded-full bg-white/10 backdrop-blur flex items-center justify-center text-white transition-colors cursor-pointer hover:bg-white/20",children:jsx12(X4,{size:18,"aria-hidden":"true"})})]}),jsxs11("div",{className:"relative flex-1 min-h-0 flex items-center justify-center p-4 pb-8",children:[jsx12("img",{src:current.src,alt:current.alt,decoding:"async",draggable:false,className:"max-w-full max-h-full object-contain rounded-card animate-qfade"},current.src),count>1&&step(true),count>1&&step(false)]})]})}import{useEffect as useEffect6,useLayoutEffect as useLayoutEffect2,useRef as useRef7,useState as useState9}from"react";import{ChevronLeft as ChevronLeft3,ChevronRight as ChevronRight3,Lock,RotateCw,Signal,Wifi}from"lucide-react";import{jsx as jsx13,jsxs as jsxs12}from"react/jsx-runtime";function BrowserFrame({url,device="desktop",tab,nav,loading,contentWidth,onScale,onReload,children,className}){const ui=useUIText();const mobile=device==="mobile";const viewport=useRef7(null);const[scale,setScale]=useState9(1);const[rtl,setRtl]=useState9(true);useLayoutEffect2(()=>{const box=viewport.current;if(!box||!contentWidth)return setScale(1);setRtl(getComputedStyle(box).direction==="rtl");const read=()=>{const w=box.clientWidth;setScale(w>0?Math.min(1,w/contentWidth):1)};read();const ro=new ResizeObserver(read);ro.observe(box);return()=>ro.disconnect()},[contentWidth]);useEffect6(()=>{onScale?.(scale)},[scale,onScale]);const control="shrink-0 size-6 rounded-full flex items-center justify-center transition-colors";return jsxs12("div",{className:cn("flex flex-col overflow-clip bg-surface border border-line shadow-panel",mobile?"rounded-[30px] border-[7px] border-night":"rounded-lg",className),children:[mobile&&jsxs12("div",{className:"shrink-0 h-7 px-5 flex items-center justify-between bg-bg","aria-hidden":"true",children:[jsxs12("span",{className:"flex items-center gap-1 text-muted2",children:[jsx13(Signal,{size:11}),jsx13(Wifi,{size:11}),jsx13("span",{className:"w-4 h-2 rounded-[2px] border border-muted2"})]}),jsx13("span",{className:"w-16 h-4 rounded-full bg-night"})]}),tab&&!mobile&&jsx13("div",{className:"shrink-0 flex items-end gap-1 px-2.5 pt-2 bg-bg border-b border-line",children:jsxs12("span",{className:"flex items-center gap-2 h-8 max-w-[220px] px-3 rounded-t-sm bg-surface border border-line border-b-0",children:[jsx13("span",{"aria-hidden":"true",className:"size-3 rounded-[3px] bg-soft2 shrink-0"}),jsx13("span",{className:"text-micro text-ink2 truncate",children:tab})]})}),jsxs12("div",{className:cn("relative shrink-0 flex items-center gap-2 bg-bg border-b border-line",mobile?"px-2.5 py-2":"px-3 py-2.5"),children:[!mobile&&!tab&&jsx13("span",{"aria-hidden":"true",className:"flex items-center gap-1.5 shrink-0 me-1",children:[0,1,2].map(i=>jsx13("span",{className:"size-2.5 rounded-full bg-line border border-border/40"},i))}),nav&&!mobile&&jsxs12("span",{className:"flex items-center gap-0.5 shrink-0 text-muted2/60",children:[jsx13("span",{className:cn(control,"cursor-not-allowed"),"aria-hidden":"true",children:jsx13(ChevronRight3,{size:13})}),jsx13("span",{className:cn(control,"cursor-not-allowed"),"aria-hidden":"true",children:jsx13(ChevronLeft3,{size:13})})]}),jsxs12("span",{className:cn("flex-1 min-w-0 flex items-center gap-1.5 rounded-full bg-surface border border-line",mobile?"h-6 px-2.5":"h-7 px-3"),children:[jsx13(Lock,{size:mobile?9:10,className:"text-green shrink-0","aria-hidden":"true"}),jsx13(TechnicalText,{className:cn("truncate text-muted",mobile?"text-[9.5px]":"text-micro"),children:url})]}),onReload&&!mobile&&jsx13("button",{type:"button",onClick:onReload,"aria-label":ui.reloadPreview,className:cn(control,"text-muted2 hover:bg-hover hover:text-ink cursor-pointer"),children:jsx13(RotateCw,{size:12,"aria-hidden":"true",className:cn(loading&&"animate-spin")})}),loading&&jsx13("span",{"aria-hidden":"true",className:"absolute bottom-0 inset-x-0 h-[2px] overflow-clip",children:jsx13("span",{className:"absolute top-0 h-full w-[35%] bg-brand animate-[qload_1.1s_ease-in-out_infinite]"})})]}),jsx13("div",{ref:viewport,className:"relative flex-1 min-h-0 overflow-clip bg-surface",children:contentWidth?jsx13("div",{style:{width:contentWidth,height:`${100/scale}%`,transform:`scale(${scale})`,transformOrigin:`top ${rtl?"right":"left"}`},children}):children}),mobile&&jsx13("span",{"aria-hidden":"true",className:"shrink-0 h-4 bg-bg flex items-center justify-center",children:jsx13("span",{className:"w-24 h-1 rounded-full bg-border/50"})})]})}import"react";import{jsx as jsx14,jsxs as jsxs13}from"react/jsx-runtime";var clamp=(v,lo=0,hi=100)=>Math.min(hi,Math.max(lo,v));var signedString=v=>(v<0?"\u2212":"")+String(Math.abs(v));function WaterfallChart({total,steps,totalLabel,netLabel,formatValue=signedString,className}){const ui=useUIText();const top=Math.max(1,total);const bars=steps.reduce((acc,s)=>{const from=acc.length?acc[acc.length-1].to:total;acc.push({...s,from,to:from+s.value});return acc},[]);const net=bars.length?bars[bars.length-1].to:total;const biggest=bars.reduce((acc,b,i)=>b.value<acc.v?{i,v:b.value}:acc,{i:-1,v:0});return jsxs13("div",{className:cn("flex flex-col",className),children:[jsx14(Line,{label:totalLabel??ui.totalSales,value:total,formatValue,strong:true,children:jsx14("span",{className:"block h-2.5 rounded-full bg-brand"})}),bars.map((b,i)=>{const drop=b.value<0;const lo=clamp(Math.min(b.from,b.to)/top*100);const span=clamp(Math.abs(b.value)/top*100);const worst=i===biggest.i;return jsx14(Line,{label:b.label,meta:b.meta,value:b.value,formatValue,flag:worst?"\u0623\u0643\u0628\u0631 \u062E\u0635\u0645":void 0,children:jsx14("span",{dir:"ltr",className:"relative block h-2.5 rounded-full bg-hover overflow-clip",children:jsx14("span",{className:cn("absolute inset-y-0 rounded-full",drop?worst?"bg-danger":"bg-brand-100":"bg-green-solid"),style:{insetInlineStart:`${lo}%`,width:`${span}%`}})})},b.key)}),jsx14(Line,{label:netLabel??ui.netToYou,value:net,formatValue,strong:true,net:true,children:jsx14("span",{dir:"ltr",className:"block h-2.5 rounded-full bg-hover overflow-clip",children:jsx14("span",{className:"block h-full rounded-full bg-green-solid",style:{width:`${clamp(net/top*100)}%`}})})})]})}function Line({label,meta,value,formatValue,flag,strong,net,children}){return jsxs13("div",{className:cn("flex flex-col gap-1.5 py-2.5",net&&"border-t border-line mt-1 pt-3.5"),children:[jsxs13("span",{className:"flex items-baseline justify-between gap-3",children:[jsxs13("span",{className:"flex items-baseline gap-2 min-w-0",children:[jsx14("span",{className:cn("truncate",strong?"text-ui font-extrabold text-ink":"text-ui text-muted"),children:label}),flag&&jsx14("span",{className:"shrink-0 text-micro font-bold text-red bg-red-bg px-1.5 py-0.5 rounded-mark",children:flag})]}),jsx14("span",{"data-num":true,className:cn("shrink-0",strong?"text-body font-black text-ink":"text-ui font-bold text-ink2"),children:formatValue(value)})]}),children,meta&&jsx14("span",{className:"text-micro text-muted2",children:meta})]})}function GoalBar({value,goal,pace,label,formatValue=String,className}){const ui=useUIText();const top=Math.max(value,goal)*1.06;const pct=clamp(value/top*100);const goalAt=clamp(goal/top*100);const paceAt=pace===void 0?null:clamp(goalAt*clamp(pace,0,1));const behind=paceAt!==null&&pct<paceAt;return jsxs13("div",{className:cn("flex flex-col gap-2",className),children:[jsxs13("span",{className:"flex items-baseline justify-between gap-3",children:[label&&jsx14("span",{className:"text-ui font-bold text-ink2 truncate",children:label}),jsxs13("span",{className:"flex items-baseline gap-1.5 shrink-0",children:[jsx14("span",{"data-num":true,className:"text-body font-black text-ink",children:formatValue(value)}),jsxs13("span",{className:"text-micro text-muted2",children:["\u0645\u0646 ",jsx14("span",{"data-num":true,children:formatValue(goal)})]})]})]}),jsxs13("span",{dir:"ltr",className:"relative block h-3 rounded-full bg-hover",children:[jsx14("span",{className:cn("absolute inset-y-0 start-0 rounded-full transition-[width] duration-500",behind?"bg-amber":"bg-brand"),style:{width:`${pct}%`}}),paceAt!==null&&jsx14("span",{"aria-hidden":"true",title:ui.shouldBeHere,className:"absolute -top-1 -bottom-1 w-0.5 bg-muted2 rounded-full",style:{insetInlineStart:`${paceAt}%`}}),jsx14("span",{"aria-hidden":"true",className:"absolute -top-1.5 -bottom-1.5 w-1 bg-ink rounded-full",style:{insetInlineStart:`${goalAt}%`}})]}),paceAt!==null&&jsx14("span",{className:cn("text-micro",behind?"text-amber-ink":"text-muted2"),children:behind?"\u0648\u0631\u0627 \u0627\u0644\u0625\u064A\u0642\u0627\u0639 \u0627\u0644\u0645\u0637\u0644\u0648\u0628":"\u0642\u062F\u0651\u0627\u0645 \u0627\u0644\u0625\u064A\u0642\u0627\u0639 \u0627\u0644\u0645\u0637\u0644\u0648\u0628"})]})}function ParetoChart({items,height=140,threshold=80,formatValue=String,className}){const sorted=[...items].sort((a,b)=>b.value-a.value);const sum=sorted.reduce((s,i)=>s+i.value,0)||1;const top=Math.max(1,sorted[0]?.value??1);const rows=sorted.reduce((out,it)=>{const acc=(out.length?out[out.length-1].cum*sum/100:0)+it.value;out.push({...it,cum:acc/sum*100});return out},[]);const vital=rows.findIndex(r=>r.cum>=threshold)+1;return jsxs13("div",{className:cn("flex flex-col gap-2.5",className),children:[jsxs13("span",{className:"text-caption text-muted [text-wrap:pretty]",children:[jsx14("span",{"data-num":true,className:"font-extrabold text-ink",children:vital})," ","\u0645\u0646"," ",jsx14("span",{"data-num":true,className:"font-extrabold text-ink",children:rows.length})," ","\u0628\u064A\u0639\u0645\u0644\u0648\u0627"," ",jsx14("span",{"data-num":true,className:"font-extrabold text-ink",children:threshold}),"\u066A \u0645\u0646 \u0627\u0644\u0625\u062C\u0645\u0627\u0644\u064A"]}),jsxs13("div",{className:"relative flex items-end gap-1.5",style:{height},children:[jsx14("span",{"aria-hidden":"true",className:"absolute inset-x-0 border-t border-dashed border-muted2",style:{top:`${100-threshold}%`}}),rows.map((r,i)=>jsx14("span",{className:"flex-1 min-w-0 flex flex-col justify-end items-center gap-1 h-full",children:jsx14("span",{title:`${String(r.label)} \xB7 ${formatValue(r.value)}`,className:cn("w-full rounded-t-mark transition-[height] duration-500",i<vital?"bg-brand":"bg-brand-100"),style:{height:`${clamp(r.value/top*100)}%`}})},r.key))]}),jsx14("div",{className:"flex items-center gap-1.5",children:rows.map((r,i)=>jsx14("span",{className:cn("flex-1 min-w-0 text-micro text-center truncate",i<vital?"text-ink2 font-bold":"text-muted2"),children:r.label},r.key))})]})}function StockRunway({items,urgentDays=7,horizonDays=30,className}){const rows=items.map(it=>({...it,days:it.perDay>0?it.stock/it.perDay:Infinity})).sort((a,b)=>a.days-b.days);return jsx14("div",{className:cn("flex flex-col gap-2.5",className),children:rows.map(r=>{const urgent=r.days<=urgentDays;const soon=!urgent&&r.days<=horizonDays/2;const pct=Number.isFinite(r.days)?clamp(r.days/horizonDays*100):100;return jsxs13("span",{className:"flex flex-col gap-1.5",children:[jsxs13("span",{className:"flex items-baseline justify-between gap-3",children:[jsx14("span",{className:"text-ui text-ink2 truncate min-w-0",children:r.label}),jsxs13("span",{className:"flex items-baseline gap-2 shrink-0",children:[jsxs13("span",{"data-num":true,className:"text-micro text-muted2",children:[r.stock," \u0642\u0637\u0639\u0629"]}),jsx14("span",{"data-num":true,className:cn("text-ui font-extrabold",urgent?"text-red":soon?"text-amber-ink":"text-ink"),children:Number.isFinite(r.days)?`${Math.floor(r.days)} \u064A\u0648\u0645`:"\u2014"})]})]}),jsx14("span",{dir:"ltr",className:"block h-1.5 rounded-full bg-hover overflow-clip",children:jsx14("span",{className:cn("block h-full rounded-full transition-[width] duration-500",urgent?"bg-danger":soon?"bg-amber":"bg-brand"),style:{width:`${pct}%`}})})]},r.key)})})}import{BadgeCheck}from"lucide-react";import{jsx as jsx15}from"react/jsx-runtime";var PROVIDER_LEVEL_LABEL={1:"\u0645\u0642\u062F\u0651\u0645 \u062C\u062F\u064A\u062F",2:"\u0645\u0642\u062F\u0651\u0645 \u0645\u062D\u062A\u0631\u0641",3:"\u0645\u0642\u062F\u0651\u0645 \u062E\u0628\u064A\u0631"};var PROVIDER_LEVEL_LABEL_EN={1:"New provider",2:"Pro provider",3:"Expert provider"};var CHEVRONS=[1.7,6,10.3];var DIM=.28;function ProviderMark({level,size=16,className}){return jsx15("svg",{width:size,height:size,viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:cn("shrink-0",className),children:CHEVRONS.map((y,i)=>jsx15("path",{d:`M3.2 ${y+4}L8 ${y}L12.8 ${y+4}`,stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",opacity:i>=CHEVRONS.length-level?1:DIM},y))})}var LEVEL_TONE={1:"bg-hover text-ink2",2:"bg-soft text-brand-ink",3:TONE_SOLID.brand};var SIZES={sm:{box:"size-6",mark:14},md:{box:"size-7",mark:16}};function MarkChip({label,size,tone,className,children}){return jsx15(Tooltip,{content:label,children:jsx15("span",{role:"img","aria-label":label,tabIndex:0,className:cn("inline-flex items-center justify-center rounded-sm shrink-0 cursor-pointer","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",SIZES[size].box,tone,className),children})})}function ProviderBadge({level,size="sm",className}){const en=useMoneyLang();const label=en?PROVIDER_LEVEL_LABEL_EN[level]:PROVIDER_LEVEL_LABEL[level];return jsx15(MarkChip,{label,size,tone:LEVEL_TONE[level],className,children:jsx15(ProviderMark,{level,size:SIZES[size].mark})})}var VERIFIED_LABEL="\u062D\u0633\u0627\u0628 \u0645\u0648\u062B\u0651\u0642";var VERIFIED_LABEL_EN="Verified account";function VerifiedBadge({size="sm",className}){const en=useMoneyLang();return jsx15(MarkChip,{label:en?VERIFIED_LABEL_EN:VERIFIED_LABEL,size,tone:TONE_SOFT.green,className,children:jsx15(BadgeCheck,{size:SIZES[size].mark,strokeWidth:2,"aria-hidden":"true"})})}export{ANIMATE_SCALE,Accordion,Alert,AudioPlayer,Avatar,Badge,BarChart,BrowserFrame,Button,COLOR_SCALE,CONTAINER_SCALE,Card,CardHeader,Carousel,Checkbox,ChoiceCards,Coach,CoachProvider,ColorField,Combobox,CommandPalette,Counter,DARK_TOKENS,DataTable,DateRangePicker,Drawer,Dropdown,Dropzone,EmptyState,FileRow,FilterChips,FunnelChart,Gallery,GoalBar,Heatmap,Input,Lightbox,LocaleCtx,Modal,Money,MoneyProvider,MultiSelect,NumberStepper,PROVIDER_LEVEL_LABEL,PROVIDER_LEVEL_LABEL_EN,PageHeader,ParetoChart,Phone,Product3DViewer,Progress,ProviderBadge,ProviderMark,RADIUS_SCALE,Radio,RadioGroup,RatingInput,SHADOW_SCALE,Scrubber,SearchInput,Select,ShareList,Sheet,Skeleton,SortableStatus,Sparkline,Stars,StatCard,Stepper,StockRunway,Switch,TEXT_SCALE,TOKENS,TONE_SOFT,TONE_SOLID,Tabs,TechnicalInput,TechnicalText,Textarea,Timeline,Toast,ToastHost,Tooltip,TrendChart,VerifiedBadge,VideoPlayer,WaterfallChart,WhatsAppIcon,buttonClasses,cn,coachSeconds,currencyName,currencySymbol,daysBetween,formatBytes,formatDate,formatRange,formatTime,isCurrency,normalizeHex,parsePhone,presets,toLatinDigits,useAudioLevel,useCoach,useCoachOptional,useCurrency,useCurrencySymbol,useMedia,useMoneyLang,useMoneyLocale,useSortable,useToasts,useUIText};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qumra/fanar",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "description": "Qumra's Arabic-first component library and design tokens. Tailwind 4, RSC-safe.",
6
6
  "license": "UNLICENSED",
@@ -1,2 +0,0 @@
1
- "use client";
2
- import{Coach,useCoachOptional}from"./chunk-GMIBQMMR.js";import{LocaleCtx,cn,useMoneyLocale,useUIText}from"./chunk-ZE4S6DBP.js";import{createContext,useContext}from"react";import{Fragment,jsx,jsxs}from"react/jsx-runtime";function Glyph({children,label,w=24}){return jsx("svg",{viewBox:`0 0 ${w} 24`,width:`${w/24}em`,height:"1em",fill:"none",stroke:"currentColor",strokeWidth:2.1,strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":label,className:"inline-block shrink-0 translate-y-[0.1em]",children})}var Dollar=jsxs(Glyph,{label:"\u062F\u0648\u0644\u0627\u0631",children:[jsx("path",{d:"M12 2.5v19"}),jsx("path",{d:"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"})]});var Euro=jsxs(Glyph,{label:"\u064A\u0648\u0631\u0648",children:[jsx("path",{d:"M17.5 6.4A7 7 0 1 0 17.5 17.6"}),jsx("path",{d:"M3.5 10h10"}),jsx("path",{d:"M3.5 14h10"})]});var Pound=jsxs(Glyph,{label:"\u062C\u0646\u064A\u0647",children:[jsx("path",{d:"M16 6.2A3.7 3.7 0 0 0 9 7.8v6.4a5 5 0 0 1-2 4h11"}),jsx("path",{d:"M6 12h7"})]});var EgyptianPound=jsxs(Glyph,{label:"\u062C\u0646\u064A\u0647 \u0645\u0635\u0631\u064A",w:31,children:[jsx("path",{d:"M10.5 6H3.5v12h7"}),jsx("path",{d:"M3.5 12h5.5"}),jsx("path",{d:"M26.5 6.2A3.7 3.7 0 0 0 19.5 7.8v6.4a5 5 0 0 1-2 4h11"}),jsx("path",{d:"M16.5 12h7"})]});var Riyal=jsx("svg",{viewBox:"0 0 24 24",width:"1em",height:"1em",fill:"currentColor",role:"img","aria-label":"\u0631\u064A\u0627\u0644 \u0633\u0639\u0648\u062F\u064A",className:"inline-block shrink-0 translate-y-[0.08em]",children:jsx("path",{d:"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 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:EgyptianPound,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!!c&&c in CURRENCY}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 resolve(style,c,locale){if(style!=="best")return style;if(locale.startsWith("ar"))return c.best;return c.sign?"sign":"code"}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"};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 unit=style==="code"?c.code:style==="word"?c.word:style==="sign"?c.sign??c.short:c.short;return jsxs("span",{className:cn("inline-flex items-baseline gap-1 whitespace-nowrap",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("opacity-65",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:"text-[0.82em] text-muted2 line-through decoration-1",children:jsx("span",{"data-num":true,children:format(was,decimals,locale,{compact,trimZeros})})})]})}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 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??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";import{Fragment as Fragment2,jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";var clamp=(v,lo=0,hi=100)=>Math.min(hi,Math.max(lo,v));function BarChart({labels,series,height=180,formatValue=String,className}){const peak=Math.max(1,...series.flatMap(s=>s.values));const plot=height-26;return jsxs3("div",{className:cn("flex flex-col gap-2.5",className),children:[series.length>1&&jsx3("div",{className:"flex items-center gap-4 text-micro text-muted",children:series.map(s=>jsxs3("span",{className:"flex items-center gap-1.5",children:[jsx3("span",{"aria-hidden":"true",className:cn("size-2.5 rounded-mark",s.muted?"bg-brand-100":"bg-brand")}),s.label]},s.label))}),jsx3("div",{className:"flex items-end gap-1.5",style:{height},role:"img","aria-label":labels.join("\u060C "),children:labels.map((label,i)=>jsxs3("div",{className:"flex-1 flex flex-col items-center justify-end gap-1.5 h-full min-w-0",children:[jsx3("span",{className:"w-full flex items-end justify-center gap-[3px]",style:{height:plot},children:series.map(s=>jsx3("span",{title:`${label} \xB7 ${s.label}: ${formatValue(s.values[i]??0)}`,className:cn("rounded-t-mark transition-[height] duration-300",series.length>1?"w-1/2":"w-3/5",s.muted?"bg-brand-100":"bg-brand"),style:{height:Math.max(2,Math.round((s.values[i]??0)/peak*plot))}},s.label))}),jsx3("span",{className:"text-micro text-muted2 truncate max-w-full",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-24;const PAD_T=6;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*.62;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("flex flex-col gap-2",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:"absolute inset-x-0 border-t border-line flex items-start",style:{top:y(max*f)},children:jsx3("span",{"data-num":true,dir:"auto",className:"text-micro text-muted2 -mt-2 bg-surface 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:"pointer-events-none rounded-sm border border-line bg-surface px-2.5 py-1.5 shadow-tip flex flex-col gap-0.5",children:[nameAt(at)&&jsx3("span",{className:"text-micro text-muted2",children:nameAt(at)}),jsx3("span",{"data-num":true,className:"text-caption font-extrabold text-ink",children:formatValue(values[at])}),compare?.[at]!==void 0&&jsxs3("span",{"data-num":true,className:"text-micro text-muted2",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:"flex items-center justify-between text-micro text-muted2",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=stages.map((s,i)=>{if(i===0)return null;const prev=stages[i-1].value;return prev>0?(prev-s.value)/prev*100:0});const worst=drops.reduce((acc,d,i)=>d!==null&&d>acc.d?{i,d}:acc,{i:-1,d:-1});return jsxs3("div",{className:cn("flex flex-col",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:"flex flex-col",children:[drop!==null&&jsxs3("span",{className:cn("flex items-center gap-1.5 ps-1 py-1 text-micro",isWorst?"font-extrabold text-amber-ink":"text-muted2"),children:[jsx3("span",{"aria-hidden":"true",className:cn("w-px h-3",isWorst?"bg-amber":"bg-line")}),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:"flex items-center gap-3",children:[jsx3("span",{className:"w-32 sm:w-40 shrink-0 text-ui text-ink2 truncate",children:s.label}),jsx3("span",{className:"flex-1 h-8 rounded-xs bg-hover overflow-clip",children:jsx3("span",{className:cn("block h-full rounded-xs transition-[width] duration-500",isWorst?"bg-amber":"bg-brand"),style:{width:`${share}%`}})}),jsx3("span",{"data-num":true,className:"w-20 shrink-0 text-ui font-extrabold text-ink text-end",children:formatValue(s.value)})]})]},s.key)}),worst.i>0&&stages[worst.i].advice&&jsx3("span",{className:"mt-3 flex items-start gap-2 p-3 rounded-field bg-amber-bg text-caption leading-[1.7] text-amber-ink",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=>v===0?0:Math.min(3,Math.ceil(v/peak*3));const TINT=["bg-hover","bg-brand/25","bg-brand/55","bg-brand"];const grid={gridTemplateColumns:`56px repeat(${cols.length}, minmax(0,1fr))`};return jsxs3("div",{className:cn("flex flex-col gap-1",className),children:[jsxs3("span",{className:"grid gap-1",style:grid,children:[jsx3("span",{}),cols.map(c=>jsx3("span",{"data-num":true,className:"text-micro text-muted2 text-center",children:c},c))]}),rows.map((r,ri)=>jsxs3("span",{className:"grid gap-1 items-center",style:grid,children:[jsx3("span",{className:"text-micro text-muted truncate",children:r}),cols.map((c,ci)=>{const v=values[ri]?.[ci]??0;return jsx3("span",{title:formatCell(v,r,c),className:cn("h-6 rounded-mark transition-colors",TINT[step(v)])},c)})]},r)),jsxs3("span",{className:"flex items-center gap-2 pt-1 text-micro text-muted2",children:[lowLabel??ui.less,jsx3("span",{className:"flex gap-1",children:TINT.map(c=>jsx3("span",{className:cn("size-3 rounded-mark",c)},c))}),highLabel??ui.more]})]})}var SHARE_FILL={brand:"bg-brand",amber:"bg-amber",red:"bg-danger",muted:"bg-border"};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("flex flex-col",inline?"gap-1.5":"gap-3",className),children:items.map(it=>{const pct=sum>0?it.value/sum*100:0;const bar=jsx3("span",{className:cn("rounded-full bg-hover overflow-clip",inline?"flex-1 h-1.5 min-w-0":"block h-1.5"),children:jsx3("span",{className:cn("block h-full rounded-full transition-[width] duration-500",SHARE_FILL[it.tone??"brand"]),style:{width:`${clamp(pct)}%`}})});if(inline){return jsxs3("span",{className:"flex items-center gap-2.5",children:[jsx3("span",{style:{width:labelWidth},className:"shrink-0 text-micro text-muted truncate",children:it.label}),bar,jsx3("span",{"data-num":true,style:{width:labelWidth},className:"shrink-0 text-caption text-muted2 text-end truncate",children:it.trailing??formatValue(it.value)})]},it.key)}return jsxs3("span",{className:"flex flex-col gap-1.5",children:[jsxs3("span",{className:"flex items-center justify-between gap-3",children:[jsxs3("span",{className:"flex flex-col min-w-0",children:[jsx3("span",{className:"text-ui font-bold text-ink truncate",children:it.label}),it.meta&&jsx3("span",{className:"text-micro text-muted truncate",children:it.meta})]}),jsxs3("span",{className:"flex items-center gap-3 shrink-0",children:[it.trailing,jsx3("span",{"data-num":true,className:"text-ui font-extrabold text-ink min-w-[64px] text-end",children:formatValue(it.value)}),showPercent&&jsxs3("span",{"data-num":true,className:"text-micro text-muted2 w-9 text-end",children:[pct.toFixed(0),"%"]})]})]}),bar]},it.key)})})}import{Check,Info,Lock}from"lucide-react";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={1:"",2:"sm:grid-cols-2",3:"sm:grid-cols-3"}[columns];const picked=Array.isArray(value)?new Set(value):null;return jsx4("div",{role:multiple?"group":"radiogroup",className:cn("grid gap-2.5",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("relative flex items-start gap-3 p-3.5 rounded-card border transition-colors",off?"border-line bg-bg cursor-not-allowed opacity-70":"cursor-pointer hover:border-brand",on&&!off?"border-brand bg-soft":"border-border bg-surface"),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("mt-0.5 size-[19px] border-[1.5px] flex items-center justify-center shrink-0 transition-colors",multiple?"rounded-mark":"rounded-full","peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-brand",on&&!off?"border-brand bg-brand":"border-border bg-surface"),children:on&&!off&&jsx4(Check,{size:12,strokeWidth:3,className:"text-white"})}),o.icon&&jsx4("span",{"aria-hidden":"true",className:cn("size-9 rounded-field flex items-center justify-center shrink-0 transition-colors",on&&!off?"bg-brand text-white":"bg-hover text-muted"),children:jsx4(o.icon,{size:17,strokeWidth:2})}),jsxs4("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[jsx4("span",{className:"text-body font-extrabold text-ink",children:o.label}),o.meta&&jsx4("span",{className:"text-caption leading-[1.6] text-muted",children:o.meta}),off&&o.lockReason&&jsxs4("span",{className:"inline-flex items-center gap-1 mt-1 text-caption font-bold text-amber-ink",children:[jsx4(Lock,{size:11,"aria-hidden":"true"}),o.lockReason]})]}),o.price&&jsx4("span",{"data-num":true,className:"text-ui font-extrabold text-ink shrink-0",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:cn("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"),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 max=Math.max(...values);const min=Math.min(...values);const span=max-min||1;const step=width/(values.length-1);const points=values.map((v,i)=>{const x=i*step;const y=height-(v-min)/span*(height-3)-1.5;return[x,y]});const line=points.map(([x,y],i)=>`${i===0?"M":"L"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");const area=`${line} L${width},${height} L0,${height} Z`;const stroke={brand:"stroke-brand",green:"stroke-green",red:"stroke-danger",muted:"stroke-muted2"}[tone];const fill={brand:"fill-brand/10",green:"fill-green/10",red:"fill-danger/10",muted:"fill-muted2/10"}[tone];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:1.5,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};