// @bun
var{defineProperty:O,getOwnPropertyNames:Q,getOwnPropertyDescriptor:U}=Object,V=Object.prototype.hasOwnProperty;function W(q){return this[q]}var $=(q)=>{var j=(P??=new WeakMap).get(q),B;if(j)return j;if(j=O({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var A of Q(q))if(!V.call(j,A))O(j,A,{get:W.bind(q,A),enumerable:!(B=U(q,A))||B.enumerable})}return P.set(q,j),j},P;var X=(q)=>q;function Y(q,j){this[q]=X.bind(null,j)}var F=(q,j)=>{for(var B in j)O(q,B,{get:j[B],enumerable:!0,configurable:!0,set:Y.bind(j,B)})};var I=(q,j)=>()=>(q&&(j=q(q=0)),j);var g=import.meta.require;function w(q){let j=[],B=/@interaction\s*\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)@endinteraction/g,A=B.exec(q);while(A!==null){let z=A[1],E=A[2].trim(),C=Z(E);j.push({name:z,storyId:"",variantId:"",steps:C}),A=B.exec(q)}return j}function Z(q){let j=[],B=q.split(`
`).map((A)=>A.trim()).filter(Boolean);for(let A of B){let z=A.match(/await\s+click\s*\(\s*['"]([^'"]+)['"]\s*\)/);if(z){j.push({action:"click",selector:z[1]});continue}let E=A.match(/await\s+type\s*\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/);if(E){j.push({action:"type",selector:E[1],value:E[2]});continue}let C=A.match(/await\s+select\s*\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/);if(C){j.push({action:"select",selector:C[1],value:C[2]});continue}let H=A.match(/await\s+hover\s*\(\s*['"]([^'"]+)['"]\s*\)/);if(H){j.push({action:"hover",selector:H[1]});continue}let J=A.match(/await\s+wait\s*\(\s*(\d+)\s*\)/);if(J){j.push({action:"wait",duration:Number.parseInt(J[1],10)});continue}let D=A.match(/expect\s*\(\s*['"]([^'"]+)['"]\s*\)\s*\.\s*(\w+)\s*\(\s*['"]?([^'")\s]+)['"]?\s*\)/);if(D){let N=D[1],K=D[2],L=D[3],G;switch(K){case"toHaveText":case"toContainText":G={type:"text",expected:L};break;case"toHaveValue":G={type:"value",expected:L};break;case"toBeVisible":G={type:"visible",expected:!0};break;case"toBeHidden":G={type:"hidden",expected:!0};break;case"toHaveClass":G={type:"class",expected:L};break;default:G={type:"text",expected:L}}j.push({action:"assert",selector:N,assertion:G})}}return j}async function R(q,j,B){let A=[];for(let z of B){let E=Date.now(),C=!0,H,J;try{if(z.setup)await z.setup();for(let D=0;D<z.steps.length;D++){let N=z.steps[D],K=await _(N);if(!K.success){C=!1,H=K.error,J=D;break}}if(z.teardown)await z.teardown()}catch(D){C=!1,H=String(D)}A.push({name:z.name,passed:C,error:H,duration:Date.now()-E,failedStep:J})}return A}async function _(q){switch(q.action){case"wait":return await new Promise((j)=>setTimeout(j,q.duration||100)),{success:!0};case"click":case"type":case"select":case"hover":case"focus":case"blur":return{success:!0};case"assert":return{success:!0};default:return{success:!1,error:`Unknown action: ${q.action}`}}}function T(){return`
    window.__stxInteraction = {
      async click(selector) {
        const el = document.querySelector(selector);
        if (!el) throw new Error('Element not found: ' + selector);
        el.click();
      },

      async type(selector, value) {
        const el = document.querySelector(selector);
        if (!el) throw new Error('Element not found: ' + selector);
        el.value = value;
        el.dispatchEvent(new Event('input', { bubbles: true }));
        el.dispatchEvent(new Event('change', { bubbles: true }));
      },

      async select(selector, value) {
        const el = document.querySelector(selector);
        if (!el) throw new Error('Element not found: ' + selector);
        el.value = value;
        el.dispatchEvent(new Event('change', { bubbles: true }));
      },

      async hover(selector) {
        const el = document.querySelector(selector);
        if (!el) throw new Error('Element not found: ' + selector);
        el.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
      },

      async wait(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
      },

      expect(selector) {
        const el = document.querySelector(selector);
        return {
          toHaveText(expected) {
            if (!el) throw new Error('Element not found: ' + selector);
            if (el.textContent !== expected) {
              throw new Error('Expected text "' + expected + '" but got "' + el.textContent + '"');
            }
          },
          toContainText(expected) {
            if (!el) throw new Error('Element not found: ' + selector);
            if (!el.textContent.includes(expected)) {
              throw new Error('Expected text to contain "' + expected + '"');
            }
          },
          toHaveValue(expected) {
            if (!el) throw new Error('Element not found: ' + selector);
            if (el.value !== expected) {
              throw new Error('Expected value "' + expected + '" but got "' + el.value + '"');
            }
          },
          toBeVisible() {
            if (!el) throw new Error('Element not found: ' + selector);
            const style = window.getComputedStyle(el);
            if (style.display === 'none' || style.visibility === 'hidden') {
              throw new Error('Expected element to be visible');
            }
          },
          toBeHidden() {
            if (el) {
              const style = window.getComputedStyle(el);
              if (style.display !== 'none' && style.visibility !== 'hidden') {
                throw new Error('Expected element to be hidden');
              }
            }
          },
          toHaveClass(className) {
            if (!el) throw new Error('Element not found: ' + selector);
            if (!el.classList.contains(className)) {
              throw new Error('Expected element to have class "' + className + '"');
            }
          }
        };
      }
    };
  `}function b(q){let j=[],B=q.filter((z)=>z.passed).length,A=q.filter((z)=>!z.passed).length;j.push(""),j.push("Interaction Tests"),j.push("\u2500".repeat(40));for(let z of q){let E=z.passed?"\u2713":"\u2717",C=z.passed?"PASS":"FAIL";if(j.push(`${E} ${z.name} [${C}] (${z.duration}ms)`),!z.passed&&z.error){if(j.push(`  Error: ${z.error}`),z.failedStep!==void 0)j.push(`  Failed at step: ${z.failedStep+1}`)}}return j.push(""),j.push(`Total: ${q.length} | Passed: ${B} | Failed: ${A}`),j.push(""),j.join(`
`)}export{R as runInteractionTests,w as parseInteractionBlocks,T as getInteractionHelpersScript,b as formatInteractionResults};
