1import{j as e}from"./query-C9rthSUJ.js";import{u as J,b as Y,B as l,A as Z}from"./navigation-Dsw3USph.js";import{E as G,a as H}from"./event-creation-shell-C67ye7ii.js";import{P as I,a as A}from"./page-shell-B_QWxdTZ.js";import{S as K}from"./status-tag-yI2hAJzc.js";import{I as p}from"./dropdown-menu-BYmjAYFV.js";import{L as u}from"./label-DOHzhs-N.js";import{e as M,c as O,b as d,g as Q}from"./index-1qHllCzV.js";import{e as X}from"./events-DR3teHDn.js";import{e as y}from"./electricity-DMvCG5yd.js";import{a as c}from"./vendor-D5-NEHb5.js";import{S as E,a as F,b as D,c as R,d as h}from"./select-Bf9mqZaD.js";import g from"./loader-circle-t1fdXJtH.js";import ee from"./circle-alert-DmTb0b_k.js";import P from"./plus-BPqzkS0V.js";import te from"./zap-BKVO1jVx.js";import re from"./trash-2-BxCcsnSK.js";import se from"./arrow-right-CN64dvda.js";import"./ui-B72G9_re.js";import"./charts-3WZcVZCN.js";import"./account-layout-CspMc0N6.js";import"./user-round-DobIWPVN.js";import"./receipt-text-CrEpgz0p.js";import"./clipboard-list-nomMHFMW.js";import"./layout-dashboard-B16n9kqU.js";import"./box-CpV0eWSF.js";import"./users-round-wVr-YTeu.js";import"./calendar-days-dvKkC3ld.js";import"./wallet-cards-CXJq92QM.js";import"./shield-check-De6YQMUI.js";import"./key-round-8Eel-15I.js";import"./settings-B4WokloQ.js";import"./registration-steps-k9l0MYIb.js";import"./site-layout-limBRqDA.js";import"./site-header-C-ga5QUs.js";import"./dialog-DDYUSWYc.js";import"./chevron-left-DjRDferW.js";import"./index-CLV1MOmb.js";import"./index-CAvYfBqI.js";function ae(){const{language:L}=M(),t=(r,s)=>Q(L,r,s),m=J(),T=Y(),{user:ie,isAuthenticated:j,isLoading:x}=O(),i=T.get("event_id"),[f,q]=c.useState(null),[b,N]=c.useState([]),[V,w]=c.useState(!0),[C,S]=c.useState(!1),[k,_]=c.useState(!1),[a,n]=c.useState({voltage:"110",ampere:"",wattage_unit:"500",price_per_unit:"750",currency:"TWD",status:"active"}),W=async()=>{if(i)try{const r=await X.getEventById(i);q(r)}catch(r){console.error("Failed to load event:",r),d.error(t("events_create_electricity_rules.load_failed"))}},v=c.useCallback(async()=>{if(i){w(!0);try{const r=await y.listRulesByEvent(i);N(Array.isArray(r)?r:[])}catch(r){console.error("Failed to load electricity rules:",r),N([])}finally{w(!1)}}},[i]);c.useEffect(()=>{if(!x&&!j){d.error(t("events_create_electricity_rules.login_required"),{description:t("events_create_electricity_rules.login_description")}),m.push("/events/policy");return}if(!i){d.error(t("events_create_electricity_rules.event_required"),{description:t("events_create_electricity_rules.event_required_description")}),m.push("/events/create/organizer");return}W(),v()},[x,j,i]);const B=async r=>{if(r.preventDefault(),!!i){S(!0);try{const s={event_id:i,voltage:parseInt(a.voltage,10),ampere:a.ampere?parseInt(a.ampere,10):null,wattage_unit:parseInt(a.wattage_unit,10),price_per_unit:a.price_per_unit,currency:a.currency,status:a.status};await y.createRule(s),d.success(t("events_create_electricity_rules.created")),_(!1),n({voltage:"110",ampere:"",wattage_unit:"500",price_per_unit:"750",currency:"TWD",status:"active"}),v()}catch(s){const o=s;console.error("Failed to create electricity rule:",s),d.error(t("events_create_electricity_rules.create_failed"),{description:o.detail||o.message})}finally{S(!1)}}},U=async r=>{if(confirm(t("events_create_electricity_rules.delete_confirm")))try{await y.deleteRule(r),d.success(t("events_create_electricity_rules.deleted")),v()}catch(s){const o=s;console.error("Failed to delete electricity rule:",s),d.error(t("events_create_electricity_rules.delete_failed"),{description:o.detail||o.message})}},$=()=>{m.push(`/events/create/products?event_id=${i}`)},z=()=>{m.push(`/events/create/products?event_id=${i}`)};return x||V?e.jsx(I,{width:"status",children:e.jsx("div",{className:"flex min-h-[50vh] items-center justify-center",children:e.jsx(g,{className:"h-8 w-8 animate-spin text-gray-400"})})}):e.jsxs(G,{current:"electricity",eventId:i,title:t("events_create_electricity_rules.title"),description:t("innerPages.eventCreation.descriptions.electricity"),children:[f&&e.jsxs(A,{padding:"compact",children:[e.jsx("p",{className:"text-[13px] text-ink-muted",children:t("events_create_electricity_rules.event_name")}
1),e.jsx("p",{className:"font-semibold text-ink",children:f.name})]}),e.jsxs(A,{children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-ink",children:t("events_create_electricity_rules.section_title")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-muted",children:t("events_create_electricity_rules.section_description")}),e.jsxs("div",{className:"mb-8 mt-4 flex gap-3 rounded-md bg-site-bg p-4",children:[e.jsx(ee,{className:"mt-0.5 h-5 w-5 shrink-0 text-brand-dark"}),e.jsxs("div",{className:"text-sm text-ink-secondary",children:[e.jsx("p",{className:"font-medium mb-1",children:t("events_create_electricity_rules.info_title")}),e.jsx("p",{children:t("events_create_electricity_rules.info_description")})]})]}),e.jsxs("div",{className:"space-y-4 mb-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-gray-900",children:t("events_create_electricity_rules.configured")}),e.jsxs(l,{onClick:()=>_(!0),className:"bg-[#1c1c1a] hover:bg-brand-dark text-white",disabled:k,children:[e.jsx(P,{className:"h-4 w-4 mr-2"}),t("events_create_electricity_rules.add")]})]}),b.length===0?e.jsxs("div",{className:"text-center py-12 bg-gray-50 rounded-md border-2 border-dashed border-gray-200",children:[e.jsx(te,{className:"h-12 w-12 text-gray-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:t("events_create_electricity_rules.empty_title")}),e.jsx("p",{className:"text-gray-600 mb-4",children:t("events_create_electricity_rules.empty_description")}),e.jsxs(l,{onClick:()=>_(!0),variant:"outline",className:"border-[#1c1c1a] text-[#1c1c1a] hover:bg-[#1c1c1a]/10",children:[e.jsx(P,{className:"h-4 w-4 mr-2"}),t("events_create_electricity_rules.add_first")]})]}):e.jsx("div",{className:"space-y-3",children:b.map(r=>e.jsxs("div",{className:"border rounded-md p-4 flex items-center justify-between gap-4 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-1 flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"font-semibold text-gray-900 text-lg",children:[r.voltage,"V"]}),r.ampere&&e.jsxs("span",{className:"text-sm text-gray-600 bg-gray-100 px-2 py-0.5 rounded",children:[r.ampere,"A"]}),e.jsx(K,{tone:r.status==="active"?"success":"neutral",children:r.status==="active"?t("events_create_electricity_rules.active"):t("events_create_electricity_rules.disabled")})]}),e.jsx("div",{className:"text-sm text-gray-600",children:t("events_create_electricity_rules.pricing",{wattage:r.wattage_unit,currency:r.currency,price:r.price_per_unit})})]}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>r.id&&U(r.id),className:"text-red-600 hover:text-red-700 hover:bg-red-50",children:e.jsx(re,{className:"h-4 w-4"})})]},r.id))})]}),k&&e.jsxs("form",{onSubmit:B,className:"mb-8 space-y-4 border-t border-divider bg-site-bg p-6",children:[e.jsx("h4",{className:"font-semibold text-gray-900 mb-4",children:t("events_create_electricity_rules.add")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"voltage",children:t("events_create_electricity_rules.voltage")}),e.jsxs(E,{value:a.voltage,onValueChange:r=>n(s=>({...s,voltage:r})),children:[e.jsx(F,{children:e.jsx(D,{placeholder:t("events_create_electricity_rules.select_voltage")})}),e.jsxs(R,{children:[e.jsx(h,{value:"110",children:"110V"}),e.jsx(h,{value:"220",children:"220V"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"ampere",children:t("events_create_electricity_rules.ampere")}),e.jsx(p,{id:"ampere",type:"number",value:a.ampere,onChange:r=>n(s=>({...s,ampere:r.target.value})),placeholder:"15"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"wattage_unit",children:t("events_create_electricity_rules.wattage")}),e.jsx(p,{id:"wattage_unit",type:"number",step:"100",min:"100",value:a.wattage_unit,onChange:r=>n(s=>({...s,wattage_unit:r.target.value})),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"price_per_unit",children:t("events_create_electricity_rules.price")}),e.jsx(p,{id:"price_per_unit",type:"number",step:["TWD","JPY"].includes((a.currency||"TWD").toUpperCase())?"1":"0.01",min:"0",value:a.price_per_unit,onChange:r=>{let s=r.target.value;["TWD","JPY"].includes((a.currency||"TWD").toUpperCase())&&(s=s.split(".")[0]),n(o=>({...o,price_per_unit:s}))},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"currency",children:t("events_create_electricity_rules.currency")}),e.jsx(p,{id:"currency",type:"text",value:a.currency,onChange:r=>n(s=>({...s,currency:r.target.value.toUpperCase()})),maxLength:3,required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"status",children:t("events_create_electricity_rules.status")}),e.jsxs(E,{value:a.status,onValueChange:r=>n(s=>({...s,status:r})),children:[e.jsx(F,{children:e.jsx(D,{placeholder:t("events_create_electricity_rules.select_status")})}),e.jsxs(R,{children:[e.jsx(h,{value:"active",children:t("events_create_electricity_rules.enable")}),e.jsx(h,{value:"disabled",children:t("events_create_electricity_rules.disable")})]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(l,{type:"button",variant:"outline",onClick:()=>_(!1),children:t("events_create_electricity_rules.cancel")}),e.jsx(l,{type:"submit",disabled:C,className:"bg-[#1c1c1a] hover:bg-brand-dark text-white",children:C?e.jsxs(e.Fragment,{children:[e.jsx(g,{className:"h-4 w-4 mr-2 animate-spin"}),t("events_create_electricity_rules.saving")]}):t("events_create_electricity_rules.save")})]})]})]}
1),e.jsxs(H,{children:[e.jsxs(l,{variant:"ghost",onClick:()=>m.push(`/events/create/basic?event_id=${i}`),children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),t("events_create_electricity_rules.previous")]}),e.jsxs("div",{className:"flex flex-col-reverse gap-3 sm:flex-row",children:[e.jsx(l,{variant:"ghost",onClick:z,children:t("events_create_electricity_rules.skip")}),e.jsxs(l,{onClick:$,children:[t("events_create_electricity_rules.next"),e.jsx(se,{className:"ml-2 h-4 w-4"})]})]})]})]})]})}function Ye(){return e.jsx(c.Suspense,{fallback:e.jsx(I,{width:"status",children:e.jsx("div",{className:"flex min-h-[50vh] items-center justify-center",children:e.jsx(g,{className:"h-8 w-8 animate-spin text-gray-400"})})}),children:e.jsx(ae,{})})}export{Ye as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.