import{u as H,r as T,j as e,L as v}from"./vendor-react-BwKDLVNL.js";import{o as O,c8 as K,aD as V,v as k,w as I,x as j,y as g,B as p,A as _,H as P,z as x,F as N,I as w,b3 as J,aJ as q,ca as Y,cb as t,cc as a,cd as r,ce as l,Z as o,cJ as E,cf as c,J as U,_ as $,$ as W,a0 as X,a1 as Z,a2 as A,a3 as G,k as Q}from"./index-C1ye5P3I.js";import{a as ee,o as ie,_ as se,s as h}from"./schemas-Ba8mALQO.js";import"./vendor-dayjs-5tvLiZdS.js";import{M as ne}from"./MarketingShell-pJlumM7K.js";import{u as te}from"./vendor-i18n-C6wqqoou.js";import{A as ae}from"./arrow-left-Em93IgUy.js";import{M as re}from"./megaphone-CD_EV-Yg.js";import{C as le}from"./circle-alert-XbZmU1vE.js";import{S as ce}from"./send-BPZS28JS.js";import"./vendor-query-D-sr233n.js";import"./vendor-sentry-B6ofghpF.js";import"./vendor-antd-core-4y2ghozH.js";import"./zap-Bd320S-h.js";import"./globe-C6LFgqFt.js";import"./shield-check-CUe1YrFZ.js";import"./users-BQu_O3JR.js";import"./file-text-cRwgk8Y4.js";import"./SiteFooter-CMa-vyJL.js";import"./building-2-BaHHBpzk.js";const S=i=>h().trim().refine(d=>d===""||Number.isFinite(Number(d))&&Number(d)>0,i("exchangeUi.publish.validation.positiveNumber","Должно быть положительное число"));function de(i){return ie({title:h().trim().max(120),cityFrom:h().trim().min(2,i("exchangeUi.publish.validation.cityFrom","Укажите РіРѕСЂРѕРґ отправления")),cityTo:h().trim().min(2,i("exchangeUi.publish.validation.cityTo","Укажите РіРѕСЂРѕРґ назначения")),cargoType:h().trim(),weightKg:S(i),volumeM3:S(i),containerType:h().trim(),pickupReadyAt:h().trim(),latestDeliveryAt:h().trim(),deadlineAt:h().trim(),budgetUsd:S(i),incoterms:h().trim(),comment:h().trim().max(2e3),visibilityMode:se(["SEALED","OPEN","TIERED"])})}const oe={title:"",cityFrom:"",cityTo:"",cargoType:"",weightKg:"",volumeM3:"",containerType:"",pickupReadyAt:"",latestDeliveryAt:"",deadlineAt:"",budgetUsd:"",incoterms:"",comment:"",visibilityMode:"SEALED"};function M(i){const d=i.trim();if(!d)return;const m=Number(d);return Number.isFinite(m)&&m>0?m:void 0}function he(i){return{title:i.title||void 0,cityFrom:i.cityFrom,cityTo:i.cityTo,cargoType:i.cargoType||void 0,weightKg:M(i.weightKg),volumeM3:M(i.volumeM3),containerType:i.containerType||void 0,pickupReadyAt:i.pickupReadyAt||void 0,latestDeliveryAt:i.latestDeliveryAt||void 0,deadlineAt:i.deadlineAt||void 0,budgetUsd:M(i.budgetUsd),incoterms:i.incoterms||void 0,comment:i.comment||void 0,visibilityMode:i.visibilityMode}}function xe(i){return{SEALED:{label:i("exchangeUi.publish.visibility.sealedLabel","Sealed (РїРѕ умолчанию)"),hint:i("exchangeUi.publish.visibility.sealedHint","Ставки скрыты, бюджет РЅРµ виден перевозчикам — честная цена")},OPEN:{label:"Open",hint:i("exchangeUi.publish.visibility.openHint","Р’СЃРµ ставки Рё бюджет публичны — быстрая конкуренция")},TIERED:{label:"Tiered",hint:i("exchangeUi.publish.visibility.tieredHint","Перевозчик РІРёРґРёС‚ топ-3 ставки + СЃРІРѕСЋ позицию")}}}function Le(){const{t:i}=te(),d=xe(i),{isAuthenticated:m}=O(),R=H(),[b,y]=T.useState("form"),[f,C]=T.useState(null),[F,D]=T.useState(null),n=K({resolver:ee(de(i)),defaultValues:oe,mode:"onBlur"});async function z(s){y("submitting"),D(null);try{if(m){const u=await Q.create(he(s));C(u.id),y("success")}else await new Promise(u=>setTimeout(u,800)),C(0),y("success")}catch(u){D(u instanceof Error?u.message:i("exchangeUi.publish.submitErrorFallback","Ошибка публикации заявки")),y("error")}}const B=b==="success";return e.jsxs(ne,{children:[e.jsx(V,{children:e.jsx("title",{children:i("exchangeUi.publish.meta.title","Опубликовать заявку В· Avalog")})}),e.jsx(k,{py:"md",bg:"surface",children:e.jsx(I,{size:"base",children:e.jsxs(j,{gap:4,children:[e.jsxs(g,{gap:3,align:"center",wrap:!0,children:[e.jsx(p,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(v,{to:"/exchange","data-testid":"m-exchange-new-back",children:[e.jsx(ae,{className:"h-4 w-4"}),i("exchangeUi.detail.backToExchange","Рљ Р±РёСЂР¶Рµ")]})}),e.jsxs(_,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"}),i("exchangeUi.publish.badge","Биржа")]})]}),e.jsx(P,{size:"h2",as:"h1",children:i("exchangeUi.publish.title","Опубликовать заявку")}),e.jsx(x,{variant:"muted",className:"text-sm",children:i("exchangeUi.publish.subtitle","Опишите маршрут Рё РіСЂСѓР·. Перевозчики подадут ставки РґРѕ дедлайна — выберете лучшую.")})]})})}),e.jsx(k,{py:"md",bg:"base",children:e.jsx(I,{size:"base",children:e.jsxs("div",{className:"mx-auto max-w-3xl",children:[!m&&b==="form"?e.jsx(N,{"data-testid":"m-exchange-new-login-banner",className:"mb-4",children:e.jsx(w,{className:"py-4",children:e.jsxs(g,{justify:"between",align:"center",wrap:!0,gap:3,children:[e.jsxs(g,{gap:2,align:"center",children:[e.jsx(J,{className:"h-4 w-4 text-text-muted"}),e.jsx(x,{className:"text-sm",children:i("exchangeUi.publish.demoBanner","Демо-форма. Войдите чтобы реально опубликовать заявку.")})]}),e.jsx(p,{asChild:!0,variant:"default",size:"sm",children:e.jsx(v,{to:"/login",children:i("exchangeUi.detail.loginBanner.cta","Войти")})})]})})}):null,B?e.jsx(N,{"data-testid":"m-exchange-new-success",children:e.jsx(w,{className:"py-12",children:e.jsxs(j,{gap:3,align:"center",children:[e.jsx(q,{className:"h-12 w-12 text-primary"}),e.jsx(P,{size:"h3",as:"h2",children:i("exchangeUi.publish.successTitle","Заявка опубликована")}),m&&f?e.jsx(x,{variant:"muted",className:"text-sm text-center",children:i("exchangeUi.publish.successText","Номер заявки: #{{id}}. Перевозчики начнут подавать ставки РІ течение часа.",{id:f})}):e.jsx(x,{variant:"muted",className:"text-sm text-center",children:i("exchangeUi.publish.mockSuccessText","Mock-публикация. Войдите чтобы реально опубликовать.")}),e.jsxs(g,{gap:2,wrap:!0,justify:"center",children:[m&&f?e.jsx(p,{asChild:!0,variant:"default",size:"sm",children:e.jsx(v,{to:`/exchange/${f}`,"data-testid":"m-exchange-new-success-open",children:i("exchangeUi.publish.openRequest","Открыть заявку")})}):e.jsx(p,{asChild:!0,variant:"default",size:"sm",children:e.jsx(v,{to:"/login",children:i("exchangeUi.detail.loginBanner.cta","Войти")})}),e.jsx(p,{asChild:!0,variant:"outline",size:"sm",children:e.jsx(v,{to:"/exchange",children:i("exchangeUi.detail.backToExchange","Рљ Р±РёСЂР¶Рµ")})})]})]})})}):e.jsx(N,{children:e.jsx(w,{className:"py-6",children:e.jsx(Y,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(z),className:"space-y-5","data-testid":"m-exchange-new-form",children:[e.jsxs(j,{gap:3,children:[e.jsx(x,{variant:"caption",children:i("exchangeUi.publish.sections.route","Маршрут")}),e.jsx(t,{control:n.control,name:"title",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.publish.fields.titleLabel","Название (опционально)")}),e.jsx(l,{children:e.jsx(o,{placeholder:i("exchangeUi.publish.fields.titlePlaceholder","например, Рлектроника РёР· Шэньчжэня"),...s})}),e.jsx(E,{children:i("exchangeUi.publish.fields.titleHelp","Помогает быстрее найти заявку РІ СЃРїРёСЃРєРµ.")}),e.jsx(c,{})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(t,{control:n.control,name:"cityFrom",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.publish.fields.cityFromLabel","Город отправления")}),e.jsx(l,{children:e.jsx(o,{placeholder:i("exchangeUi.create.route.fromPlaceholder","Шанхай"),...s})}),e.jsx(c,{})]})}),e.jsx(t,{control:n.control,name:"cityTo",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.publish.fields.cityToLabel","Город назначения")}),e.jsx(l,{children:e.jsx(o,{placeholder:i("exchangeUi.create.route.toPlaceholder","РњРѕСЃРєРІР°"),...s})}),e.jsx(c,{})]})})]})]}),e.jsx(U,{}),e.jsxs(j,{gap:3,children:[e.jsx(x,{variant:"caption",children:i("exchangeUi.publish.sections.cargo","Груз")}),e.jsx(t,{control:n.control,name:"cargoType",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.cargoType","РўРёРї РіСЂСѓР·Р°")}),e.jsx(l,{children:e.jsx(o,{placeholder:i("exchangeUi.publish.fields.cargoTypePlaceholder","Рлектроника, текстиль..."),...s})}),e.jsx(c,{})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(t,{control:n.control,name:"containerType",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.containerType","РўРёРї контейнера")}),e.jsx(l,{children:e.jsx(o,{placeholder:"20 DC, 40 HC...",...s})}),e.jsx(c,{})]})}),e.jsx(t,{control:n.control,name:"weightKg",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.weightKg","Вес, РєРі")}),e.jsx(l,{children:e.jsx(o,{inputMode:"numeric",placeholder:"12000",...s})}),e.jsx(c,{})]})}),e.jsx(t,{control:n.control,name:"volumeM3",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.volumeM3","Объём, РјВі")}),e.jsx(l,{children:e.jsx(o,{inputMode:"numeric",placeholder:"32",...s})}),e.jsx(c,{})]})})]}),e.jsx(t,{control:n.control,name:"incoterms",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:"Incoterms"}),e.jsx(l,{children:e.jsx(o,{placeholder:"FOB, EXW, CIF...",...s})}),e.jsx(c,{})]})})]}),e.jsx(U,{}),e.jsxs(j,{gap:3,children:[e.jsx(x,{variant:"caption",children:i("exchangeUi.publish.sections.dates","РЎСЂРѕРєРё")}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(t,{control:n.control,name:"pickupReadyAt",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.pickupReady","Готов Рє забору")}),e.jsx(l,{children:e.jsx(o,{type:"date",...s})}),e.jsx(c,{})]})}),e.jsx(t,{control:n.control,name:"latestDeliveryAt",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.latestDelivery","Доставить РЅРµ РїРѕР·Р¶Рµ")}),e.jsx(l,{children:e.jsx(o,{type:"date",...s})}),e.jsx(c,{})]})}),e.jsx(t,{control:n.control,name:"deadlineAt",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.bidsDeadline","Дедлайн приёма ставок")}),e.jsx(l,{children:e.jsx(o,{type:"date",...s})}),e.jsx(c,{})]})})]})]}),e.jsx(U,{}),e.jsxs(j,{gap:3,children:[e.jsx(x,{variant:"caption",children:i("exchangeUi.publish.sections.budgetVisibility","Бюджет Рё видимость ставок")}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(t,{control:n.control,name:"budgetUsd",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.publish.fields.budgetLabel","Бюджет, USD (РѕРїС†.)")}),e.jsx(l,{children:e.jsx(o,{inputMode:"numeric",placeholder:"4500",...s})}),e.jsx(E,{children:i("exchangeUi.publish.fields.budgetHelp","Р’ sealed-bid режиме — скрыт РѕС‚ перевозчиков.")}),e.jsx(c,{})]})}),e.jsx(t,{control:n.control,name:"visibilityMode",render:({field:s})=>{var u,L;return e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.publish.fields.auctionMode","Режим аукциона")}),e.jsxs($,{value:s.value,onValueChange:s.onChange,children:[e.jsx(l,{children:e.jsx(W,{"data-testid":"m-exchange-new-visibility",children:e.jsx(X,{children:(u=d[s.value])==null?void 0:u.label})})}),e.jsxs(Z,{children:[e.jsx(A,{value:"SEALED",children:d.SEALED.label}),e.jsx(A,{value:"OPEN",children:d.OPEN.label}),e.jsx(A,{value:"TIERED",children:d.TIERED.label})]})]}),e.jsx(E,{children:(L=d[s.value])==null?void 0:L.hint}),e.jsx(c,{})]})}})]})]}),e.jsx(U,{}),e.jsx(t,{control:n.control,name:"comment",render:({field:s})=>e.jsxs(a,{children:[e.jsx(r,{children:i("exchangeUi.detail.fields.comment","Комментарий")}),e.jsx(l,{children:e.jsx(G,{placeholder:i("exchangeUi.publish.fields.commentPlaceholder","Особенности РіСЂСѓР·Р°, требования Рє перевозчику..."),rows:4,...s})}),e.jsx(c,{})]})}),b==="error"&&F?e.jsxs(g,{gap:2,align:"center","data-testid":"m-exchange-new-error",children:[e.jsx(le,{className:"h-4 w-4 text-text-muted"}),e.jsx(x,{variant:"muted",className:"text-xs",children:F})]}):null,e.jsxs(g,{gap:2,align:"center",wrap:!0,children:[e.jsxs(p,{type:"submit",variant:"default",disabled:b==="submitting","data-testid":"m-exchange-new-submit",children:[e.jsx(ce,{className:"h-4 w-4"}),b==="submitting"?i("exchangeUi.publish.submitting","Публикуем..."):i("exchangeUi.publish.submit","Опубликовать")]}),m?null:e.jsx(x,{variant:"muted",className:"text-xs",children:i("exchangeUi.publish.demoHint","Demo mode — реальная публикация РїСЂРё auth.")})]})]})})})}),e.jsx("span",{"data-testid":"m-exchange-new-nav-ref",hidden:!0,children:typeof R=="function"?"1":"0"})]})})})]})}export{de as buildCreateRequestSchema,Le as default,he as formToPayload};