import{jsxs as r,jsx as e,Fragment as z}from"react/jsx-runtime";import{B}from"./badge-CFi7bqqA.js";import{B as u}from"./button-BvFBRYHq.js";import{C as E,b as I,c as O,d as U,a as q}from"./card-Zg0WOx-j.js";import{I as W}from"./input-qMvM9qch.js";import{L as F}from"./label-DMnntKPk.js";import{S as b}from"./separator-BDLxzoJ8.js";import{T as _}from"./textarea-DGUf1VTd.js";import{Target as L,Copy as H,Download as G}from"lucide-react";import{useState as h}from"react";import{toast as l}from"sonner";import{ColoredOutput as J}from"./ColoredOutput-DOBwYw7G.js";import"@radix-ui/react-slot";import"class-variance-authority";import"./utils-CMbmcP35.js";import"clsx";import"tailwind-merge";import"@radix-ui/react-label";import"@radix-ui/react-separator";async function S(n){if(!n||n.trim()==="")throw l.error("No text to copy"),new Error("No text to copy");try{await navigator.clipboard.writeText(n),l.success("Text copied to clipboard!");return}catch{}try{const o=document.createElement("textarea");o.value=n,o.style.position="fixed",o.style.left="-999999px",o.style.top="-999999px",document.body.appendChild(o),o.focus(),o.select();const p=document.execCommand("copy");if(document.body.removeChild(o),p)l.success("Text copied to clipboard!");else throw new Error("execCommand failed")}catch(o){throw l.error("Failed to copy to clipboard. Please copy manually."),o}}function K(){const[n,o]=h(""),[p,a]=h(""),[f,N]=h("#00ffff"),[s,m]=h([]),[C,w]=h(!0),[T,k]=h(0);return{inputText:n,setInputText:o,outputText:p,colorPicker:f,setColorPicker:N,convertedArray:s,sortAscending:C,totalPercentage:T,convertText:async()=>{const c=n.trim();if(!c){l.error("Please enter input data first.");return}const i=f.replace("#","").toLowerCase(),t=c.split(`
`),d=[];let v=0;if(t.forEach(g=>{const y=g.trim().split(/\s{2,}|\t/);if(y.length>=7){const j=y[2],$="x"+y[4],D=y[5].replace("%",""),P=parseFloat(D);v+=P;const R=`^${i}${j} ${$} - ${P.toFixed(2)}%`;d.push({line:R,percent:P})}}),d.length===0){l.error("No valid data found. Please check your input format.");return}const A=d.map(g=>g.line).join(`
`);m(d),a(A),k(v);try{await S(A)}catch{}},toggleSort:()=>{if(s.length===0){l.error("Please convert the data first.");return}const c=[...s].sort((i,t)=>C?i.percent-t.percent:t.percent-i.percent);m(c),a(c.map(i=>i.line).join(`
`)),w(!C)},setColor:()=>{if(s.length===0){l.error("Please convert the data first.");return}const c=f.replace("#","").toLowerCase(),i=s.map(t=>{const d=t.line.replace(/^\^[0-9a-fA-F]{6}/,"");return{...t,line:`^${c}${d}`}});m(i),a(i.map(t=>t.line).join(`
`))},autoColorize:()=>{if(s.length<3){l.error("At least 3 items required.");return}const c=[...s].sort((t,d)=>t.percent-d.percent);for(let t=0;t<c.length;t++){const d=t<3?"ff0000":t<8?"ff8000":"00ff00",v=c[t].line.replace(/^\^[0-9a-fA-F]{6}/,"");c[t].line=`^${d}${v}`}const i=c.reverse();m(i),a(i.map(t=>t.line).join(`
`))}}}function M(n,o){if(!n){l.error("No content to download");return}const p=new Blob([n],{type:"text/plain"}),a=document.createElement("a");a.download=o,a.href=URL.createObjectURL(p),a.click(),URL.revokeObjectURL(a.href),l.success("File downloaded!")}function xe(){const{inputText:n,setInputText:o,outputText:p,colorPicker:a,setColorPicker:f,convertedArray:N,sortAscending:s,totalPercentage:m,convertText:C,toggleSort:w,setColor:T,autoColorize:k}=K();return r(E,{children:[r(I,{children:[r(O,{className:"flex items-center gap-2",children:[e(L,{className:"h-5 w-5"}),"Drop Rate Converter"]}),e(U,{children:"Convert game drop data to formatted output with color coding"})]}),r(q,{className:"space-y-6",children:[r("div",{className:"space-y-4",children:[r("div",{className:"space-y-2",children:[e(F,{htmlFor:"inputText",children:"Input Data"}),e(_,{id:"inputText",placeholder:"Paste game drop data here...",value:n,onChange:x=>o(x.target.value),rows:6,className:"font-mono text-sm"})]}),e(b,{}),r("div",{className:"space-y-2",children:[e(F,{htmlFor:"colorPicker",children:"Text Color"}),r("div",{className:"flex items-center gap-3",children:[e(W,{id:"colorPicker",type:"color",value:a,onChange:x=>f(x.target.value),className:"h-10 w-20 cursor-pointer"}),e(B,{variant:"outline",className:"px-4 font-mono",children:a})]})]})]}),e(b,{}),r("div",{className:"flex flex-wrap gap-2",children:[r(u,{onClick:C,size:"default",children:[e(L,{className:"h-4 w-4"}),e("span",{className:"ml-2 hidden md:inline",children:"Convert"})]}),r(u,{onClick:T,variant:"outline",children:[e("span",{className:"hidden md:inline",children:"Apply Color"}),e("span",{className:"md:hidden",children:"Color"})]}),r(u,{onClick:k,variant:"outline",children:[e("span",{className:"hidden md:inline",children:"Auto Colorize"}),e("span",{className:"md:hidden",children:"Auto"})]}),r(u,{onClick:w,variant:"outline",children:[r("span",{className:"hidden md:inline",children:["Sort ",s?"↑":"↓"]}),e("span",{className:"md:hidden",children:s?"↑":"↓"})]}),r(u,{onClick:()=>S(p),variant:"outline",children:[e(H,{className:"h-4 w-4"}),e("span",{className:"ml-2 hidden md:inline",children:"Copy"})]}),r(u,{onClick:()=>M(p,"drop_rate_result.txt"),variant:"outline",children:[e(G,{className:"h-4 w-4"}),e("span",{className:"ml-2 hidden md:inline",children:"Download"})]})]}),p&&r(z,{children:[e(b,{}),e(J,{items:N,totalPercentage:m})]})]})]})}export{xe as DropRateConverter};
