import{k as D,a2 as M,s as R,E as F,o as i,b as d,a as u,t as $,m as w,F as G,h as T,c as E,i as c,u as r,w as q,f as I,d as f}from"../vendor-1-1-46.js";import{_ as S}from"../MdrSelect-1-1-46.js";import{u as x,_ as K}from"../ResourceStore-1-1-46.js";import{_ as L}from"../BarcodeModal-1-1-46.js";import{_ as P}from"../ShipmentListItem-1-1-46.js";import{u as W}from"../ApiRequestStore-1-1-46.js";import{e as j,s as z}from"../UiStore-1-1-46.js";import{i as H}from"../admin-app-1-1-46.js";import"../MdrModal-1-1-46.js";import"../ShipmentInfoModal-1-1-46.js";import"../admin-app-1-1-462.js";const J={class:"dokan-panel dokan-panel-default"},O={class:"dokan-panel-body"},Q={key:0,class:"mb-4"},X={class:"text-sm font-semibold text-gray-700 mb-2"},Y={class:"space-y-4"},Z={key:1,class:"w-full mb-3"},ee={key:2,class:"w-full mb-3"},te={__name:"App",setup(ae){var y,b,V,U;const{t:k}=D(),s=window.gcargo.order_data,o=M({list:window.gcargo.shipments||[],status:window.gcargo.shipment_status||"ready_for_shipment"}),m=window.gcargo.cargo_integrations||[],p=window.gcargo.warehouses||[],A=window.gcargo.shipment_setting||{},{shipment:l}=R(x()),{store:B}=x(),{getPdf:C}=W(),g=f({}),h=f([]),n=f(!1),_=f("");if(s){const t=((y=m.find(a=>a.is_default))==null?void 0:y.id)||((b=m[0])==null?void 0:b.id),e=((V=p.find(a=>a.is_default))==null?void 0:V.id)||((U=p[0])==null?void 0:U.id);l.value={...s,...A,customer:{...s.customer},lines:[...s.lines],cargo_integration_id:t,warehouse_id:e,desi:s.desi,kg:s.kg,is_pay_at_door:s.is_pay_at_door,invoice_number:s.invoice_number,waybill_number:s.waybill_number,platform_id:s.platform_id,platform_d_id:s.platform_d_id,package_count:s.package_count}}F(()=>o.list,t=>{t.forEach(e=>{h.value[e.id]===void 0&&(h.value[e.id]=!1)})},{immediate:!0});const N=async()=>{if(g.value={},!!l.value)try{const t=await B({data:{resource:"shipments",data:l.value},onValidationError:e=>{j({message:e.errors}),g.value=e.errors}});t&&t.id&&(o.list.push(t),o.list.length===1&&o.status==="ready_for_shipment"&&(o.status="partial_shipped")),z({message:k("resource_added",[k("shipment")])}),_.value=await C({data:{shipments:[t.id]}}),n.value=!0}catch(t){console.error("Error creating shipment:",t),g.value={general:["Gönderi oluşturulurken bir hata oluştu."]}}};return(t,e)=>(i(),d("div",J,[e[6]||(e[6]=u("div",{class:"dokan-panel-heading"},[u("strong",null,"Kargo Entegratör")],-1)),u("div",O,[o.list.length>0?(i(),d("div",Q,[u("h4",X," Mevcut Gönderiler ("+$(o.list.length)+") ",1),u("div",Y,[w(L,{modelValue:n.value,"onUpdate:modelValue":e[0]||(e[0]=a=>n.value=a),"pdf-url":_.value},null,8,["modelValue","pdf-url"]),(i(!0),d(G,null,T(o.list,a=>(i(),E(P,{key:a.id,shipment:a,modals:h.value,"pdf-url-modal":n.value,"pdf-url":_.value,"onUpdate:pdfUrlModal":e[1]||(e[1]=v=>n.value=v),"onUpdate:pdfUrl":e[2]||(e[2]=v=>_.value=v)},null,8,["shipment","modals","pdf-url-modal","pdf-url"]))),128))])])):c("",!0),r(p).length>1&&o.status!=="all_shipped"?(i(),d("div",Z,[w(S,{modelValue:r(l).warehouse_id,"onUpdate:modelValue":e[3]||(e[3]=a=>r(l).warehouse_id=a),options:r(p),"value-key":"id","text-key":"name",label:t.$t("warehouse")},null,8,["modelValue","options","label"])])):c("",!0),r(m).length>1&&o.status!=="all_shipped"?(i(),d("div",ee,[w(S,{modelValue:r(l).cargo_integration_id,"onUpdate:modelValue":e[4]||(e[4]=a=>r(l).cargo_integration_id=a),options:r(m),"value-key":"id","text-key":"name",label:t.$t("cargo_integration")},null,8,["modelValue","options","label"])])):c("",!0),o.status!=="all_shipped"?(i(),E(K,{key:3,class:"!w-full",onClick:e[5]||(e[5]=a=>N())},{default:q(()=>[I($(t.$t("create_fast_shipment")),1)]),_:1})):c("",!0)])]))}};H(te);
