1import{j as e}from"./app-xtnexrKX.js";import{V as t,a}from"./vendor-jfmykXpB.js";import{A as s}from"./AdminLayoutNew-C0AoHtGQ.js";import{c as l,h as d}from"./alertDateLogic-CCoziK7i.js";import{S as r}from"./StatusIndicator-heDYNIng.js";import{i as n}from"./format-A_ews_9b.js";import"./utils-Cp3twET-.js";import"./ApplicationLogo-DxAzR1IV.js";import"./transition-BDGULseq.js";import"./DarkLightModeSwitcher-Cf-XG8h9.js";import"./DataContext-D360ttN-.js";import"./debounce-DUp1Mma4.js";import"./addDays-Bshq1ti_.js";import"./index-B2n7kSfH.js";import"./iconBase-Cpk8zDH3.js";const i=({alert:t={},holidays:s=[]})=>{const{data:i,setData:o,post:c,processing:m,errors:x}=a({id:t.id||null,title:t.title||"",message:t.message||"",enabled:t.enabled||!1,date_mode:t.holiday_type?"holidays":"my_dates",holiday_type:t.holiday_type||"",start_offset:t.start_offset||0,end_offset:t.end_offset||0,start_date:t.start_date?new Date(t.start_date):null,end_date:t.end_date?new Date(t.end_date):null,target_audience:t.target_audience||[]}),u=l(i),h=()=>{if(!i.enabled)return!1;const e=new Date;let t,a;if(i.holiday_type){if(!u||"Invalid Date"===u.start||"Invalid Date"===u.end)return!1;t=new Date(u.start),a=new Date(u.end)}else{if(!n(i.start_date)||!n(i.end_date))return!1;t=new Date(i.start_date),a=new Date(i.end_date)}return e>=t&&e<=a},f=e=>{const t=e.target.value;o("target_audience",i.target_audience.includes(t)?i.target_audience.filter(e=>e!==t):[...i.target_audience,t])};return e.jsxs("form",{onSubmit:e=>{e.preventDefault(),c(route("admin.alerts.update",[t.id]))},className:"max-w-lg mx-auto p-6 bg-white shadow-md rounded-md",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{htmlFor:"enabled",className:"inline-flex items-center",children:[e.jsx("input",{type:"checkbox",id:"enabled",checked:i.enabled,onChange:e=>o("enabled",e.target.checked),className:"form-checkbox h-5 w-5 text-blue-600"}),e.jsx("span",{className:"ml-2 text-gray-700",children:"Enabled"})]}),x.enabled&&e.jsx("p",{className:"text-red-500 text-sm",children:x.enabled})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"title",className:"block text-gray-700 font-semibold mb-2",children:"Title"}),e.jsx("input",{type:"text",id:"title",value:i.title,onChange:e=>o("title",e.target.value),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),x.title&&e.jsx("p",{className:"text-red-500 text-sm",children:x.title})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"message",className:"block text-gray-700 font-semibold mb-2",children:"Message"}),e.jsx("textarea",{id:"message",value:i.message,onChange:e=>o("message",e.target.value),rows:"4",className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),x.message&&e.jsx("p",{className:"text-red-500 text-sm",children:x.message})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-gray-700 font-semibold mb-2",children:"Target Audience"}),e.jsx("div",{className:"flex flex-wrap gap-4",children:["premium","free","guest"].map(t=>e.jsxs("label",{className:"inline-flex items-center",children:[e.jsx("input",{type:"checkbox",value:t,checked:i.target_audience.includes(t),onChange:f,className:"form-checkbox h-4 w-4 text-blue-600"}),e.jsx("span",{className:"ml-2 capitalize",children:t})]},t))}),x.target_audience&&e.jsx("p",{className:"text-red-500 text-sm",children:x.target_audience})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-gray-700 font-semibold mb-2",children:"Date Mode"}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("label",{className:"inline-flex items-center",children:[e.jsx("input",{type:"radio",name:"date_mode",value:"my_dates",checked:"my_dates"===i.date_mode,onChange:e=>d(o,e.target.value),className:"form-radio h-4 w-4 text-blue-600"}),e.jsx("span",{className:"ml-2",children:"My Dates"})]}),e.jsxs("label",{className:"inline-flex items-center",children:[e.jsx("input",{type:"radio",name:"date_mode",value:"holidays",checked:"holidays"===i.date_mode,onCh
1ange:e=>d(o,e.target.value),className:"form-radio h-4 w-4 text-blue-600"}),e.jsx("span",{className:"ml-2",children:"Holidays"})]})]})]}),"my_dates"===i.date_mode&&e.jsxs("div",{className:"flex space-x-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{htmlFor:"start_date",className:"block text-gray-700 font-semibold mb-2",children:"Start Date"}),e.jsx("input",{type:"date",id:"start_date",value:n(i.start_date)?i.start_date.toISOString().substr(0,10):"",onChange:e=>o("start_date",new Date(e.target.value)),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{htmlFor:"end_date",className:"block text-gray-700 font-semibold mb-2",children:"End Date"}),e.jsx("input",{type:"date",id:"end_date",value:n(i.end_date)?i.end_date.toISOString().substr(0,10):"",onChange:e=>o("end_date",new Date(e.target.value)),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]})]}),"holidays"===i.date_mode&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"holiday_type",className:"block text-gray-700 font-semibold mb-2",children:"Holiday"}
1),e.jsxs("select",{id:"holiday_type",value:i.holiday_type,onChange:e=>o("holiday_type",e.target.value),className:"form-select w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:""}),s.map(t=>e.jsx("option",{value:t.key,children:t.name},t.key))]})]}),e.jsxs("div",{className:"flex space-x-4",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"start_offset",className:"block text-gray-700 font-semibold mb-2",children:"Start Offset (days)"}),e.jsx("input",{type:"number",id:"start_offset",min:"-365",max:"365",value:i.start_offset,onChange:e=>o("start_offset",parseInt(e.target.value,10)||0),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"end_offset",className:"block text-gray-700 font-semibold mb-2",children:"End Offset (days)"}),e.jsx("input",{type:"number",id:"end_offset",min:"-365",max:"365",value:i.end_offset,onChange:e=>o("end_offset",parseInt(e.target.value,10)||0),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]})]})]}),u&&e.jsxs("div",{className:"mt-4 text-gray-500",children:[e.jsx("p",{children:e.jsx("strong",{children:"Next Active Range:"})}),e.jsxs("p",{children:[u.start," to ",u.end]})]}),i.title&&i.message&&e.jsxs("div",{className:"mt-6 mb-8",children:[e.jsxs("div",{className:"flex items-center mb-2",children:[e.jsx("label",{className:"block text-gray-700 font-semibold",children:"Alert Preview"}),e.jsx("div",{className:"ml-2",title:h()?"Alert would be active now":"Alert would not be active now",children:e.jsx(r,{status:h()?"active":"inactive"})})]}),e.jsx("div",{className:"border border-gray-300 rounded-md overflow-hidden",children:e.jsx("div",{className:"flex items-center p-4 border-t-4 text-red-800 border-red-300 bg-red-50 dark:text-red-400 dark:bg-gray-800 dark:border-red-800 w-full",role:"alert",children:e.jsx("div",{className:"inline-flex items-center mx-auto",children:e.jsxs("div",{className:"text-sm font-medium",children:[e.jsx("strong",{children:i.title}),!i.title.match(/[?!.]$/)&&":"," ",e.jsx("span",{dangerouslySetInnerHTML:{__html:i.message}})]})})})})]}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"submit",className:"px-6 py-2 bg-blue-600 text-white font-semibold rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:m,children:m?"Updating...":"Update Alert"})})]})};function o({auth:a}){const{alert:l,holidays:d}=t().props;return e.jsx(s,{user:(null==a?void 0:a.user)||!1,header:e.jsx("h2",{className:"font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight",children:"Edit Alert"}),children:e.jsx("div",{className:"flex flex-col lg:flex-row mt-10",children:e.jsx("div",{className:"w-full",children:e.jsx(i,{alert:l,holidays:d})})})})}export{o 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.