import{k as D,a2 as G,s as M,d as c,G as R,b as d,o as l,a as u,i as f,c as $,t as E,m as w,F,j as T,u as r,w as j,g as q}from"../vendor-1-1-40.js";import{_ as S}from"../MdrSelect-1-1-40.js";import{u as x,_ as I}from"../ResourceStore-1-1-40.js";import{_ as K}from"../BarcodeModal-1-1-40.js";import{_ as L}from"../ShipmentListItem-1-1-40.js";import{u as P}from"../ApiRequestStore-1-1-40.js";import{e as W,s as z}from"../UiStore-1-1-40.js";import{i as H}from"../admin-app-1-1-40.js";import"../MdrModal-1-1-40.js";import"../ShipmentInfoModal-1-1-40.js";import"../admin-app-1-1-402.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=G({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:i}=M(x()),{store:B}=x(),{getPdf:C}=P(),g=c({}),h=c([]),n=c(!1),_=c("");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);i.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.id,platform_d_id:s.id,package_count:s.package_count}}R(()=>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={},!!i.value)try{const t=await B({data:{resource:"shipments",data:i.value},onValidationError:e=>{W({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)=>(l(),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?(l(),d("div",Q,[u("h4",X," Mevcut Gönderiler ("+E(o.list.length)+") ",1),u("div",Y,[w(K,{modelValue:n.value,"onUpdate:modelValue":e[0]||(e[0]=a=>n.value=a),"pdf-url":_.value},null,8,["modelValue","pdf-url"]),(l(!0),d(F,null,T(o.list,a=>(l(),$(L,{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))])])):f("",!0),r(p).length>1&&o.status!=="all_shipped"?(l(),d("div",Z,[w(S,{modelValue:r(i).warehouse_id,"onUpdate:modelValue":e[3]||(e[3]=a=>r(i).warehouse_id=a),options:r(p),"value-key":"id","text-key":"name",label:t.$t("warehouse")},null,8,["modelValue","options","label"])])):f("",!0),r(m).length>1&&o.status!=="all_shipped"?(l(),d("div",ee,[w(S,{modelValue:r(i).cargo_integration_id,"onUpdate:modelValue":e[4]||(e[4]=a=>r(i).cargo_integration_id=a),options:r(m),"value-key":"id","text-key":"name",label:t.$t("cargo_integration")},null,8,["modelValue","options","label"])])):f("",!0),o.status!=="all_shipped"?(l(),$(I,{key:3,class:"!w-full",onClick:e[5]||(e[5]=a=>N())},{default:j(()=>[q(E(t.$t("create_fast_shipment")),1)]),_:1})):f("",!0)])]))}};H(te);
