var a=class{static generate(e,n="element"){let{selectors:t}=e;if(!t||typeof t!="object")return this.generateFallbackSelector(e,n);let r=[];return t.role&&r.push(this.generateRoleSelector(t.role)),t.attributes&&r.push(this.generateAttributeSelector(t.attributes)),t.partialMatch&&r.push(this.generatePartialMatchSelector(t.partialMatch)),t.structure&&r.push(this.generateStructuralSelector(t.structure)),r.length===0?this.generateFallbackSelector(e,n):r.length===1?`const ${n} = ${r[0]};`:`const ${n} = ${r[0]}
${r.slice(1).map(i=>`  .or(${i})`).join(`
`)};`}static generateRoleSelector(e){let{role:n,name:t}=e;if(!n)return null;if(t){let r=this.escapeRegex(t);return`page.getByRole('${n}', { name: /${r}/i })`}return`page.getByRole('${n}')`}static generateAttributeSelector(e){if(!e||typeof e!="object")return null;let n=Object.entries(e).filter(([r,c])=>c!=null).map(([r,c])=>r==="placeholder"||r==="aria-label"?r==="placeholder"?`page.getByPlaceholder('${this.escapeString(c)}')`:`page.locator('[${r}="${this.escapeString(c)}"]')`:`[${r}="${this.escapeString(c)}"]`);if(e.placeholder)return`page.getByPlaceholder('${this.escapeString(e.placeholder)}')`;let t=n.filter(r=>!r.startsWith("page.")).join("");return t?`page.locator('${t}')`:null}static generatePartialMatchSelector(e){if(!e||typeof e!="object")return null;let n=Object.entries(e).filter(([t,r])=>r!==void 0).map(([t,r])=>{let c=r.replace(/^\^/,"");return`[${t}^="${this.escapeString(c)}"]`});return n.length>0?`page.locator('${n.join("")}')`:null}static generateStructuralSelector(e){return!e||typeof e!="string"?null:`page.locator('${this.escapeString(e)}')`}static generateFallbackSelector(e,n){let{description:t,type:r}=e;if(r==="fill"||r==="type")return`const ${n} = page.locator('input').first();`;if(r==="click"){if(t.toLowerCase().includes("button"))return`const ${n} = page.locator('button').first();`;if(t.toLowerCase().includes("link"))return`const ${n} = page.locator('a').first();`}return`const ${n} = page.locator('body');`}static escapeString(e){return typeof e!="string"?String(e):e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"')}static escapeRegex(e){return typeof e!="string"?String(e):e.replace(/[.*+?^${}()[\]\\]/g,"\\$&")}static generateActionCode(e,n){let{type:t,value:r,description:c,selectors:i}=e,o=`element${n}`,s=this.generate(e,o),l=this.generateActionMethod(t,o,r);return`${s}
${l}`}static generateActionMethod(e,n,t){switch(e){case"fill":case"type":return`await ${n}.fill('${this.escapeString(t||"")}');`;case"click":return`await ${n}.click();`;case"navigate":return`await page.goto('${this.escapeString(t||"")}');`;case"wait":return`await page.waitForTimeout(${parseInt(t)||2e3});`;default:return`// Unknown action type: ${e}`}}static generateAssertionCode(e,n){let{description:t,expected:r,actual:c,passed:i}=e;return t.toLowerCase().includes("url")?`await expect(page).toHaveURL(/${this.escapeRegex(c)}/);`:t.toLowerCase().includes("visible")?"await expect(page.locator('body')).toBeVisible();":`// ${t}`}},g=a;export{a as SelectorGenerator,g as default};
