import{useState as n}from"react";import{router as p}from"@inertiajs/react";import{b as f}from"./shop-helpers-CW6YR2iv.js";import h from"axios";function S(u){const[o,i]=n(f(u)),[r,t]=n({}),[s,a]=n(!1),m=e=>{i(f(e)),t({})};return{formData:o,errors:r,isLoading:s,setFormData:i,setErrors:t,handleCreate:()=>{a(!0),t({}),p.post(route("admin.shop.store"),o,{preserveScroll:!0,onSuccess:()=>{m()},onError:e=>{t(e)},onFinish:()=>{a(!1)}})},handleUpdate:e=>{a(!0),t({}),p.put(route("admin.shop.update",e),o,{preserveScroll:!0,onSuccess:()=>{},onError:c=>{t(c)},onFinish:()=>{a(!1)}})},resetForm:m}}function L(u="",o=""){const[i,r]=n(u),[t,s]=n(o),[a,m]=n(!1);return{itemName:i,itemColor:t,isLoadingItemName:a,fetchItemName:async e=>{if(!e||e.trim()===""){r(""),s("");return}m(!0);try{const c=await h.get(route("admin.shop.items"),{params:{item_id:e}});r(c.data.name||""),s(c.data.color||"")}catch{r("Item not found"),s("")}finally{m(!1)}},resetItemName:()=>{r(u),s(o)}}}export{L as a,S as u};
