import{u as t,j as i}from"./fields-wnm5Jtc6.js";import{h as C,u as S,a as h}from"./vendor-D21mNUGX.js";import{a as g}from"./index.esm-DCQn2FO4.js";import{L as I,n as d}from"./Layout-CFk9FOHT.js";import{u as P,a as k,m as R,co as W,B as T,s as D,L as E,D as L,cF as V}from"./index-pmrLY__j.js";import{a as H}from"./woocommerce_icons-D18HYm26.js";import{C as q}from"./index-5Ilcd7WA.js";import{I as B}from"./Input-Cutb8bBf.js";import{C as u}from"./CardRow-Bf5pkBel.js";import{T as F}from"./Toggle-DrKXNyA3.js";import{C as M}from"./Checkbox-DzMD2qZF.js";import{S as U}from"./SelectMulti-CzFQ1GVp.js";import{I as A}from"./InputHidden-B-jHubUl.js";const ie=({})=>{const n=P(),{data:e}=k(r=>r.fetchWooCommerceProductData),v=C(),{id:o}=S(),m=o?"Edit WooCommerce product data":"Create new WooCommerce product data",[b,p]=h.useState(!1),{register:s,handleSubmit:_,setValue:l,formState:{errors:c},clearErrors:y}=g({mode:"all"}),x=()=>e?typeof e.icon>"u"?null:typeof e.icon=="object"?[e.icon.icon]:[e.icon]:null;h.useEffect(()=>{R(t(m)),o?n(W({id:o})).then(r=>{const a=r.payload;l("product_data_name",a.name),l("icon",a.icon),l("show_ui",a.showInUI),p(!0)}):p(!0)},[]);const w=r=>{n(V(r)).then(a=>{const f=a.payload;f.success?(v("/product-data/product"),d.success(t("Product data successfully saved"))):d.error(f.error)}).catch(a=>{d.error(a)})},j=[i.jsx(T,{type:"submit",style:D.PRIMARY,children:t("Save")})];return b?i.jsx("form",{onSubmit:_(w),children:i.jsx(I,{crumbs:[{label:t("Registered Custom Post Types"),link:"/"},{label:t("WooCommerce product data"),link:"/product-data/product"},{label:o?t("Edit WooCommerce product data"):t("Create new WooCommerce product data")}],title:m,actions:j,children:i.jsxs(q,{style:"with-shadow",children:[i.jsx(A,{register:s,id:"id",value:o||L()}),i.jsx(u,{label:t("Product data name"),value:i.jsx(B,{id:"product_data_name",placeholder:t("Product data name"),description:t("The product data name."),register:s,errors:c,isRequired:!0,validate:{maxLength:{value:20,message:t("max length is 20")},required:t("This field is mandatory")}})}),i.jsx(u,{label:t("Icon"),value:i.jsx(U,{id:"icon",register:s,setValue:l,defaultValue:x(),values:H,clearErrors:y,errors:c,maxItems:1})}),i.jsx(u,{label:t("visibility"),value:i.jsx(M,{register:s,errors:c,id:"visibility",values:{"Show in simple products":{value:"show_if_simple",checked:e&&e.visibility?e.visibility.includes("show_if_simple"):!0},"Show in variable products":{value:"show_if_variable",checked:e&&e.visibility?e.visibility.includes("show_if_variable"):!0},"Show in grouped products":{value:"show_if_grouped",checked:e&&e.visibility?e.visibility.includes("show_if_grouped"):!0},"Show in external products":{value:"show_if_external",checked:e&&e.visibility?e.visibility.includes("show_if_external"):!0},"Hide in virtual products":{value:"hide_if_virtual",checked:e&&e.visibility?e.visibility.includes("hide_if_virtual"):!1},"Hide in external products":{value:"hide_if_external",checked:e&&e.visibility?e.visibility.includes("hide_if_external"):!1}}})}),i.jsx(u,{label:t("Show in UI"),value:i.jsx(F,{register:s,errors:c,id:"show_ui",description:t("Show the product data on the front store page."),defaultValue:null})})]})})}):i.jsx(E,{})};export{ie as default};
