"use strict";(globalThis.webpackChunkgoogle_listings_and_ads=globalThis.webpackChunkgoogle_listings_and_ads||[]).push([[456],{521:(e,t,a)=>{a.d(t,{A:()=>d});var s=a(7143),l=a(6520),i=a(7692),n=a(2775);const o="products",r={products:[],intervals:[],totals:{}};function d(e){const t=(0,n.A)();return(0,s.useSelect)(a=>{const{getReport:s}=a(l.Ui),n=s(o,e,t,"primary"),d=s(o,e,t,"secondary"),g=n.loaded&&d.loaded;let c=r;return g&&n.data&&d.data&&(c={products:n.data.products||r.products,intervals:n.data.intervals||r.intervals,totals:(0,i.bM)(n.data.totals,d.data.totals,n.reportQuery.fields)}),{data:c,loaded:g}},[e,t])}},8885:(e,t,a)=>{a.r(t),a.d(t,{default:()=>ae});var s=a(7723),l=a(8242),i=a(4848);const n=()=>(0,i.jsx)("p",{children:(0,s.__)("Create attribute rules to control what product data gets sent to Google and to manage product attributes in bulk.","google-listings-and-ads")});var o=a(8846),r=a(6427),d=a(6087),g=a(7892),c=a(2159),u=a(6494),p=a(9039),_=a(3905),h=a(1340);const m=({categories:e})=>(0,i.jsx)("div",{className:"gla-attribute-mapping__table-categories-help",children:(0,s.sprintf)(
// translators: %d: number of categories.
// translators: %d: number of categories.
(0,s._n)("%d category","%d categories",e.length,"google-listings-and-ads"),e.length)}),b=({categories:e,condition:t})=>{const a=e?.split(",")||[],{names:l}=(0,h.A)(a);if(t===_.aL.ALL)return(0,s.__)("All","google-listings-and-ads");const n=a.length>_.vL?(0,s.sprintf)(
// translators: %d: The number of categories.
// translators: %d: The number of categories.
(0,s.__)("+ %d more","google-listings-and-ads"),a.length-_.vL):"";return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{children:t===_.aL.ONLY?(0,s.__)("Only in","google-listings-and-ads"):(0,s.__)("All except","google-listings-and-ads")}),(0,i.jsx)(p.A,{text:(0,i.jsxs)("div",{className:"gla-attribute-mapping__table-categories-tooltip",children:[l,n&&(0,i.jsx)("span",{children:n})]}),children:(0,i.jsx)(m,{categories:a})})]})};var x=a(8468),j=a(8771),v=a(9457),y=a(7568),A=a(7437),C=a(771);const f=({sources:e=[],help:t,...a})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(y.A,{options:[{value:"",label:(0,s.__)("Select an option","google-listings-and-ads")},...e.map(e=>({...e,disabled:e.value.includes("disabled:")}))],...a}),t]});var L=a(8683),k=a(5092),N=a(1177),w=a(6257);const P="fixed",T="field",S=(0,s.__)("Set a fixed value","google-listings-and-ads"),F=(0,s.__)("Use value from existing product field","google-listings-and-ads"),R=({sources:e=[],onChange:t=x.noop,value:a})=>{const[l,n]=(0,d.useState)(!a||a?.includes(":")?T:P),o=e=>{t(""),n(e)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(j.A.Subtitle,{className:"gla_attribute_mapping_helper-text",children:(0,s.__)("Choose how to assign a value to the target attribute","google-listings-and-ads")}),(0,i.jsx)(L.A,{className:"gla-attribute-mapping__radio-control",label:(0,i.jsxs)(i.Fragment,{children:[F,(0,i.jsx)(w.A,{id:`${T}-helper-popover`,children:(0,i.jsx)("div",{children:(0,s.__)("Auto-populate the target attribute with the value of the field you link it to.","google-listings-and-ads")})})]}),onChange:o,value:T,selected:l,collapsible:!0,children:(0,i.jsx)(f,{value:a,onChange:t,"aria-label":F,sources:e,help:(0,i.jsx)(j.A.HelperText,{className:"gla-attribute-mapping__help-text",children:(0,d.createInterpolateElement)((0,s.__)("Can’t find an appropriate field? Create a new attribute","google-listings-and-ads"),{link:(0,i.jsx)(N.A,{context:"attribute-mapping",linkId:"create-new-attribute",href:"/wp-admin/edit.php?post_type=product&page=product_attributes"})})})})}),(0,i.jsx)(L.A,{className:"gla-attribute-mapping__radio-control",label:(0,i.jsxs)(i.Fragment,{children:[S,(0,i.jsx)(w.A,{id:`${P}-helper-popover`,children:(0,i.jsx)("div",{children:(0,d.createInterpolateElement)((0,s.__)("Use fixed values to populate the target attribute with a value you specify. For example, you can enter a fixed value of 'White' to specify a single color for all your products.","google-listings-and-ads"),{em:(0,i.jsx)("em",{})})})})]}),onChange:o,value:P,selected:l,collapsible:!0,children:(0,i.jsx)(k.A,{value:a,maxLength:100,onChange:t,"aria-label":S,placeholder:(0,s.__)("Enter a value","google-listings-and-ads")})})]})};var q=a(4301);const E=({selectedConditionalType:e=_.aL.ALL,selectedCategories:t,onConditionalTypeChange:a=x.noop,onCategoriesChange:l=x.noop})=>{const{categories:n,selected:o}=(0,h.A)(t);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(y.A,{options:[{value:_.aL.ALL,label:(0,s.__)("Apply to all categories","google-listings-and-ads")},{value:_.aL.EXCEPT,label:(0,s.__)("Apply to all categories EXCEPT","google-listings-and-ads")},{value:_.aL.ONLY,label:(0,s.__)("Apply ONLY to these categories","google-listings-and-ads")}],value:e,onChange:a}),(e===_.aL.ONLY||e===_.aL.EXCEPT)&&(0,i.jsx)(q.A,{options:n,isSearchable:!0,placeholder:(0,s.__)("Type for search","google-listings-and-ads"),selected:o,onChange:e=>l(e.map(e=>e.value)),multiple:!0,inlineTags:!0})]})};var M=a(3741),D=a(2434),G=a(6473);const I=(0,s.__)("Select default value","google-listings-and-ads"),O=(0,s.__)("Select a Google attribute that you want to manage","google-listings-and-ads"),Y=(e=[])=>[...e.map(e=>({value:e.id,label:e.label}))],X=({rule:e,onRequestClose:t=x.noop})=>{const[a,l]=(0,d.useState)(e?{...e}:{category_condition_type:_.aL.ALL}),[n,o]=(0,d.useState)(!1),{updateMappingRule:r,createMappingRule:c}=(0,D.j)(),{data:u}=(0,A.A)(),{data:p=[],hasFinishedResolution:h}=(0,C.A)(a.attribute),m=u.find(({id:e})=>e===a.attribute)?.enum||!1,b=Y(p),L=[{value:"",label:(0,s.__)("Select an attribute","google-listings-and-ads")},...Y(u)],k=a.source&&a.attribute&&(a.category_condition_type===_.aL.ALL||a.categories?.length>0)&&!(0,x.isEqual)(a,e),N=e=>{l((e=>({...e,categories:e.category_condition_type===_.aL.ALL?"":e.categories}))(e))},w=e=>{N({...a,source:e})},P=()=>{n||t("dismiss")};return(0,i.jsxs)(v.A,{overflow:"auto",onRequestClose:P,className:"gla-attribute-mapping__rule-modal",title:e?(0,s.__)("Manage attribute rule","google-listings-and-ads"):(0,s.__)("Create attribute rule","google-listings-and-ads"),buttons:[(0,i.jsx)(g.A,{disabled:n,isLink:!0,onClick:P,children:(0,s.__)("Cancel","google-listings-and-ads")},"cancel"),(0,i.jsx)(g.A,{disabled:!k||n,isPrimary:!0,text:n?(0,s.__)("Saving…","google-listings-and-ads"):(0,s.__)("Save rule","google-listings-and-ads"),eventName:"gla_attribute_mapping_save_rule_click",eventProps:{context:e?"attribute-mapping-manage-rule-modal":"attribute-mapping-create-rule-modal"},onClick:async()=>{o(!0);try{e?(await r(a),(0,G.ce)("gla_attribute_mapping_update_rule",{context:"attribute-mapping-manage-rule-modal"})):(await c(a),(0,G.ce)("gla_attribute_mapping_create_rule",{context:"attribute-mapping-create-rule-modal"})),t("confirm")}catch(e){o(!1)}}},"save-rule")],children:[(0,i.jsxs)(j.A,{children:[(0,i.jsx)(j.A.Title,{children:(0,s.__)("Target attribute","google-listings-and-ads")}),(0,i.jsx)(j.A.Subtitle,{className:"gla_attribute_mapping_helper-text",children:O}),(0,i.jsx)(y.A,{value:a.attribute,"aria-label":O,onChange:e=>{N({...a,attribute:e,source:""})},options:L})]}),!h&&(0,i.jsx)(M.A,{}),b.length>0&&h&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(j.A,{children:[(0,i.jsx)(j.A.Title,{children:m?I:(0,s.__)("Assign value","google-listings-and-ads")}),m?(0,i.jsx)(f,{sources:b,onChange:w,value:a.source,"aria-label":I}):(0,i.jsx)(R,{sources:b,onChange:w,value:a.source})]}),(0,i.jsxs)(j.A,{children:[(0,i.jsx)(j.A.Title,{children:(0,s.__)("Categories","google-listings-and-ads")}),(0,i.jsx)(E,{selectedConditionalType:a.category_condition_type,selectedCategories:a.categories?.length?a.categories.split(","):[],onConditionalTypeChange:e=>{N({...a,category_condition_type:e})},onCategoriesChange:e=>{N({...a,categories:e.join(",")})}})]})]})]})},U=({onRequestClose:e=x.noop,rule:t})=>{const[a,l]=(0,d.useState)(!1),{deleteMappingRule:n}=(0,D.j)(),o=()=>{a||e("dismiss")};return(0,i.jsx)(v.A,{onRequestClose:o,title:(0,s.__)("Delete attribute rule?","google-listings-and-ads"),buttons:[(0,i.jsx)(g.A,{disabled:a,isLink:!0,onClick:o,children:(0,s.__)("Cancel","google-listings-and-ads")},"cancel"),(0,i.jsx)(g.A,{disabled:a,isPrimary:!0,text:a?(0,s.__)("Deleting…","google-listings-and-ads"):(0,s.__)("Delete attribute rule","google-listings-and-ads"),eventName:"gla_attribute_mapping_delete_rule_click",eventProps:{context:"attribute-mapping-delete-rule-modal"},onClick:async()=>{l(!0);try{await n(t),(0,G.ce)("gla_attribute_mapping_delete_rule",{context:"attribute-mapping-delete-rule-modal"}),e("confirm")}catch(e){l(!1)}}},"delete-rule")],children:(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{children:(0,s.__)("Deleting a rule does’t affect any data that has already been submitted to Google.","google-listings-and-ads")}),(0,i.jsx)("p",{children:(0,s.__)("Product data is re-submitted to Google every 30 days to ensure that the information in your product listings are up-to-date.","google-listings-and-ads")}),(0,i.jsx)("p",{children:(0,s.__)("To ensure your products continue to be approved and promoted by Google, make sure that your product fields include all the required information.","google-listings-and-ads")})]})})};var $=a(8443),V=a(33),W=a(6520),z=a(3376);const B=()=>{const{data:e,start:t}=(0,V.A)({path:`${W.RV}/mc/mapping/sync`});if((0,d.useEffect)(()=>{t()},[t]),!e)return null;const a=(0,s.__)("Scheduled for sync","google-listings-and-ads"),l=e.last_sync?(0,$.format)(z.Z,new Date(1e3*e.last_sync)):(0,s.__)("Never","google-listings-and-ads");return(0,i.jsxs)(r.Flex,{justify:"end",align:"center",children:[(0,i.jsx)("strong",{children:(0,s.__)("Last sync:","google-listings-and-ads")}),(0,i.jsx)("span",{className:"gla-attribute-mapping__sync-status",children:e.is_scheduled?a:l}),(0,i.jsx)(w.A,{id:"gla-attribute-mapping-last-sync-helper-popover",position:"bottom left",children:(0,i.jsx)("div",{children:(0,s.__)("When an attribute rule is added or changed, data will be synced to Google Merchant Center via an async job. Note that it may take a while for the update to show up on Merchant Center, especially if it involves products that have not been synced and approved before.","google-listings-and-ads")})})]})};var H=a(993),Q=a(1396);const Z=[{key:"attribute",label:(0,s.__)("Target Attribute","google-listings-and-ads"),isLeftAligned:!0,required:!0},{key:"source",label:(0,s.__)("Data Source / Default Value","google-listings-and-ads"),isLeftAligned:!0,required:!0},{key:"categories",label:(0,s.__)("Categories","google-listings-and-ads"),isLeftAligned:!0,required:!0},{key:"controls",label:"",required:!0}],J=()=>{const{page:e,setPage:t}=(0,Q.A)("attribute-mapping"),{data:{rules:a,total:n},hasFinishedResolution:p}=(0,H.A)({page:e,perPage:10}),{data:_,hasFinishedResolution:h}=(0,A.A)(),m=!h||!p;return(0,d.useEffect)(()=>{p&&0===a?.length&&e>1&&t(e-1)},[e,a,p,t]),(0,i.jsx)(c.A,{children:(0,i.jsxs)(l.A.Card,{children:[(0,i.jsx)(r.CardBody,{size:null,children:m?(0,i.jsx)(o.TablePlaceholder,{headers:Z,caption:(0,s.__)("Loading Attribute Mapping rules","google-listings-and-ads")}):(0,i.jsx)(o.Table,{emptyMessage:(0,s.__)("You have no attribute rules","google-listings-and-ads"),caption:(0,s.__)("Attribute Mapping configuration","google-listings-and-ads"),headers:Z,rows:a.map(e=>{return[{display:(t=e.attribute,_.find(e=>e.id===t)?.label||"")},{display:(0,i.jsx)("span",{className:"gla-attribute-mapping__table-label",children:e.source})},{display:(0,i.jsx)("span",{className:"gla-attribute-mapping__table-categories",children:(0,i.jsx)(b,{categories:e.categories,condition:e.category_condition_type})})},{display:(0,i.jsxs)(r.Flex,{justify:"end",children:[(0,i.jsx)(r.FlexItem,{children:(0,i.jsx)(u.A,{button:(0,i.jsx)(g.A,{isLink:!0,text:(0,s.__)("Edit","google-listings-and-ads"),eventName:"gla_modal_open",eventProps:{context:"attribute-mapping-manage-rule-modal"}}),modal:(0,i.jsx)(X,{rule:e,onRequestClose:e=>{(0,G.ce)("gla_modal_closed",{context:"attribute-mapping-manage-rule-modal",action:e})}})})}),(0,i.jsx)(r.FlexItem,{children:(0,i.jsx)(u.A,{button:(0,i.jsx)(g.A,{isLink:!0,text:(0,s.__)("Delete","google-listings-and-ads"),eventName:"gla_modal_open",eventProps:{context:"attribute-mapping-delete-rule-modal"}}),modal:(0,i.jsx)(U,{rule:e,onRequestClose:e=>{(0,G.ce)("gla_modal_closed",{context:"attribute-mapping-delete-rule-modal",action:e})}})})})]})}];var t})})}),(0,i.jsxs)(r.CardFooter,{align:"between",className:"gla-attribute-mapping__table-footer",children:[(0,i.jsx)(u.A,{button:(0,i.jsx)(g.A,{isSecondary:!0,text:(0,s.__)("Create attribute rule","google-listings-and-ads"),eventName:"gla_modal_open",eventProps:{context:"attribute-mapping-create-rule-modal"}}),modal:(0,i.jsx)(X,{onRequestClose:e=>{(0,G.ce)("gla_modal_closed",{context:"attribute-mapping-create-rule-modal",action:e})}})}),(0,i.jsx)(o.Pagination,{className:"gla-attribute-mapping__pagination",page:e,perPage:10,total:n,showPagePicker:!1,showPerPagePicker:!1,onPageChange:(e,a)=>{t(e),(0,G.Xh)("attribute-mapping-rules",e,a)}}),(0,i.jsx)(B,{})]})]})})};var K=a(9927),ee=a(5246),te=a(2635);const ae=()=>(0,i.jsxs)("div",{className:"gla-attribute-mapping",children:[(0,i.jsx)(te.A,{}),(0,i.jsx)(K.A,{}),(0,i.jsx)(ee.A,{}),(0,i.jsx)(l.A,{title:(0,s.__)("Manage attributes","google-listings-and-ads"),description:(0,i.jsx)(n,{}),children:(0,i.jsx)(J,{})})]})}}]);