1import{h as A,d as R,r as x,j as e,a as D,g as u,i as P,t as c}from"./index-BEBQyefh.js";import{u as U,a as T,F as V,b as o,c as l,C as d,d as m,o as E,s as h,f as $,l as _}from"./form-DgZy1aiB.js";import{I as j}from"./input-DfNyGJXt.js";import{T as k}from"./textarea-DzHnde_H.js";import{C as M,a as q,b as z,d as B}from"./card-DyVwCimA.js";import{S as w}from"./select-CCkhHNgp.js";import{c as H}from"./content-DsM0PwCS.js";import{g as G}from"./news-r4wQ8ge0.js";import{A as J}from"./arrow-left-Dg5pTMEd.js";import{n as C}from"./coerce-BYl0uTkR.js";import"./label-D0a2U9Rl.js";import"./chevron-down-F9b2-bWp.js";const K=E({title:h().min(1,"ÐаÑÑиг оÑÑÑлна ÑÑ"),type:$(["text","news","pdf","image"],{required_error:"ТөÑөл Ñонгоно ÑÑ"}),body:h().optional(),file_url:h().url("Ðөв URL оÑÑÑлна ÑÑ").optional().or(_("")),news_id:C().int().positive("ÐÑдÑÑний ID оÑÑÑлна ÑÑ").optional().or(_("")),order_number:C().int().min(0).optional()}).refine(n=>!(n.type==="news"&&!n.news_id),{message:"ÐÑдÑÑний ÑÓ©Ñөл ÑонгоÑон бол мÑдÑÑ Ñонгоно ÑÑ",path:["news_id"]}).refine(n=>!((n.type==="pdf"||n.type==="image")&&!n.file_url),{message:"PDF ÑÑвÑл зÑÑÐ°Ð³Ð½Ñ ÑÓ©Ñөл ÑонгоÑон бол ÑайлÑн URL оÑÑÑлна ÑÑ",path:["file_url"]});function oe(){const{menuId:n}=A(),f=R(),[N,L]=x.useState([]),[g,b]=x.useState(!1),{control:a,handleSubmit:S,watch:F,setValue:O,formState:{errors:t,isSubmitting:y}}=U({resolver:T(K),defaultValues:{title:"",type:"text",body:"",file_url:"",news_id:"",order_number:0}}),i=F("type");x.useEffect(()=>{i==="news"&&I()},[i]);const I=async()=>{b(!0);try{const r=await G(),s=r.data?.data||r.data||r,p=Array.isArray(s)?s:[];L(p)}catch(r){console.error("ÐÑдÑÑ Ð°Ð²Ð°Ñ
ад алдаа:",r)}finally{b(!1)}},v=async r=>{try{if(r.type==="news"&&!r.news_id){c.error("ÐÑдÑÑний ÑÓ©Ñөл ÑонгоÑон бол мÑдÑÑ Ñонгоно ÑÑ");return}if((r.type==="pdf"||r.type==="image")&&!r.file_url){c.error("PDF ÑÑвÑл зÑÑÐ°Ð³Ð½Ñ ÑÓ©Ñөл ÑонгоÑон бол ÑайлÑн URL оÑÑÑлна ÑÑ");return}const s={title:r.title,menu_id:parseInt(n),type:r.type,body:r.body&&r.body.trim()?r.body:null,file_url:r.file_url&&r.file_url.trim()?r.file_url.trim():null,news_id:r.news_id?parseInt(r.news_id):null,order_number:r.order_number||0};await H(s),c.success("ÐонÑÐµÐ½Ñ Ð°Ð¼Ð¶Ð¸Ð»ÑÑай Ò¯Ò¯ÑгÑлÑÑ!"),f(`/admin/content/${n}`)}catch(s){console.error("ÐонÑÐµÐ½Ñ Ò¯Ò¯ÑгÑÑ
Ñд алдаа:",s);const p=s.response?.data?.error||s.response?.data?.message||"ÐонÑÐµÐ½Ñ Ò¯Ò¯ÑгÑÑ
Ñд алдаа гаÑлаа";c.error(p)}};return e.jsxs("div",{className:"p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(D,{to:`/admin/content/${n}`,children:e.jsx(u,{variant:"ghost",size:"icon",children:e.jsx(J,{className:"h-4 w-4"})})}),e.jsx("h1",{className:"text-2xl font-bold",children:"ÐонÑÐµÐ½Ñ Ð½ÑмÑÑ
"})]}),e.jsxs(M,{children:[e.jsx(q,{children:e.jsx(z,{children:"ÐонÑенÑний мÑдÑÑлÑл"})}),e.jsx(B,{children:e.jsxs(V,{onSubmit:S(v),children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(o,{children:[e.jsx(l,{children:"ÐаÑÑиг *"}),e.jsx(d,{name:"title",control:a,render:({field:r})=>e.jsx(j,{placeholder:"ÐонÑенÑний гаÑÑиг оÑÑÑлна ÑÑ",...r})}),t.title&&e.jsx(m,{children:t.title.message})]}),e.jsxs(o,{children:[e.jsx(l,{children:"ТөÑөл *"}),e.jsx(d,{name:"type",control:a,render:({field:r})=>e.jsx(w,{value:r.value,onValueChange:r.onChange,options:[{value:"text",label:"ТекÑÑ"},{value:"news",label:"ÐÑдÑÑ"},{value:"pdf",label:"PDF"},{value:"image",label:"ÐÑÑаг"}]})}),t.type&&e.jsx(m,{children:t.type.message})]}),i==="text"&&e.jsxs(o,{children:[e.jsx(l,{children:"ÐгÑÑлга"}),e.jsx(d,{name:"body",control:a,render:({field:r})=>e.jsx(k,{placeholder:"ÐонÑенÑний агÑÑлга оÑÑÑлна ÑÑ",rows:6,...r})}),t.body&&e.jsx(m,{children:t.body.message})]}),i==="news"&&e.jsxs(o,{children:[e.jsx(l,{children:"ÐÑдÑÑ *"}),e.jsx(d,{name:"news_id",control:a,render:({field:r})=>e.jsx(w,{value:r.value?.toString()||"",onValueChange:s=>r.onChange(s?parseInt(s):""),options:N.map(s=>({value:s.id.toString(),label:s.title})),disabled:g,placeholder:g?"ÐÑдÑÑ Ð°Ñааллаж байна...":"ÐÑдÑÑ Ñонгоно ÑÑ"})}),t.news_id&&e.jsx(m,{children:t.news_id.message})]}),(i==="pdf"||i==="image")&&e.jsxs(o,{children:[e.jsx(l,{children:"ФайлÑн URL *"}),e.jsx(d,{name:"file_url",control:a,render:({field:r})=>e.jsx(j,{placeholder:"PDF ÑÑвÑл зÑÑÐ°Ð³Ð½Ñ URL оÑÑÑлна ÑÑ",...r})}),t.file_url&&e.jsx(m,{children:t.file_url.message})]}),e.jsxs(o,{children:[e.jsx(l,{children:"ÐÑÑмбÑ"}),e.jsx(d,{name:"order_number",control:a,render:({field:r})=>
1e.jsx(j,{type:"number",min:"0",placeholder:"0",...r,onChange:s=>r.onChange(parseInt(s.target.value)||0)})}),t.order_number&&e.jsx(m,{children:t.order_number.message})]})]}),e.jsxs("div",{className:"flex gap-4 mt-6",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>f(`/admin/content/${n}`),children:"ЦÑÑлаÑ
"}),e.jsx(u,{type:"submit",disabled:y,className:"bg-red-600 hover:bg-red-700",children:y?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"mr-2 h-4 w-4 animate-spin"}),"Хадгалж байна..."]}):"ХадгалаÑ
"})]})]})})]})]})}export{oe 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.