Sid Gifari File Manager
🏠Root
/
home
/
ailwtbdh
/
public_html
/
wp-content
/
plugins
/
woocommerce
/
assets
/
client
/
admin
/
wp-admin-scripts
/
Editing: fulfillments.js
/*! For license information please see fulfillments.js.LICENSE.txt */ (()=>{"use strict";var e={94931:(e,t,r)=>{var l=r(51609),o=Symbol.for("react.element"),n=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,s=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,r){var l,n={},a=null,m=null;for(l in void 0!==r&&(a=""+r),void 0!==t.key&&(a=""+t.key),void 0!==t.ref&&(m=t.ref),t)i.call(t,l)&&!c.hasOwnProperty(l)&&(n[l]=t[l]);if(e&&e.defaultProps)for(l in t=e.defaultProps)void 0===n[l]&&(n[l]=t[l]);return{$$typeof:o,type:e,key:a,ref:m,props:n,_owner:s.current}}t.Fragment=n,t.jsx=a,t.jsxs=a},39793:(e,t,r)=>{e.exports=r(94931)},51609:e=>{e.exports=window.React}},t={};function r(l){var o=t[l];if(void 0!==o)return o.exports;var n=t[l]={exports:{}};return e[l](n,n.exports,r),n.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var l in t)r.o(t,l)&&!r.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};r.r(l),r.d(l,{default:()=>We});var o=r(51609),n=r.n(o);const i=window.wp.element,s=window.wc.navigation,c=window.wc.tracks,a=window.wp.i18n,m=window.wp.components,d=window.wp.data,u=[...Object.values(window.wcFulfillmentSettings.providers??{}),{label:(0,a.__)("Other","woocommerce"),icon:null,value:"other",url:""}],f=window.wp.apiFetch;var h=r.n(f);const p=window.wp.url,_=(e,t)=>{if(e&&"object"==typeof e&&"message"in e&&"code"in e){const t=e;if("woocommerce_fulfillment_error"===t.code)return t.message}return t},w="SET_ORDER",x="SET_REFUNDS",g="SET_LOADING",v="SET_ERROR",j="SET_FULFILLMENTS",b="SET_FULFILLMENT",y="DELETE_FULFILLMENT",C={orderMap:{}},k={setOrder:(e,t)=>({type:w,orderId:e,order:t}),setRefunds:(e,t)=>({type:x,orderId:e,refunds:t}),setLoading:(e,t)=>({type:g,orderId:e,isLoading:t}),setError:(e,t)=>({type:v,orderId:e,error:t}),setFulfillments:(e,t)=>({type:j,orderId:e,fulfillments:t}),setFulfillment:(e,t,r)=>({type:b,orderId:e,fulfillmentId:t,fulfillment:r}),deleteFulfillmentRecord:(e,t)=>({type:y,orderId:e,fulfillmentId:t})},N={...k,saveFulfillment:(e,t,r)=>async({dispatch:l})=>{l.setLoading(e,!0),l.setError(e,null);try{const o=await h()({path:(0,p.addQueryArgs)(`/wc/v3/orders/${e}/fulfillments`,{notify_customer:r}),method:"POST",data:t,headers:{"Content-Type":"application/json","X-WC-Fulfillments-UI":"true"}});if(!o.id)throw new Error("Fulfillment ID is missing in response");l.setFulfillment(e,o.id,o)}catch(t){l.setError(e,_(t,"Failed to save fulfillment"))}finally{l.setLoading(e,!1)}},updateFulfillment:(e,t,r)=>async({dispatch:l})=>{if(l.setLoading(e,!0),l.setError(e,null),!t.id)return l.setError(e,"Fulfillment ID is required"),void l.setLoading(e,!1);try{const o=await h()({path:(0,p.addQueryArgs)(`/wc/v3/orders/${e}/fulfillments/${t.id}`,{notify_customer:r}),method:"PUT",data:t,headers:{"Content-Type":"application/json","X-WC-Fulfillments-UI":"true"}});if(!o.id)throw new Error("Fulfillment ID is missing in response");l.setFulfillment(e,o.id,o)}catch(t){l.setError(e,_(t,"Failed to update fulfillment"))}finally{l.setLoading(e,!1)}},deleteFulfillment:(e,t,r)=>async({dispatch:l})=>{l.setLoading(e,!0),l.setError(e,null);try{await h()({path:(0,p.addQueryArgs)(`/wc/v3/orders/${e}/fulfillments/${t}`,{notify_customer:r}),method:"DELETE",headers:{"Content-Type":"application/json","X-WC-Fulfillments-UI":"true"}}),l.deleteFulfillmentRecord(e,t)}catch(t){l.setError(e,_(t,"Failed to delete fulfillment"))}finally{l.setLoading(e,!1)}}},E={getOrder:e=>async({dispatch:t})=>{t.setLoading(e,!0),t.setError(e,null);try{const r=await h()({path:`/wc/v3/orders/${e}`,method:"GET"});if(t.setOrder(e,r),r.refunds.length>0){const r=await h()({path:`/wc/v3/orders/${e}/refunds`,method:"GET"});t.setRefunds(e,r)}}catch(r){t.setError(e,r instanceof Error?r.message:"Failed to load order")}finally{t.setLoading(e,!1)}},readFulfillments:e=>async({dispatch:t})=>{t.setLoading(e,!0),t.setError(e,null);try{const r=await h()({path:`/wc/v3/orders/${e}/fulfillments`,method:"GET"});t.setFulfillments(e,r)}catch(r){t.setError(e,r instanceof Error?r.message:"Failed to load fulfillments")}finally{t.setLoading(e,!1)}}},S=(0,d.createReduxStore)("order/fulfillments",{reducer:function(e=C,t){const r=e.orderMap[t.orderId]||{order:null,refunds:[],fulfillments:[],loading:!1,error:null};switch(t.type){case w:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,order:t.order}}};case x:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,refunds:t.refunds}}};case g:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,loading:t.isLoading}}};case v:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,error:t.error}}};case j:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,fulfillments:t.fulfillments}}};case b:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,fulfillments:[...r.fulfillments.filter((e=>e.id!==t.fulfillmentId)),t.fulfillment]}}};case y:return{...e,orderMap:{...e.orderMap,[t.orderId]:{...r,fulfillments:r.fulfillments.filter((e=>e.id!==t.fulfillmentId))}}};default:return e}},actions:N,selectors:{getState:e=>e,getOrder:(e,t)=>e.orderMap[t]?.order,getRefunds:(e,t)=>e.orderMap[t]?.refunds||[],isLoading:(e,t)=>!!e.orderMap[t]?.loading,getError:(e,t)=>e.orderMap[t]?.error||null,readFulfillments:(e,t)=>e.orderMap[t]?.fulfillments||[],readFulfillment:(e,t,r)=>e.orderMap[t]?.fulfillments?.find((e=>e.id===r))||null},resolvers:E});function F(e,t,r){if(!e)return r;const l=e.meta_data.find((e=>e.key===t))?.value;return l||r}function I(e){return F(e,"_items",[])}async function M(e){(0,d.dispatch)(S).invalidateResolution("getOrder",[e]);const t=await(0,d.resolveSelect)(S).getOrder(e);if(t){const r=t.meta_data.find((e=>"_fulfillment_status"===e.key))?.value??"no_fulfillments",l=document.querySelector(`.order-${e} td.fulfillment_status mark`);if(l){const e=window.wcFulfillmentSettings.order_fulfillment_statuses[r]||{label:(0,a.__)("Unknown","woocommerce"),background_color:"#f8f9fa",text_color:"#6c757d"},t=l.querySelector("span");if(t)t.textContent=e.label;else{const t=document.createElement("span");t.textContent=e.label,l.replaceChildren(t)}l.setAttribute("style",`background-color: ${e.background_color}; color: ${e.text_color};`)}}}function L(e){const t=u.find((t=>t.value===e));return t?t.label:""}(0,d.register)(S);const O="_shipping_option",H="_tracking_number",T="_tracking_url",R="_shipment_provider",D="_provider_name",P="tracking-number",V="manual-entry",B="no-info",U=P;var z=r(39793);const A={selectedOption:U,setSelectedOption:()=>{},trackingNumber:"",setTrackingNumber:()=>{},shipmentProvider:"",setShipmentProvider:()=>{},trackingUrl:"",setTrackingUrl:()=>{},providerName:"",setProviderName:()=>{}},Z=(0,o.createContext)(A),$=()=>{const e=n().useContext(Z);if(!e)throw new Error("useShipmentFormContext must be used within a ShipmentFormProvider");return e},q=({fulfillment:e=null,children:t})=>{const[r,l]=n().useState(A.selectedOption),[i,s]=n().useState(A.trackingNumber),[c,a]=n().useState(A.shipmentProvider),[m,d]=n().useState(A.trackingUrl),[u,f]=n().useState(A.providerName);n().useEffect((()=>{l(F(e,O,"tracking-number")),s(F(e,H,"")),a(F(e,R,"")),d(F(e,T,"")),f(F(e,D,""))}),[e]);const h=(0,o.useMemo)((()=>({selectedOption:r,setSelectedOption:l,trackingNumber:i,setTrackingNumber:s,shipmentProvider:c,setShipmentProvider:a,trackingUrl:m,setTrackingUrl:d,providerName:u,setProviderName:f})),[r,l,i,s,c,a,m,d,u,f]);return(0,z.jsx)(Z.Provider,{value:h,children:t})},K=(0,o.createContext)({order:null,fulfillment:null,setFulfillment:()=>{},selectedItems:[],setSelectedItems:()=>{},notifyCustomer:!0,setNotifyCustomer:()=>{}}),W=()=>{const e=n().useContext(K);if(!e)throw new Error("useFulfillmentContext must be used within a FulfillmentProvider");return e},G=({order:e,fulfillment:t,items:r,children:l})=>{const[i,s]=n().useState(t??null),[c,a]=n().useState(!0),{selectedOption:m,trackingNumber:d,trackingUrl:u,shipmentProvider:f,providerName:h}=$(),[p,_]=(0,o.useState)(r??[]);(0,o.useEffect)((()=>{_(r??[])}),[r]),(0,o.useEffect)((()=>{s(e?.id?{id:t?.id??void 0,entity_id:String(e.id),entity_type:"WC_Order",is_fulfilled:t?.is_fulfilled??!1,status:t?.status??"unfulfilled",meta_data:[{id:0,key:O,value:m},{id:0,key:H,value:m===B?"":d},{id:0,key:T,value:m===B?"":u},{id:0,key:R,value:m===B?"":f},{id:0,key:D,value:m===B?"":h},{id:0,key:"_items",value:p.map((e=>({item_id:e.item_id,qty:e.selection.filter((e=>e.checked)).length}))).filter((e=>e.qty>0))}]}:null)}),[e,d,u,f,h,m,t,p]);const w=(0,o.useMemo)((()=>({order:e,fulfillment:i,setFulfillment:s,selectedItems:p,setSelectedItems:_,notifyCustomer:c,setNotifyCustomer:a})),[e,i,s,p,_,c,a]);return(0,z.jsx)(K.Provider,{value:w,children:l})},Q=window.wp.compose,Y=window.lodash,X=(e,t)=>I(t).map((t=>{const r=e.line_items.find((e=>e.id===t.item_id));return{item_id:t.item_id,item:r||{},selection:(0,Y.range)(t.qty).map((e=>({index:e,checked:!0})))}})),J=(e,t)=>{const r={};return e.forEach((e=>{r[e.item_id]={...e}})),t.forEach((e=>{r[e.item_id]?r[e.item_id].selection=[...r[e.item_id].selection,...e.selection].map(((e,t)=>(e.index=t,e))):r[e.item_id]={...e}})),Object.values(r)},ee=(e,t)=>{const r={};return e.forEach((e=>{r[e.item_id]={...e}})),t.forEach((e=>{r[e.item_id]?(r[e.item_id].selection.splice(0,e.selection.length),r[e.item_id].selection=r[e.item_id].selection.map(((e,t)=>(e.index=t,e)))):r[e.item_id]={...e}})),Object.values(r)},te=(e,t,r=[])=>{let l=(e=>{const t=[];return e.line_items.forEach((e=>{t.push({item_id:e.id,item:e,selection:(0,Y.range)(e.quantity).map((e=>({index:e,checked:!1})))})})),t})(t);if(r.length>0){const e=r.reduce(((e,t)=>{const r=t.line_items.map((e=>({item_id:l.find((t=>t.item.product_id===e.product_id))?.item_id||e.id,item:e,selection:(0,Y.range)(-e.quantity).map((e=>({index:e,checked:!0})))})));return J(e,r)}),[]);l=ee(l,e)}if(e.length>0){const r=e.reduce(((e,r)=>{const l=X(t,r);return J(e,l)}),[]);l=ee(l,r)}return l.filter((e=>e.selection.length>0))},re=(0,o.createContext)({fulfillments:[],setFulfillments:()=>{},order:null,setOrder:()=>{},refunds:[],setRefunds:()=>{},openSection:"",setOpenSection:()=>{},isEditing:!1,setIsEditing:()=>{}}),le=()=>{const e=n().useContext(re);if(!e)throw new Error("useFulfillmentDrawerContext must be used within a FulfillmentDrawerProvider");return e},oe=({orderId:e,children:t})=>{const[r,l]=(0,o.useState)("order"),[n,i]=(0,o.useState)(!1),[s,c]=(0,o.useState)(),[a,m]=(0,o.useState)(),[u,f]=(0,o.useState)();return(0,d.useSelect)((t=>{if(!e)return;const r=t(S),l=r.getOrder(e),o=r.readFulfillments(e),n=r.getRefunds(e);(0,Y.isEqual)(l,u)||(f(l),i(!1)),(0,Y.isEqual)(n,a)||(m(n??[]),i(!1)),(0,Y.isEqual)(o,s)||(c(o??[]),i(!1))}),[e,s,u,a]),(0,o.useLayoutEffect)((()=>{u&&s&&te(s,u,a).length>0?l("order"):s&&1===s.length?l("fulfillment-"+s[0].id):s&&s.length>0?l("fulfillment-"+s[s.length-1].id):l("")}),[e,s,u,a]),null===e?null:(0,z.jsx)(re.Provider,{value:{fulfillments:s??[],setFulfillments:c,order:u??null,setOrder:f,refunds:a??[],setRefunds:m,openSection:r,setOpenSection:l,isEditing:n,setIsEditing:i},children:t})};function ne({setError:e}){const{setIsEditing:t}=le(),{order:r,fulfillment:l,notifyCustomer:n}=W(),[i,s]=(0,o.useState)(!1),{saveFulfillment:c}=(0,d.useDispatch)(S),u=(0,Q.useInstanceId)(ne,"save-draft-description");return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m.Button,{variant:"secondary",onClick:async()=>{if(e(null),!l||!r)return;if(0===I(l).length)return void e((0,a.__)("Select items to be fulfilled.","woocommerce"));s(!0),await c(r.id,l,n);const o=(0,d.select)(S).getError(r.id);o?e(o):(M(r.id),t(!1)),s(!1)},__next40pxDefaultSize:!0,isBusy:i,disabled:i,"aria-describedby":u,children:i?(0,a.__)("Saving…","woocommerce"):(0,a.__)("Save as draft","woocommerce")}),(0,z.jsx)("span",{id:u,className:"screen-reader-text",children:(0,a.__)("Saves the fulfillment without marking items as fulfilled","woocommerce")})]})}function ie({setError:e}){const{setIsEditing:t}=le(),{order:r,fulfillment:l,notifyCustomer:n}=W(),[i,s]=(0,o.useState)(!1),{saveFulfillment:c}=(0,d.useDispatch)(S),u=(0,Q.useInstanceId)(ie,"fulfill-items-description");return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m.Button,{variant:"primary",onClick:async()=>{if(e(null),!l||!r)return;if(0===I(l).length)return void e((0,a.__)("Select items to be fulfilled.","woocommerce"));s(!0),l.is_fulfilled=!0,l.status="fulfilled",await c(r.id,l,n);const o=(0,d.select)(S).getError(r.id);o?e(o):(M(r.id),t(!1)),s(!1)},__next40pxDefaultSize:!0,isBusy:i,disabled:i,"aria-describedby":u,children:i?(0,a.__)("Fulfilling…","woocommerce"):(0,a.__)("Fulfill items","woocommerce")}),(0,z.jsx)("span",{id:u,className:"screen-reader-text",children:(0,a.__)("Marks the selected items as fulfilled and updates their status","woocommerce")})]})}const se=window.wp.a11y,ce=window.wc.currency;var ae=r.n(ce);const me=window.wp.htmlEntities;function de({item:e,quantity:t,currency:r,editMode:l,toggleItem:n,isChecked:i,isIndeterminate:s}){const[c,d]=(0,o.useState)(!1),u=(0,o.useContext)(ce.CurrencyContext),f=u.getCurrencyConfig(),h=(e,t)=>{if(t||(t=f?.code||"USD"),f&&f.code===t)return u.formatAmount(e);const r=window.wcFulfillmentSettings.currency_symbols[t];return r?ae()({...f,symbol:(0,me.decodeEntities)(r),symbolPosition:f.symbolPosition,code:t}).formatAmount(e):`${t}${e}`};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)("div",{className:["woocommerce-fulfillment-item-container",c?"woocommerce-fulfillment-item-expanded":""].join(" "),children:[l&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-checkbox",children:(0,z.jsx)(m.CheckboxControl,{value:e.id,checked:i(e.id,-1),onChange:t=>{n(e.id,-1,t)},indeterminate:s(e.id),__nextHasNoMarginBottom:!0,"aria-label":e.name})}),l&&t>1&&(0,z.jsx)(m.Button,{onClick:()=>{d(!c)},"aria-label":c?(0,a.__)("Collapse item details","woocommerce"):(0,a.__)("Expand item details","woocommerce"),"aria-expanded":c,className:"woocommerce-fulfillment-item-expand-button",children:(0,z.jsx)(m.Icon,{icon:c?"arrow-up-alt2":"arrow-down-alt2","aria-hidden":"true",size:16})}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-title",children:[(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-image-container",children:e.image?.src&&(0,z.jsx)("img",{src:e.image?.src,alt:e.name,width:32,height:32,className:"woocommerce-fulfillment-item-image"})}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-name-sku",children:[(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-name",children:e.name}),e.sku&&(0,z.jsx)("span",{className:"woocommerce-fulfillment-item-sku",children:e.sku})]})]}),t>1&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-quantity",children:"x"+t}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-price",children:h(parseFloat(e.total)*(t/e.quantity),r)})]}),l&&c&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-expansion",children:(0,Y.range)(t).map((t=>(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-expansion-row",children:[l&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-checkbox",children:(0,z.jsx)(m.CheckboxControl,{name:`fulfillment-item-${e.id}-${t}`,value:e.id+"-"+t,checked:i(e.id,t),onChange:r=>{n(e.id,t,r)},"aria-label":`${e.name} - item ${t+1}`,__nextHasNoMarginBottom:!0})}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-title",children:[(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-image-container",children:(0,z.jsx)("img",{src:e.image.src,alt:"",width:32,height:32,className:"woocommerce-fulfillment-item-image"})}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-name-sku",children:[(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-name",children:e.name}),e.sku&&(0,z.jsx)("span",{className:"woocommerce-fulfillment-item-sku",children:e.sku})]})]}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-price",children:h(parseInt(e.total,10)/e.quantity,r)})]},"fulfillment-item-expansion-"+t)))})]})}function ue({editMode:e}){const{order:t,selectedItems:r,setSelectedItems:l}=W(),o=r.reduce(((e,t)=>e+t.selection.length),0),n=r.reduce(((e,t)=>e+t.selection.filter((e=>e.checked)).length),0),i=(e,t,o)=>{if(t<0)return void l([...r.map((t=>t.item_id===e?{...t,selection:t.selection.map((e=>({...e,checked:o})))}:t))]);l([...r.map((r=>(r.item_id===e&&r.selection.map((e=>(e.index===t&&(e.checked=o),e))),r)))]);const n=r.find((t=>t.item_id===e));n&&(0,se.speak)((0,a.sprintf)((0,a.__)("%1$s %2$s.","woocommerce"),n.item.name,o?(0,a.__)("selected","woocommerce"):(0,a.__)("deselected","woocommerce")),"polite")},s=(e,t)=>{if(t<0)return r.some((t=>t.item_id===e&&t.selection.every((e=>e.checked))));const l=r.find((t=>t.item_id===e));if(!l)return!1;const o=l.selection.find((e=>e.index===t));return!!o&&o.checked},c=e=>{const t=r.find((t=>t.item_id===e));if(!t)return!1;const l=t.selection.filter((e=>e.checked)).length;return l>0&&l<t.selection.length};return(0,z.jsxs)("ul",{className:"woocommerce-fulfillment-item-list","aria-label":(0,a.__)("Select items for fulfillment","woocommerce"),children:[(0,z.jsx)("li",{children:(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-bulk-select",children:[e&&(0,z.jsx)(m.CheckboxControl,{onChange:()=>{n===o?(l(r.map((e=>({...e,selection:e.selection.map((e=>({...e,checked:!1})))})))),(0,se.speak)((0,a.__)("All items deselected.","woocommerce"),"polite")):(l(r.map((e=>({...e,selection:e.selection.map((e=>({...e,checked:!0})))})))),(0,se.speak)((0,a.sprintf)((0,a._n)("%d item selected.","%d items selected.",o,"woocommerce"),o),"polite"))},checked:n===o,indeterminate:n>0&&n<o,"aria-label":n===o?(0,a.__)("Deselect all items","woocommerce"):(0,a.__)("Select all items","woocommerce"),__nextHasNoMarginBottom:!0}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-bulk-select__label",children:(0,a.sprintf)((0,a._n)("%s selected","%s selected",n,"woocommerce"),n)})]})}),r.map((r=>(0,z.jsx)("li",{children:(0,z.jsx)(de,{item:r.item,quantity:r.selection.length,editMode:e,currency:t?.currency??"",toggleItem:i,isChecked:s,isIndeterminate:c})},r.item_id)))]})}function fe({error:e}){const t=(0,o.useRef)(null);return(0,o.useLayoutEffect)((()=>{e&&t.current?.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})}),[e]),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-error-label",ref:t,children:[(0,z.jsx)("span",{className:"woocommerce-fulfillment-error-label__icon","aria-hidden":"true",children:(0,z.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[(0,z.jsx)("path",{d:"M7.99996 13.3333C10.9455 13.3333 13.3333 10.9455 13.3333 7.99996C13.3333 5.05444 10.9455 2.66663 7.99996 2.66663C5.05444 2.66663 2.66663 5.05444 2.66663 7.99996C2.66663 10.9455 5.05444 13.3333 7.99996 13.3333Z",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M8.66671 4.66663H7.33337V8.66663H8.66671V4.66663Z"}),(0,z.jsx)("path",{d:"M8.66671 10H7.33337V11.3333H8.66671V10Z"})]})}),(0,z.jsx)("span",{className:"woocommerce-fulfillment-error-label__text",children:e})]})}const he=()=>(0,z.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{d:"M6.75 0.75C4.275 0.75 2.25 2.775 2.25 5.25C2.25 6.3 2.625 7.275 3.225 8.025L0.375 10.875L1.2 11.7L4.05 8.85C4.8 9.45 5.775 9.825 6.825 9.825C9.3 9.825 11.325 7.8 11.325 5.325C11.325 2.85 9.225 0.75 6.75 0.75ZM6.75 8.625C4.875 8.625 3.375 7.125 3.375 5.25C3.375 3.375 4.875 1.875 6.75 1.875C8.625 1.875 10.125 3.375 10.125 5.25C10.125 7.125 8.625 8.625 6.75 8.625Z",fill:"#1E1E1E"})}),pe=()=>(0,z.jsx)("svg",{width:"18",height:"14",viewBox:"0 0 18 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0.5 1.75C0.5 0.783502 1.2835 0 2.25 0L12.5 0V3H14.5607L18 6.43934V8.75C18 9.7165 17.2165 10.5 16.25 10.5H16.2377C16.2458 10.5822 16.25 10.6656 16.25 10.75C16.25 12.1307 15.1307 13.25 13.75 13.25C12.3693 13.25 11.25 12.1307 11.25 10.75C11.25 10.6656 11.2542 10.5822 11.2623 10.5H7.23766C7.24582 10.5822 7.25 10.6656 7.25 10.75C7.25 12.1307 6.13071 13.25 4.75 13.25C3.36929 13.25 2.25 12.1307 2.25 10.75C2.25 10.6656 2.25418 10.5822 2.26234 10.5H0.5V1.75ZM11 9V1.5H2.25C2.11193 1.5 2 1.61193 2 1.75V9H2.96464C3.41837 8.53716 4.05065 8.25 4.75 8.25C5.44935 8.25 6.08163 8.53716 6.53536 9H11ZM15.5354 9H16.25C16.3881 9 16.5 8.88807 16.5 8.75V7.06066L13.9393 4.5H12.5V8.58446C12.8677 8.37174 13.2946 8.25 13.75 8.25C14.4493 8.25 15.0816 8.53716 15.5354 9ZM3.7815 10.5C3.76094 10.5799 3.75 10.6637 3.75 10.75C3.75 11.3023 4.19772 11.75 4.75 11.75C5.30228 11.75 5.75 11.3023 5.75 10.75C5.75 10.6637 5.73906 10.5799 5.7185 10.5C5.60749 10.0687 5.21596 9.75 4.75 9.75C4.28404 9.75 3.89251 10.0687 3.7815 10.5ZM12.7815 10.5C12.7609 10.5799 12.75 10.6637 12.75 10.75C12.75 11.3023 13.1977 11.75 13.75 11.75C14.3023 11.75 14.75 11.3023 14.75 10.75C14.75 10.6637 14.7391 10.5799 14.7185 10.5C14.7144 10.4841 14.7099 10.4683 14.705 10.4526C14.5784 10.0456 14.1987 9.75 13.75 9.75C13.284 9.75 12.8925 10.0687 12.7815 10.5Z",fill:"#1E1E1E"})}),_e=()=>(0,z.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{d:"M14 1.5H2C1.86739 1.5 1.74021 1.55268 1.64645 1.64645C1.55268 1.74021 1.5 1.86739 1.5 2V14C1.5 14.1326 1.55268 14.2598 1.64645 14.3536C1.74021 14.4473 1.86739 14.5 2 14.5H14C14.1326 14.5 14.2598 14.4473 14.3536 14.3536C14.4473 14.2598 14.5 14.1326 14.5 14V2C14.5 1.86739 14.4473 1.74021 14.3536 1.64645C14.2598 1.55268 14.1326 1.5 14 1.5ZM2 0H14C14.5304 0 15.0391 0.210714 15.4142 0.585786C15.7893 0.960859 16 1.46957 16 2V14C16 14.5304 15.7893 15.0391 15.4142 15.4142C15.0391 15.7893 14.5304 16 14 16H2C1.46957 16 0.960859 15.7893 0.585786 15.4142C0.210714 15.0391 0 14.5304 0 14V2C0 1.46957 0.210714 0.960859 0.585786 0.585786C0.960859 0.210714 1.46957 0 2 0ZM3 5H4.5V6.5H3V5ZM4.5 9.5H3V11H4.5V9.5ZM6 5H13V6.5H6V5ZM13 9.5H6V11H13V9.5Z",fill:"#1E1E1E"})}),we=()=>(0,z.jsx)("svg",{width:"18",height:"14",viewBox:"0 0 18 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0 2C0 0.89543 0.895431 0 2 0H16C17.1046 0 18 0.895431 18 2V12C18 13.1046 17.1046 14 16 14H2C0.89543 14 0 13.1046 0 12V2ZM2 1.5H16C16.2761 1.5 16.5 1.72386 16.5 2V2.93754L9.00005 8.5625L1.5 2.93746V2C1.5 1.72386 1.72386 1.5 2 1.5ZM1.5 4.81246V12C1.5 12.2761 1.72386 12.5 2 12.5H16C16.2761 12.5 16.5 12.2761 16.5 12V4.81254L9.00005 10.4375L1.5 4.81246Z",fill:"#1E1E1E"})}),xe=({copyText:e})=>{const[t,r]=(0,o.useState)(!1),l=(0,o.useRef)();return(0,o.useEffect)((()=>()=>{l.current&&clearTimeout(l.current)}),[]),(0,z.jsx)(m.Button,{size:"small",iconSize:14,onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e).then((()=>{r(!0),l.current&&clearTimeout(l.current),l.current=setTimeout((()=>r(!1)),2e3)}),(e=>{console.error("Failed to copy to clipboard:",e)}))},icon:t?(0,z.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{d:"M5.25 10.5L1.75 7L2.6275 6.1225L5.25 8.7375L11.3725 2.625L12.25 3.5L5.25 10.5Z",fill:"#008A20"})}):(0,z.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.68815 1.5835H9.81315C9.87065 1.5835 9.91732 1.63016 9.91732 1.68766V9.81266C9.91732 9.84029 9.90634 9.86679 9.88681 9.88632C9.86727 9.90586 9.84078 9.91683 9.81315 9.91683H1.68815C1.66052 9.91683 1.63403 9.90586 1.61449 9.88632C1.59496 9.86679 1.58398 9.84029 1.58398 9.81266V1.68766C1.58398 1.63016 1.63065 1.5835 1.68815 1.5835ZM0.333984 1.68766C0.333984 0.940163 0.940651 0.333496 1.68815 0.333496H9.81315C10.5615 0.333496 11.1673 0.940163 11.1673 1.68766V9.81266C11.1673 10.561 10.5615 11.1668 9.81315 11.1668H1.68815C1.329 11.1668 0.984566 11.0242 0.730611 10.7702C0.476655 10.5162 0.333984 10.1718 0.333984 9.81266V1.68766ZM12.4173 11.401V3.901H13.6673V11.401C13.6673 12.6668 12.6423 13.6668 11.3765 13.6668H2.20898V12.4168H11.3765C11.9515 12.4168 12.4173 11.9768 12.4173 11.401Z",fill:"#949494"})}),"aria-label":t?"Copied":"Copy",label:t?"Copied":"Copy",__next40pxDefaultSize:!0})},ge=()=>(0,z.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 12 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,z.jsx)("path",{d:"M11.8333 2.83301L9.33329 0.333008L2.24996 7.41634L1.41663 10.7497L4.74996 9.91634L11.8333 2.83301ZM5.99996 12.4163H0.166626V13.6663H5.99996V12.4163Z",fill:"#1E1E1E"})}),ve=({providerKey:e})=>{const t=u.find((t=>t.value===e));return t?(0,z.jsx)("div",{className:"woocommerce-fulfillment-shipment-provider-icon",children:t.icon?(0,z.jsx)("img",{src:t.icon,alt:t.label},e):(0,z.jsx)(pe,{})}):null};function je(){const[e,t]=(0,o.useState)(""),[r,l]=(0,o.useState)(!1),[n,i]=(0,o.useState)(null),[s,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(!1),f=(0,o.useRef)(null),{order:_}=W(),w=(0,Q.useInstanceId)(je,"tracking-number-error"),x=(0,Q.useInstanceId)(je,"finding-status"),g=(0,Q.useInstanceId)(je,"provider-ambiguity-notice"),{trackingNumber:v,setTrackingNumber:j,trackingUrl:b,setTrackingUrl:y,setProviderName:C,shipmentProvider:k,setShipmentProvider:N,setSelectedOption:E}=$();(0,o.useEffect)((()=>{i(null)}),[_?.id]);const S=async()=>{i(null);try{u(!0);const t=await h()({path:(0,p.addQueryArgs)(`/wc/v3/orders/${_?.id}/fulfillments/lookup`,{tracking_number:e.trim()}),method:"GET"});if(!t.tracking_number){const e=(0,a.__)("No information found for this tracking number. Check the number or enter the details manually.","woocommerce");return i(e),void(0,se.speak)(e,"assertive")}if(l(!1),t.possibilities&&Object.keys(t.possibilities).length>1){const e=Object.values(t.possibilities);(e.every((e=>e.ambiguity_score<85))||e.filter((e=>e.ambiguity_score>=85)).length>1)&&l(!0)}j(t.tracking_number),y(t.tracking_url),N(t.shipping_provider),C(""),c(!1);const r=(0,a.__)("Tracking information found successfully.","woocommerce");(0,se.speak)(r,"polite")}catch(e){console.error("Tracking number lookup failed:",e);const t=(0,a.__)("Failed to fetch shipment information.","woocommerce");i(t),(0,se.speak)(t,"assertive")}finally{u(!1)}};(0,o.useEffect)((()=>{(0,Y.isEmpty)(v)&&c(!0)}),[v]),(0,o.useEffect)((()=>{s&&f.current&&f.current.focus()}),[s]);const F=()=>{c(!0),t(v)};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("p",{className:"woocommerce-fulfillment-description",children:(0,a.__)("Provide the shipment tracking number to find the shipment provider and tracking URL.","woocommerce")}),s?(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-container",children:(0,z.jsxs)("div",{className:"woocommerce-fulfillment-input-group",children:[(0,z.jsx)(m.TextControl,{ref:f,type:"text",label:(0,a.__)("Tracking Number","woocommerce"),placeholder:(0,a.__)("Enter tracking number","woocommerce"),value:e,onChange:e=>{t(e),n&&i(null)},onKeyDown:t=>{"Enter"!==t.key||d||(0,Y.isEmpty)(e.trim())||S()},"aria-invalid":!!n,"aria-describedby":n?w:void 0,autoComplete:"off",__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),(0,z.jsx)(m.Button,{variant:"secondary",text:d?(0,a.__)("Finding…","woocommerce"):(0,a.__)("Find info","woocommerce"),disabled:d||(0,Y.isEmpty)(e.trim()),isBusy:d,onClick:S,"aria-describedby":d?x:void 0,__next40pxDefaultSize:!0}),d&&(0,z.jsx)("span",{id:x,className:"screen-reader-text",children:(0,a.__)("Searching for tracking information…","woocommerce")})]})}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)("div",{className:"woocommerce-fulfillment-input-container",children:[(0,z.jsx)("h4",{children:(0,a.__)("Tracking Number","woocommerce")}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-input-group space-between",children:[(0,z.jsx)("span",{onClick:F,role:"button",tabIndex:0,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||F()},style:{cursor:"pointer"},"aria-label":(0,a.__)("Edit tracking number","woocommerce"),children:v}),(0,z.jsx)(m.Button,{size:"small","aria-label":(0,a.__)("Edit tracking number","woocommerce"),onClick:F,children:(0,z.jsx)(ge,{})})]})]}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-input-container",children:[(0,z.jsx)("h4",{children:(0,a.__)("Provider","woocommerce")}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-group",children:(0,z.jsxs)("div",{children:[(0,z.jsx)(ve,{providerKey:k}),(0,z.jsx)("span",{children:L(k)})]})}),r&&(0,z.jsxs)(m.Flex,{direction:"column",gap:0,children:[(0,z.jsx)("p",{className:"woocommerce-fulfillment-description",id:g,children:(0,a.__)("Not your provider?","woocommerce")}),(0,z.jsx)(m.Button,{variant:"link",size:"small",className:"woocommerce-fulfillment-description-button",onClick:()=>{E(V),(0,se.speak)((0,a.__)("Switched to manual provider selection.","woocommerce"),"polite")},"aria-describedby":g,children:(0,a.__)("Select your provider manually","woocommerce")})]})]}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-input-container",children:[(0,z.jsx)("h4",{children:(0,a.__)("Tracking URL","woocommerce")}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-group",children:(0,z.jsx)(m.ExternalLink,{href:b,style:{width:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"},children:b})})]})]}),n&&(0,z.jsx)("div",{id:w,role:"alert",children:(0,z.jsx)(fe,{error:n})})]})}const be=({item:e})=>(0,z.jsxs)("div",{className:["woocommerce-fulfillment-shipping-provider-list-item","woocommerce-fulfillment-shipping-provider-list-item-"+e.value].join(" "),children:[(0,z.jsx)("div",{className:"woocommerce-fulfillment-shipping-provider-list-item-icon",children:e.icon?(0,z.jsx)("img",{src:e.icon,alt:e.label}):(0,z.jsx)(pe,{})}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-shipping-provider-list-item-label",children:e.label})]});function ye(){const{trackingNumber:e,setTrackingNumber:t,shipmentProvider:r,setShipmentProvider:l,providerName:o,setProviderName:n,trackingUrl:i,setTrackingUrl:s}=$();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("p",{className:"woocommerce-fulfillment-description",children:(0,a.__)("Provide the shipment information for this fulfillment.","woocommerce")}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-container",children:(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-group",children:(0,z.jsx)(m.TextControl,{label:(0,a.__)("Tracking Number","woocommerce"),type:"text",placeholder:(0,a.__)("Enter tracking number","woocommerce"),value:e,onChange:e=>{t(e),r&&"other"!==r&&s((window.wcFulfillmentSettings.providers[r]?.url??"").replace(/__placeholder__/i,encodeURIComponent(e)))},__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})})}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-container",children:(0,z.jsxs)("div",{className:"woocommerce-fulfillment-input-group",children:[(0,z.jsx)(m.ComboboxControl,{label:(0,a.__)("Provider","woocommerce"),__experimentalRenderItem:({item:e})=>(0,z.jsx)(be,{item:e}),allowReset:!1,__next40pxDefaultSize:!0,value:r,options:u,onChange:t=>{"string"==typeof t&&(t?(l(t),s((window.wcFulfillmentSettings.providers[t]?.url??"").replace(/__placeholder__/i,encodeURIComponent(e??"")))):s(""))},__nextHasNoMarginBottom:!0}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-shipment-provider-search-icon",children:(0,z.jsx)(he,{})})]})}),"other"===r&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-container",children:(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-group",children:(0,z.jsx)(m.TextControl,{label:(0,a.__)("Provider Name","woocommerce"),type:"text",placeholder:(0,a.__)("Enter provider name","woocommerce"),value:o,onChange:e=>{n(e)},__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})})}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-container",children:(0,z.jsx)("div",{className:"woocommerce-fulfillment-input-group",children:(0,z.jsx)(m.TextControl,{label:(0,a.__)("Tracking URL","woocommerce"),type:"text",placeholder:(0,a.__)("Enter tracking URL","woocommerce"),value:i,onChange:e=>{s(e)},__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})})})]})}function Ce({header:e,isCollapsable:t,initialState:r,size:l="medium",children:i}){const[s,c]=(0,o.useState)("expanded"===r),d=n().Children.toArray(i).length>0,u=()=>c(!s);return(0,z.jsxs)("div",{className:`woocommerce-fulfillment-card woocommerce-fulfillment-card__size-${l}`,children:[(0,z.jsxs)("div",{className:["woocommerce-fulfillment-card__header",t?"woocommerce-fulfillment-card__header--clickable":""].join(" "),...t?{onClick:u,onKeyUp:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),u())},role:"button",tabIndex:0}:{},children:[e,t&&(0,z.jsx)(m.Button,{__next40pxDefaultSize:!0,size:"small",onClick:()=>c(!s),"aria-label":s?(0,a.__)("Collapse section","woocommerce"):(0,a.__)("Expand section","woocommerce"),"aria-expanded":s,children:(0,z.jsx)(m.Icon,{icon:s?"arrow-up-alt2":"arrow-down-alt2",size:16})})]}),s&&d&&(0,z.jsx)("div",{className:["woocommerce-fulfillment-card__body",t?"":"no-collapse"].join(" "),children:i})]})}function ke(){const{selectedOption:e,setSelectedOption:t}=$(),r="radio-group-"+String(Math.floor(1e6*Math.random()));return(0,z.jsx)(Ce,{isCollapsable:!1,initialState:"expanded",header:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(pe,{}),(0,z.jsx)("h3",{children:(0,a.__)("Shipment Information","woocommerce")})]}),children:(0,z.jsxs)("div",{className:"woocommerce-fulfillment-shipment-information-options",children:[(0,z.jsxs)("div",{className:"woocommerce-fulfillment-shipment-information-option-tracking-number",children:[(0,z.jsx)(m.CheckboxControl,{type:"radio",name:r,value:P,checked:e===P,onChange:e=>e&&t(P),label:(0,a.__)("Tracking Number","woocommerce"),__nextHasNoMarginBottom:!0}),e===P&&(0,z.jsx)(je,{})]}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-shipment-information-option-manual-entry",children:[(0,z.jsx)(m.CheckboxControl,{type:"radio",name:r,value:V,checked:e===V,onChange:e=>e&&t(V),label:(0,a.__)("Enter manually","woocommerce"),__nextHasNoMarginBottom:!0}),e===V&&(0,z.jsx)(ye,{})]}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-shipment-information-option-no-info",children:(0,z.jsx)(m.CheckboxControl,{type:"radio",name:r,value:B,checked:e===B,onChange:e=>e&&t(B),label:(0,a.__)("No shipment information","woocommerce"),__nextHasNoMarginBottom:!0})})]})})}function Ne({type:e="fulfill"}){const{notifyCustomer:t,setNotifyCustomer:r}=W(),l=(0,o.useRef)(null),n=(0,o.useMemo)((()=>({fulfill:(0,a.__)("Fulfillment notification","woocommerce"),remove:(0,a.__)("Removal update","woocommerce"),update:(0,a.__)("Update notification","woocommerce")})),[]),i=(0,o.useMemo)((()=>({fulfill:(0,a.__)("Automatically send an email to the customer when the selected items are fulfilled.","woocommerce"),remove:(0,a.__)("Automatically send an email to the customer notifying that the fulfillment is cancelled.","woocommerce"),update:(0,a.__)("Automatically send an email to the customer when the fulfillment is updated.","woocommerce")})),[]),s="notification-description";return(0,o.useEffect)((()=>{l.current&&(l.current.ariaLabel=n[e]||n.fulfill,l.current.setAttribute("aria-describedby",s))}),[e,n]),(0,z.jsx)(Ce,{size:"small",isCollapsable:!1,initialState:"expanded",header:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(we,{}),(0,z.jsx)("h3",{children:n[e]||n.fulfill}),(0,z.jsx)(m.ToggleControl,{__nextHasNoMarginBottom:!0,checked:t,label:"",ref:l,onChange:e=>{r(e)}})]}),children:(0,z.jsx)("p",{id:s,className:"woocommerce-fulfillment-description",children:i[e]||i.fulfill})})}const Ee=()=>{const{order:e,fulfillments:t,refunds:r,openSection:l,setOpenSection:n,isEditing:i}=le(),[s,c]=(0,o.useState)(null);(0,o.useEffect)((()=>{c(null)}),[e?.id]);const d=(0,o.useMemo)((()=>te(t,e??{line_items:[]},r??[]).map((e=>({...e,selection:e.selection.map((e=>({...e,checked:!0})))})))),[t,e,r]);return e?0===d.length?null:(0,z.jsxs)("div",{className:["woocommerce-fulfillment-new-fulfillment-form",i?"woocommerce-fulfillment-new-fulfillment-form__disabled":"",0===t.length?"woocommerce-fulfillment-new-fulfillment-form__first":""].join(" "),children:[(0,z.jsxs)("div",{className:["woocommerce-fulfillment-new-fulfillment-form__header","order"===l?"is-open":""].join(" "),onClick:()=>{t.length>0&&n("order"===l?"":"order")},onKeyDown:e=>{t.length>0&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),n("order"===l?"":"order")))},tabIndex:t.length>0?0:-1,role:"button","aria-expanded":"order"===l,"aria-label":"order"===l?(0,a.__)("Collapse pending items","woocommerce"):(0,a.__)("Expand pending items","woocommerce"),children:[(0,z.jsx)("h3",{children:0===t.length?(0,a.__)("Order Items","woocommerce"):(0,a.__)("Pending Items","woocommerce")}),t.length>0&&(0,z.jsx)("div",{"aria-hidden":"true",children:(0,z.jsx)(m.Icon,{icon:"order"===l?"arrow-up-alt2":"arrow-down-alt2",size:16})})]}),!i&&"order"===l&&(0,z.jsxs)("div",{className:"woocommerce-fulfillment-new-fulfillment-form__content",children:[s&&(0,z.jsx)(fe,{error:s}),(0,z.jsx)(q,{children:(0,z.jsxs)(G,{order:e,fulfillment:null,items:d,children:[(0,z.jsx)(ue,{editMode:!0}),(0,z.jsx)(ke,{}),(0,z.jsx)(Ne,{type:"fulfill"}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-item-actions",children:[(0,z.jsx)(ne,{setError:c}),(0,z.jsx)(ie,{setError:c})]})]})})]})]}):null},Se=window.wc.remoteLogging;class Fe extends o.Component{constructor(e){super(e),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),(0,c.bumpStat)("error","unhandled-js-error-during-render");const r=t.componentStack?.trim().split("\n").slice(0,10).map((e=>e.trim()));(0,Se.captureException)(e,{severity:"critical",extra:{componentStack:r}})}handleRefresh=()=>{window.location.reload()};handleOpenSupport=()=>{window.open("https://wordpress.org/support/plugin/woocommerce/","_blank")};render(){return this.state.hasError?(0,z.jsxs)("div",{className:"woocommerce-global-error-boundary",children:[(0,z.jsx)("h1",{className:"woocommerce-global-error-boundary__heading",children:(0,a.__)("Oops, something went wrong","woocommerce")}),(0,z.jsx)("p",{className:"woocommerce-global-error-boundary__subheading",children:(0,a.__)("We’re sorry for the inconvenience. Please try reloading the page, or you can get support from the community forums.","woocommerce")}),(0,z.jsxs)("div",{className:"woocommerce-global-error-boundary__actions",children:[(0,z.jsx)(m.Button,{variant:"secondary",onClick:this.handleOpenSupport,children:(0,a.__)("Get Support","woocommerce")}),(0,z.jsx)(m.Button,{variant:"primary",onClick:this.handleRefresh,children:(0,a.__)("Reload Page","woocommerce")})]}),(0,z.jsxs)("details",{className:"woocommerce-global-error-boundary__details",children:[(0,z.jsx)("summary",{children:(0,a.__)("Click for error details","woocommerce")}),(0,z.jsxs)("div",{className:"woocommerce-global-error-boundary__details-content",children:[(0,z.jsx)("strong",{className:"woocommerce-global-error-boundary__error",children:this.state.error&&this.state.error.toString()}),(0,z.jsx)("p",{children:this.state.errorInfo&&this.state.errorInfo.componentStack})]})]})]}):this.props.children}}function Ie({onClick:e}){const t=(0,Q.useInstanceId)(Ie,"edit-fulfillment-description");return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m.Button,{variant:"secondary",onClick:e,__next40pxDefaultSize:!0,"aria-describedby":t,children:(0,a.__)("Edit fulfillment","woocommerce")}),(0,z.jsx)("span",{id:t,className:"screen-reader-text",children:(0,a.__)("Opens the fulfillment editor to modify fulfillment details","woocommerce")})]})}function Me({onClick:e}){const t=(0,Q.useInstanceId)(Me,"cancel-link-description");return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m.Button,{variant:"link",onClick:e,style:{flex:1},__next40pxDefaultSize:!0,"aria-describedby":t,children:(0,a.__)("Cancel","woocommerce")}),(0,z.jsx)("span",{id:t,className:"screen-reader-text",children:(0,a.__)("Cancels the current operation without saving changes","woocommerce")})]})}function Le({setError:e}){const{setIsEditing:t,setOpenSection:r}=le(),{order:l,fulfillment:n,notifyCustomer:i}=W(),[s,c]=(0,o.useState)(!1),{deleteFulfillment:u}=(0,d.useDispatch)(S),f=(0,Q.useInstanceId)(Le,"remove-button-description"),[h,p]=(0,o.useState)(!1),_=()=>p(!1),w=async()=>{if(e(null),!(n&&n.id&&l&&l.id))return;c(!0),await u(l.id,n.id,i);const o=(0,d.select)(S).getError(l.id);o?e(o):(M(l.id),r("order"),t(!1)),c(!1)};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m.Button,{variant:"secondary",onClick:e=>{e.stopPropagation(),e.preventDefault(),n&&!s&&(n.is_fulfilled?p(!0):w())},isBusy:s,__next40pxDefaultSize:!0,"aria-describedby":f,disabled:s,children:s?(0,a.__)("Removing…","woocommerce"):(0,a.__)("Remove","woocommerce")}),(0,z.jsx)("span",{id:f,className:"screen-reader-text",children:(0,a.__)("Deletes this fulfillment permanently","woocommerce")}),h&&(0,z.jsxs)(m.Modal,{title:(0,a.__)("Remove fulfillment","woocommerce"),onRequestClose:_,size:"medium",isDismissible:!1,className:"woocommerce-fulfillment-modal",children:[(0,z.jsx)("p",{className:"woocommerce-fulfillment-modal-text",children:(0,a.__)("Are you sure you want to remove this fulfillment?","woocommerce")}),(0,z.jsx)(Ne,{type:"remove"}),(0,z.jsxs)("div",{className:"woocommerce-fulfillment-modal-actions",children:[(0,z.jsx)(m.Button,{variant:"link",onClick:_,__next40pxDefaultSize:!0,"aria-label":(0,a.__)("Cancel removal and close dialog","woocommerce"),children:(0,a.__)("Cancel","woocommerce")}),(0,z.jsx)(m.Button,{variant:"primary",onClick:()=>{w(),_()},isBusy:s,__next40pxDefaultSize:!0,disabled:s,children:s?(0,a.__)("Removing…","woocommerce"):(0,a.__)("Remove fulfillment","woocommerce")})]})]})]})}function Oe({setError:e}){const{setIsEditing:t}=le(),{order:r,fulfillment:l,notifyCustomer:n}=W(),{updateFulfillment:i}=(0,d.useDispatch)(S),[s,c]=(0,o.useState)(!1),u=(0,Q.useInstanceId)(Oe,"update-button-description");return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m.Button,{variant:"primary",onClick:async()=>{if(!l||!r)return void e((0,a.__)("An unexpected error has occurred. Please refresh the page and try again.","woocommerce"));if(0===I(l).length)return void e((0,a.__)("Select items to be fulfilled.","woocommerce"));e(null),c(!0),await i(r.id,l,n);const o=(0,d.select)(S).getError(r.id);o?e(o):(M(r.id),t(!1)),c(!1)},disabled:s,isBusy:s,__next40pxDefaultSize:!0,"aria-describedby":u,children:s?(0,a.__)("Updating…","woocommerce"):(0,a.__)("Update","woocommerce")}),(0,z.jsx)("span",{id:u,className:"screen-reader-text",children:(0,a.__)("Applies changes to the existing fulfillment","woocommerce")})]})}function He({fulfillment:e}){const t=(window.wcFulfillmentSettings?.fulfillment_statuses||{})[e.status]||{label:e.status,is_fulfilled:!1,background_color:"",text_color:""};return(0,z.jsx)("div",{className:`woocommerce-fulfillment-status-badge woocommerce-fulfillment-status-badge__${e.status}`,style:{backgroundColor:t.background_color,color:t.text_color},role:"status","aria-label":`${(0,a.__)("Fulfillment status:","woocommerce")} ${t.label}`,children:t.label})}function Te({value:e,href:t}){return(0,Y.isEmpty)(String(e))?(0,z.jsx)(z.Fragment,{children:(0,a.__)("(empty)","woocommerce")}):t?(0,z.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:String(e)}):(0,z.jsx)(z.Fragment,{children:String(e)})}function Re({metaList:e}){return(0,z.jsx)("ul",{className:"woocommerce-fulfillment-meta-list",children:e.map(((e,t)=>(0,z.jsxs)("li",{className:"woocommerce-fulfillment-meta-list__item",children:[(0,z.jsx)("div",{className:"woocommerce-fulfillment-meta-list__item-label",children:e.label}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-meta-list__item-value",children:(0,z.jsx)(Te,{value:e.value,href:e.href})})]},t)))})}function De(){const{shipmentProvider:e,providerName:t,trackingNumber:r,trackingUrl:l,selectedOption:o}=$(),n=o!==B&&""!==r.trim(),i="other"!==e?u.find((t=>t.value===e)):null;return(0,z.jsx)(Ce,{isCollapsable:n,initialState:"collapsed",header:n?(0,z.jsxs)(z.Fragment,{children:[i?.icon?(0,z.jsx)("img",{src:i.icon,alt:i.label||""}):(0,z.jsx)(pe,{}),(0,z.jsxs)("h3",{children:[r," ",(0,z.jsx)(xe,{copyText:r})]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(pe,{}),(0,z.jsx)("h3",{children:(0,a.__)("No shipment information","woocommerce")})]}),children:n&&(0,z.jsx)(Re,{metaList:[{label:(0,a.__)("Tracking number","woocommerce"),value:r},{label:(0,a.__)("Provider name","woocommerce"),value:(s=e,c=t,"other"===s?c:L(s)||c||(0,a.__)("Unknown","woocommerce"))},{label:(0,a.__)("Tracking URL","woocommerce"),value:l,href:l||void 0}]})});var s,c}function Pe({fulfillment:e}){const t=e.meta_data.filter((e=>!1===e.key.startsWith("_")));return(0,z.jsxs)(Ce,{isCollapsable:!0,header:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(_e,{}),(0,z.jsx)("h3",{children:(0,a.__)("Fulfillment details","woocommerce")})]}),children:[0===t.length&&(0,z.jsx)("p",{children:(0,a.__)("No metadata available.","woocommerce")}),t.length>0&&(0,z.jsx)(Re,{metaList:t.map((e=>({label:e.key,value:e.value})))})]})}function Ve({message:e}){return(0,z.jsxs)("div",{className:"woocommerce-fulfillment-lock-label",children:[(0,z.jsx)("span",{className:"woocommerce-fulfillment-lock-label__icon",children:(0,z.jsx)("svg",{width:"10",height:"15",viewBox:"0 0 10 15",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:(0,z.jsx)("path",{d:"M9.16667 6.33341H8.16667V3.83341C8.16667 2.08341 6.75 0.666748 5 0.666748C3.25 0.666748 1.83333 2.08341 1.83333 3.83341V6.33341H0.833333C0.333333 6.33341 0 6.66675 0 7.16675V13.8334C0 14.3334 0.333333 14.6667 0.833333 14.6667H9.16667C9.66667 14.6667 10 14.3334 10 13.8334V7.16675C10 6.66675 9.66667 6.33341 9.16667 6.33341ZM3.16667 3.83341C3.16667 2.83341 4 2.00008 5 2.00008C6 2.00008 6.83333 2.83341 6.83333 3.83341V6.33341H3.16667V3.83341ZM8.75 13.4167H1.25V7.58341H8.75V13.4167Z"})})}),(0,z.jsx)("span",{className:"woocommerce-fulfillment-lock-label__text",children:e||(0,a.__)("This item is locked and cannot be edited.","woocommerce")})]})}function Be({index:e,expanded:t,onExpand:r,onCollapse:l,fulfillment:n,disabled:i=!1}){const{order:s,fulfillments:c,refunds:d}=le(),{isEditing:u,setIsEditing:f}=le(),[h,p]=(0,o.useState)(null),_=(0,o.useRef)(null),w=s?X(s,n):[],x=s?te(c,s,d):[],g=J([...w],[...x]),v=function(e){return{isLocked:F(e,"_is_locked",!1),reason:F(e,"_lock_message","")}}(n);(0,o.useEffect)((()=>{p(null)}),[s?.id]),(0,o.useEffect)((()=>{let e,r;if(u&&t&&_.current){const t=_.current;e=requestAnimationFrame((()=>{r=requestAnimationFrame((()=>{const e=t.querySelector('input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])');e&&e.focus()}))}))}return()=>{cancelAnimationFrame(e),cancelAnimationFrame(r)}}),[u,t]);const j=()=>{u||0===x.length&&1===c.length||(t?l():r())};return(0,z.jsxs)("div",{className:["woocommerce-fulfillment-stored-fulfillment-list-item",i?"woocommerce-fulfillment-stored-fulfillment-list-item__disabled":""].join(" "),children:[(0,z.jsxs)("div",{className:["woocommerce-fulfillment-stored-fulfillment-list-item-header",t?"is-open":""].join(" "),onClick:j,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),j())},role:"button",tabIndex:0,"aria-expanded":t,children:[(0,z.jsx)("h3",{children:(0,a.sprintf)(u?(0,a.__)("Editing fulfillment #%s","woocommerce"):(0,a.__)("Fulfillment #%s","woocommerce"),e+1)}),(0,z.jsx)(He,{fulfillment:n}),(x.length>0||c.length>1)&&(0,z.jsx)("div",{"aria-hidden":"true",children:(0,z.jsx)(m.Icon,{icon:t?"arrow-up-alt2":"arrow-down-alt2",size:16,color:u?"#dddddd":void 0})})]}),t&&(0,z.jsxs)("div",{className:"woocommerce-fulfillment-stored-fulfillment-list-item-content",ref:_,children:[h&&(0,z.jsx)(fe,{error:h}),(0,z.jsx)(q,{fulfillment:n,children:(0,z.jsxs)(G,{order:s,fulfillment:n,items:u?g:w,children:[(0,z.jsx)(ue,{editMode:u}),u&&(0,z.jsx)(ke,{}),!u&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(De,{}),(0,z.jsx)(Pe,{fulfillment:n})]}),(n.is_fulfilled&&u||!n.is_fulfilled&&!u)&&(0,z.jsx)(Ne,{type:"update"}),v.isLocked?(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-lock-container",children:(0,z.jsx)(Ve,{message:v.reason})}):(0,z.jsx)("div",{className:"woocommerce-fulfillment-item-actions",children:u?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(Me,{onClick:()=>{p(null),f(!1)}}),(0,z.jsx)(Le,{setError:e=>p(e)}),(0,z.jsx)(Oe,{setError:e=>p(e)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(Ie,{onClick:()=>{f(!0)}}),!n.is_fulfilled&&(0,z.jsx)(ie,{setError:p})]})})]})})]})]})}function Ue(){const{fulfillments:e,openSection:t,setOpenSection:r,isEditing:l}=le();return e.length>0&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-stored-fulfillments-list",children:e.map(((e,o)=>(0,z.jsx)(Be,{index:o,disabled:l&&t!=="fulfillment-"+e.id,expanded:t==="fulfillment-"+e.id,onExpand:()=>r("fulfillment-"+e.id),onCollapse:()=>r(""),fulfillment:e},e.id)))})}const ze=window.moment;var Ae=r.n(ze);function Ze({onClose:e}){const{order:t,setIsEditing:r,setOpenSection:l}=le();return t?t&&(0,z.jsxs)("div",{className:"woocommerce-fulfillment-drawer__header",tabIndex:-1,children:[(0,z.jsxs)("div",{className:"woocommerce-fulfillment-drawer__header__title",children:[(0,z.jsxs)("h2",{id:"fulfillment-drawer-header",children:["#",t.id," ",t.billing.first_name+" "+t.billing.last_name]}),(0,z.jsx)("button",{className:"woocommerce-fulfillment-drawer__header__close-button",onClick:()=>{r(!1),l("order"),e()},"aria-label":(0,a.__)("Close fulfillment drawer","woocommerce"),children:"×"})]}),(0,z.jsx)("p",{children:Ae()(t.date_created).format("MMMM D, YYYY, H:mma")})]}):null}function $e({children:e}){return(0,z.jsx)("div",{className:"woocommerce-fulfillment-drawer__body",children:e})}const qe=({isOpen:e,hasBackdrop:t=!1,onClose:r,orderId:l})=>{const n=(0,o.useRef)(null),i=(0,o.useRef)(null);return(0,o.useEffect)((()=>{let t,r;if(e){const e=n.current;e&&(i.current=e.ownerDocument.activeElement,t=requestAnimationFrame((()=>{r=requestAnimationFrame((()=>{e&&e.focus()}))})))}else i.current?.isConnected&&i.current.focus();return()=>{cancelAnimationFrame(t),cancelAnimationFrame(r)}}),[e]),(0,o.useEffect)((()=>{const t=t=>{if(e)if("Escape"!==t.key){if("Tab"===t.key){const e=n.current;if(!e)return;const r=e.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])');if(0===r.length)return;const l=r[0],o=r[r.length-1],i=e.ownerDocument.activeElement;t.shiftKey?i!==l&&i!==e||(t.preventDefault(),o?.focus()):i===o&&(t.preventDefault(),l?.focus())}}else r()};return e&&document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}}),[e,r]),(0,z.jsxs)(z.Fragment,{children:[t&&(0,z.jsx)("div",{className:"woocommerce-fulfillment-drawer__backdrop",onClick:r,role:"presentation",style:{display:e?"block":"none"},"aria-hidden":!e}),(0,z.jsx)("div",{className:"woocommerce-fulfillment-drawer",children:(0,z.jsx)("div",{ref:n,className:["woocommerce-fulfillment-drawer__panel",e?"is-open":"is-closed"].join(" "),role:"dialog","aria-modal":"true","aria-labelledby":"fulfillment-drawer-header","aria-hidden":!e,tabIndex:-1,children:(0,z.jsx)(Fe,{children:(0,z.jsxs)(oe,{orderId:l,children:[(0,z.jsx)(Ze,{onClose:r}),(0,z.jsxs)($e,{children:[(0,z.jsx)(Ee,{}),(0,z.jsx)(Ue,{})]})]})})})})]})};function Ke(){const[e,t]=(0,o.useState)(!1),[r,l]=(0,o.useState)(null),n=(0,s.getQuery)(),i=Object.prototype.hasOwnProperty.call(n,"id")||Object.prototype.hasOwnProperty.call(n,"post"),a=(0,o.useCallback)((()=>{document.querySelectorAll(".type-shop_order").forEach((e=>{e.classList.remove("is-selected")}))}),[]),m=(0,o.useCallback)((e=>{const t=e.closest("tr");a(),t?.classList.add("is-selected")}),[a]),d=(0,o.useCallback)((e=>{l(e),t(!0),(0,c.recordEvent)("fulfillment_modal_opened",{source:i?"order_detail_page":"orders_list",order_id:e})}),[l,t,i]);return(0,o.useLayoutEffect)((()=>{const e=e=>{const t=e.target;if(t.closest(".fulfillments-trigger")){const r=t.closest(".fulfillments-trigger"),l=parseInt(r.dataset.orderId||"",10);l&&(e.preventDefault(),e.stopPropagation(),m(r),d(l))}};return document.body.addEventListener("click",e),()=>{document.body.removeEventListener("click",e)}}),[m,d]),(0,z.jsx)(qe,{hasBackdrop:i,isOpen:e,orderId:r,onClose:()=>{a(),t(!1),setTimeout((()=>{l(null)}),300)}})}const We=Ke,Ge=document.querySelector("#wc_order_fulfillments_panel_container");(0,i.createRoot)(Ge).render((0,z.jsx)(Ke,{})),(window.wc=window.wc||{}).fulfillments=l})();
Save
Cancel