import{jsxs as r,jsx as t}from"react/jsx-runtime";import{B as u}from"./badge-CFi7bqqA.js";import{B as d}from"./button-BvFBRYHq.js";import{C as h,b as C,c as g,d as y,a as w}from"./card-Zg0WOx-j.js";import{L as v}from"./label-DMnntKPk.js";import{S as N}from"./separator-BDLxzoJ8.js";import{T as x}from"./textarea-DGUf1VTd.js";import{Eraser as R,Download as I,FileUp as S}from"lucide-react";import{useState as m}from"react";import{toast as n}from"sonner";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";function f(){return document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||""}async function b(s){try{const e=await(await fetch("/admin/fitur/load-rare-item",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":f()},body:JSON.stringify({path:s})})).json();if(e.success&&e.content)return e.content;throw n.error(e.message||"Failed to load rare_item.conf"),new Error(e.message||"Failed to load file")}catch(o){throw n.error("Error loading rare_item.conf file"),o}}async function F(s,o){try{const a=await(await fetch("/admin/fitur/save-rare-item",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":f()},body:JSON.stringify({path:s,content:o})})).json();if(a.success)n.success("rare_item.conf saved successfully!");else throw n.error(a.message||"Failed to save file"),new Error(a.message||"Failed to save file")}catch(e){throw n.error("Error saving rare_item.conf file"),e}}function T(s){const[o,e]=m(""),[a,i]=m(!1);return{manualCodes:o,setManualCodes:e,isLoading:a,loadRareItems:async()=>{i(!0);try{const p=await b(s);e(p)}finally{i(!1)}},saveRareItems:async()=>{await F(s,o)}}}function G({rareItemPath:s}){const{manualCodes:o,setManualCodes:e,isLoading:a,loadRareItems:i,saveRareItems:l}=T(s);return r(h,{children:[r(C,{children:[r(g,{className:"flex items-center gap-2",children:[t(R,{className:"h-5 w-5"}),"Rare Item Cleaner"]}),t(y,{children:"Edit and manage rare_item.conf file directly"})]}),r(w,{className:"space-y-6",children:[r("div",{className:"space-y-2",children:[r("div",{className:"flex items-center justify-between",children:[t(v,{htmlFor:"manualCodes",children:"Item Codes"}),a&&t(u,{variant:"secondary",className:"text-xs",children:"Loading..."})]}),t(x,{id:"manualCodes",placeholder:"Loading rare_item.conf...",value:o,onChange:c=>e(c.target.value),rows:20,className:"font-mono text-sm",disabled:a}),r("p",{className:"text-muted-foreground text-xs",children:["Edit item codes directly. One code per line. File will be saved to: ",s]})]}),t(N,{}),r("div",{className:"flex gap-2",children:[r(d,{onClick:l,size:"default",disabled:a,children:[t(I,{className:"h-4 w-4"}),t("span",{className:"ml-2 hidden md:inline",children:"Save Changes"})]}),r(d,{onClick:i,variant:"outline",disabled:a,children:[t(S,{className:"h-4 w-4"}),t("span",{className:"ml-2 hidden md:inline",children:"Load File"})]})]})]})]})}export{G as RareItemCleaner};
