import{a as v,b as J}from"./chunk-OASPW2P2.js";import{a as C}from"./chunk-DE3WCNP6.js";import{a as p}from"./chunk-YBFCDINU.js";import{a as N}from"./chunk-STJ3LWFL.js";import{r as E}from"./chunk-5T3OVTF5.js";import{p as c,r as F,v as S}from"./chunk-PTIJDS6I.js";import{O as w}from"./chunk-2HZMOK4U.js";import{b as q,c as D}from"./chunk-Q6LCSRIW.js";import{A as T,S as O,v as I,x as u}from"./chunk-E24W34C4.js";import{Lb as a}from"./chunk-EYDNSYYE.js";import{r as M}from"./chunk-T6CC5WUU.js";import{e as A,g as h}from"./chunk-VKWPEFWQ.js";h();h();async function _(t,o,e){let{name:r,verbose:d,noColor:l,json:m,force:x}=e,g=O()||x;if(C({verbose:d,noColor:l}),g&&!o){let s="A theme ID is required to duplicate a theme, specify one with the --theme flag";m?a(JSON.stringify({message:s,errors:[]})):u({body:[s]});return}let i=o?await J(t,o):await v(t,{header:"Select a theme to duplicate",filter:{theme:o}});if(!i){let s=`No theme with ID ${o} could be found. Use shopify theme list to find a theme ID.`;m?a(JSON.stringify({message:s,errors:[]})):u({body:[s]});return}if(i?.role==="development"){let s="Development themes can't be duplicated. Use shopify theme push to upload it to the store first.";m?a(JSON.stringify({message:s,errors:[]})):u({body:[s]});return}if(!g&&!await T({message:`Do you want to duplicate '${i.name}' on ${t.storeFqdn}?`,confirmationMessage:`Yes, duplicate '${i.name}'`,cancellationMessage:"No, cancel duplicate"}))return;let b=await E(i.id,r,t);m?j(i,t,b):P(i,t,b)}function P(t,o,e){if(e.userErrors&&e.userErrors.length>0){let r=e.userErrors.map(d=>d.message).join(", ");u({body:["The theme",...p(t),"could not be duplicated due to errors: ",{subdued:r},{char:"."},...e.requestId?[`
Request ID: `,{subdued:e.requestId}]:[]]})}else e.theme?I({body:["The theme",...p(t),"has been duplicated",{char:"."}],nextSteps:[[{link:{label:"View the duplicated theme",url:N(e.theme,o)}}]]}):u({body:["The theme",...p(t),"unexpectedly could not be duplicated",{char:"."},...e.requestId?[`
Request ID: `,{subdued:e.requestId}]:[]]})}function j(t,o,e){if(e.userErrors&&e.userErrors.length>0)a(JSON.stringify({message:`The theme '${t.name}' could not be duplicated due to errors`,errors:e.userErrors.map(r=>r.message),requestId:e.requestId}));else if(e.theme){let{id:r,name:d,role:l}=e.theme,m={theme:{id:r,name:d,role:l,shop:o.storeFqdn}};a(JSON.stringify(m))}else a(JSON.stringify({message:`The theme '${t.name}' unexpectedly could not be duplicated `,errors:[],requestId:e.requestId}))}var f=A(M(),1);var y,n=class extends S{async run(){let{flags:o}=await this.parse(y),e=F(o),r=await w(e,o.password);await _(r,o.theme,o)}};y=n;n.summary="Duplicates a theme from your theme library.";n.usage=["theme duplicate","theme duplicate --theme 10 --name 'New Theme'"];n.descriptionWithMarkdown=`If you want to duplicate your local theme, you need to run \`shopify theme push\` first.

If no theme ID is specified, you're prompted to select the theme that you want to duplicate from the list of themes in your store. You're asked to confirm that you want to duplicate the specified theme.

Prompts and confirmations are not shown when duplicate is run in a CI environment or the \`--force\` flag is used, therefore you must specify a theme ID using the \`--theme\` flag.

You can optionally name the duplicated theme using the \`--name\` flag.

If you use the \`--json\` flag, then theme information is returned in JSON format, which can be used as a machine-readable input for scripts or continuous integration.

Sample JSON output:

\`\`\`json
{
  "theme": {
    "id": 108267175958,
    "name": "A Duplicated Theme",
    "role": "unpublished",
    "shop": "mystore.myshopify.com"
  }
}
\`\`\`

\`\`\`json
{
  "message": "The theme 'Summer Edition' could not be duplicated due to errors",
  "errors": ["Maximum number of themes reached"],
  "requestId": "12345-abcde-67890"
}
\`\`\``;n.description=y.descriptionWithoutMarkdown();n.flags={...q,...D,password:c.password,theme:f.Flags.string({char:"t",description:"Theme ID or name of the remote theme.",env:"SHOPIFY_FLAG_THEME_ID"}),name:f.Flags.string({char:"n",description:"Name of the newly duplicated theme.",env:"SHOPIFY_FLAG_NAME"}),store:c.store,environment:c.environment,force:f.Flags.boolean({char:"f",description:"Force the duplicate operation to run without prompts or confirmations.",env:"SHOPIFY_FLAG_FORCE"})};var ee=n;export{ee as a};
