import{h,w as j,c as _,d as V,o as g,e,t as M,i as k,v as $,g as v,r as f,a as F,b as B,j as y,k as u,u as b,l as N,F as U}from"./app-OFnD_EfZ.js";import{u as d}from"./swal-C1wxMWhd.js";import{_ as D}from"./CustomTable-wjyxWH_G.js";import{_ as O}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{r as S}from"./PlusCircleIcon-DKkKuqdz.js";import{r as z}from"./MagnifyingGlassIcon-BNDw92ps.js";import{r as I}from"./PencilIcon-DlHVKXpT.js";import{r as L}from"./TrashIcon-B13aKaaG.js";import"./sweetalert2.esm.all-BQIkj5Wb.js";/* empty css                                                    */const T={key:0,class:"fixed inset-0 z-50 bg-black/40 backdrop-blur-sm flex items-center justify-center"},E={class:"bg-white rounded-xl shadow-xl w-full max-w-md animate-fade-in"},K={class:"bg-slate-600 rounded-t-xl text-white"},q={class:"text-2xl font-semibold p-4 text-center"},A={class:"space-y-4 my-6 p-4"},G={class:"flex flex-row whitespace-nowrap items-center mx-6 gap-2"},H={class:"flex justify-center gap-2 p-4 border-t-4 shadow font-semibold"},J={__name:"Modal",props:{show:Boolean,factory:Object},emits:["update:show","saved"],setup(p,{emit:c}){const a=p,n=c,s=h({name:""});j(()=>a.factory,i=>{i?Object.assign(s,i):Object.assign(s,{name:""})});const m=async()=>{var i;if(!s.name.trim()){await d.error("請確認「廠區名稱」已填寫","資料未填寫完整");return}try{(i=a.factory)!=null&&i.id?(await v.put(`/api/factory/${a.factory.id}`,s),await d.success("廠區修改成功")):(await v.post("/api/factory",s),await d.success("廠區新增成功")),n("saved"),n("update:show",!1)}catch{await d.error("請稍後再試，或聯絡管理員","儲存失敗")}};return(i,r)=>{var w;return p.show?(g(),_("div",T,[e("div",E,[e("div",K,[e("div",q,M((w=p.factory)!=null&&w.id?"修改廠區":"新增廠區"),1)]),e("div",A,[e("div",G,[r[2]||(r[2]=e("label",{class:"text-base font-bold text-gray-700"},"廠區名稱",-1)),k(e("input",{"onUpdate:modelValue":r[0]||(r[0]=x=>s.name=x),type:"text",class:"text-base w-full border border-gray-300 rounded-md ml-2 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400",placeholder:"請輸入廠區名稱"},null,512),[[$,s.name]])])]),e("div",H,[e("button",{onClick:r[1]||(r[1]=x=>n("update:show",!1)),class:"w-20 h-10 px-4 py-2 text-base bg-red-600 hover:bg-red-500 text-white rounded"}," 取消 "),e("button",{onClick:m,class:"w-20 h-10 px-4 py-2 text-base bg-blue-800 hover:bg-blue-700 text-white rounded"}," 儲存 ")])])])):V("",!0)}}},P=O(J,[["__scopeId","data-v-63e1f071"]]),Q={class:"sm:p-4 md:p-6"},R={class:"flex flex-col sm:flex-row sm:justify-between sm:items-center mb-4 gap-3 sm:gap-0 mt-4 sm:mt-0"},W={class:"flex flex-col sm:flex-row gap-3 w-full sm:w-auto justify-between"},X={class:"relative w-full sm:w-64"},Y=["onClick"],Z=["onClick"],ce={__name:"Index",setup(p){const c=f(!1),a=f(null),n=f("");f(!1),h({name:""});const s=f([]),m=async()=>{var l;try{const t=await v.get("/api/factory");s.value=((l=t.data)==null?void 0:l.data)||[]}catch(t){await d.error(t,"載入失敗")}},i=()=>{a.value=null,c.value=!0},r=l=>{a.value={...l},c.value=!0},w=async l=>{if((await d.confirm("確認刪除？")).isConfirmed)try{await v.delete(`/api/factory/${l}`),await d.success("刪除成功"),m()}catch(o){await d.error(o.response.data.message)}};F(()=>{m()});const x=B(()=>{if(!n.value.trim())return s.value;const l=n.value.toLowerCase();return s.value.filter(t=>t.name.toLowerCase().includes(l))});return(l,t)=>(g(),_(U,null,[t[4]||(t[4]=e("h2",{class:"flex items-center text-xl sm:text-3xl px-3 pb-2 font-semibold text-black dark:text-white border-b-4 border-zinc-200"},[e("div",{class:"text-sm mr-2"},":::"),y(" 廠區管理 ")],-1)),e("div",Q,[e("div",R,[e("div",null,[e("button",{onClick:i,class:"flex items-center justify-center bg-white text-lg text-blue-900 font-semibold px-2 py-1 rounded border border-blue-200 w-full sm:w-auto"},[u(b(S),{class:"w-7 h-7 text-blue-900 mr-1"}),t[3]||(t[3]=y("新增 ",-1))])]),e("div",W,[e("div",X,[u(b(z),{class:"absolute left-2 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-400"}),k(e("input",{"onUpdate:modelValue":t[0]||(t[0]=o=>n.value=o),type:"text",placeholder:"搜尋",class:"border rounded px-3 py-2 text-sm w-full sm:w-64 pl-8"},null,512),[[$,n.value]])])])]),u(D,{items:x.value,columns:[{label:"廠區名稱",field:"name"}],modelValue:a.value,"onUpdate:modelValue":t[1]||(t[1]=o=>a.value=o),rows:5,selectable:!1},{action:N(({data:o})=>[e("button",{onClick:C=>r(o),class:"text-blue-900 hover:underline text-sm rounded border border-gray-200 shadow px-1 py-1"},[u(b(I),{class:"w-5 h-5"})],8,Y),e("button",{onClick:C=>w(o.id),class:"text-red-600 hover:underline text-sm rounded border border-gray-200 shadow px-1 py-1"},[u(b(L),{class:"w-5 h-5"})],8,Z)]),_:1},8,["items","modelValue"]),u(P,{show:c.value,"onUpdate:show":t[2]||(t[2]=o=>c.value=o),factory:a.value,onSaved:m},null,8,["show","factory"])])],64))}};export{ce as default};
