{"version":3,"file":"steps_controller-D0BSUIfI.js","sources":["../../../app/javascript/controllers/popup/steps_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport { get } from \"@rails/request.js\"\n\nexport default class extends Controller {\n static values = {\n activeStepId: String,\n }\n\n static targets = [\n \"mobileLayoutButton\",\n \"desktopLayoutButton\",\n \"bubbleButton\",\n \"buttonBackgroundColor\",\n \"buttonTextColor\",\n \"buttonAlignment\",\n \"overlayBackgroundColor\",\n ]\n static classes = [\"active\"]\n\n initialize() {\n this.stepsCount = this.element.querySelectorAll(\n '[data-controller=\"popup--step--name\"]'\n ).length\n this.activeLayout = \"mobile\"\n }\n\n displayMobileLayout() {\n if (this.bubbleVisible) {\n this.displayMobileBubble()\n }\n this.displayMobileLayoutForAllSteps()\n\n this.mobileLayoutButtonTarget.classList.add(\"text-tiger\")\n this.desktopLayoutButtonTarget.classList.remove(\"text-tiger\")\n\n this.activeLayout = \"mobile\"\n }\n\n displayDesktopLayout() {\n if (this.bubbleVisible) {\n this.displayDesktopBubble()\n }\n\n this.displayDesktopLayoutForAllSteps()\n\n this.desktopLayoutButtonTarget.classList.add(\"text-tiger\")\n this.mobileLayoutButtonTarget.classList.remove(\"text-tiger\")\n\n this.activeLayout = \"desktop\"\n }\n\n showStep({ currentTarget }) {\n this.bubbleVisible = false\n this.notifyStepToShow(currentTarget)\n }\n\n showBubble() {\n this.element.querySelectorAll(\"[data-step-id]\").forEach((stepButton) => {\n stepButton.classList.remove(this.activeClass)\n })\n\n this.bubbleButtonTarget.classList.add(this.activeClass)\n this.dispatch(\"show-step\", {\n target: document.documentElement,\n detail: \"mobile_bubble\",\n })\n\n if (this.activeLayout === \"mobile\") {\n this.displayMobileBubble()\n } else {\n this.displayDesktopBubble()\n }\n\n this.bubbleVisible = true\n }\n\n showBubbleStep() {\n this.bubbleButtonTarget.removeAttribute(\"hidden\")\n this.bubbleButtonTarget.click()\n }\n\n hideBubbleStep() {\n this.bubbleButtonTarget.setAttribute(\"hidden\", \"\")\n this.notifyStepToShow(\n this.element.querySelector(\"[data-step-id]:first-child\")\n )\n }\n\n setButtonStyles({ detail: { state } }) {\n this.buttonStyle = state\n this.buttonBackgroundColorTarget.value = state.backgroundColor\n this.buttonTextColorTarget.value = state.textColor\n this.buttonAlignmentTarget.value = state.alignment\n }\n\n async setNewStepAsActive({ currentTarget }) {\n this.bubbleVisible = false\n this.element.querySelectorAll(\"[data-step-id]\").forEach((stepButton) => {\n stepButton.classList.remove(this.activeClass)\n })\n\n await get(currentTarget.dataset.url, {\n responseKind: \"turbo-stream\",\n query: {\n step_count: ++this.stepsCount,\n mobile_layout: window.mobileLayout || \"\",\n desktop_layout: window.desktopLayout || \"\",\n active_layout: this.activeLayout,\n button_style: JSON.stringify(this.buttonStyle),\n overlay_background_color: document.querySelector(\n \"input[name='popup[overlay][background_color]']\"\n ).value,\n },\n })\n\n this.dispatch(\"hide-step\", {\n target: document.documentElement,\n })\n }\n\n remove({ currentTarget }) {\n document.getElementById(currentTarget.dataset.step).remove()\n document.getElementById(currentTarget.dataset.stepNameId).remove()\n\n --this.stepsCount\n this.notifyStepToShow(\n this.element.querySelector(\"[data-step-id]:first-child\")\n )\n }\n\n disableDesktopLayout() {\n this.mobileLayoutButtonTarget.disabled = false\n this.mobileLayoutButtonTarget.click()\n\n this.desktopLayoutButtonTarget.disabled = true\n }\n\n disableMobileLayout() {\n this.desktopLayoutButtonTarget.disabled = false\n this.desktopLayoutButtonTarget.click()\n\n this.mobileLayoutButtonTarget.disabled = true\n }\n\n enableBothMobileAndDesktopLayout() {\n this.mobileLayoutButtonTarget.disabled = false\n this.desktopLayoutButtonTarget.disabled = false\n }\n\n setOverlayBackgroundImage({ detail: color }) {\n this.overlayBackgroundColorTarget.value = color\n }\n\n // private\n\n notifyStepToShow(element) {\n this.hideMobileBubble()\n this.hideDesktopBubble()\n\n console.log(element.dataset)\n this.dispatch(\"show-step\", {\n target: document.documentElement,\n detail: element.dataset.stepId,\n })\n\n this.bubbleButtonTarget.classList.remove(this.activeClass)\n this.activeStepIdValue = element.dataset.stepId\n\n this.element.querySelectorAll(\"[data-step-id]\").forEach((stepButton) => {\n if (stepButton.dataset.stepId === this.activeStepIdValue) {\n stepButton.classList.add(this.activeClass)\n } else {\n stepButton.classList.remove(this.activeClass)\n }\n })\n }\n\n displayMobileLayoutForAllSteps() {\n this.dispatch(\"display:mobile-layout\", {\n target: document.documentElement,\n detail: this.activeStepIdValue,\n })\n }\n\n displayDesktopLayoutForAllSteps() {\n this.dispatch(\"display:desktop-layout\", {\n target: document.documentElement,\n detail: this.activeStepIdValue,\n })\n }\n\n displayMobileBubble() {\n this.hideDesktopBubble()\n\n document.querySelector(\"[data-bubble='mobile']\").classList.remove(\"hidden\")\n }\n\n hideMobileBubble() {\n document.querySelector(\"[data-bubble='mobile']\").classList.add(\"hidden\")\n }\n\n displayDesktopBubble() {\n this.hideMobileBubble()\n\n document.querySelector(\"[data-bubble='desktop']\").classList.remove(\"hidden\")\n }\n\n hideDesktopBubble() {\n document.querySelector(\"[data-bubble='desktop']\").classList.add(\"hidden\")\n }\n}\n"],"names":["steps_controller","Controller","currentTarget","stepButton","state","get","color","element","__publicField"],"mappings":"+PAGe,MAAKA,UAASC,CAAW,CAgBtC,YAAa,CACX,KAAK,WAAa,KAAK,QAAQ,iBAC7B,uCACN,EAAM,OACF,KAAK,aAAe,QACxB,CAEE,qBAAsB,CAChB,KAAK,eACP,KAAK,oBAAmB,EAE1B,KAAK,+BAA8B,EAEnC,KAAK,yBAAyB,UAAU,IAAI,YAAY,EACxD,KAAK,0BAA0B,UAAU,OAAO,YAAY,EAE5D,KAAK,aAAe,QACxB,CAEE,sBAAuB,CACjB,KAAK,eACP,KAAK,qBAAoB,EAG3B,KAAK,gCAA+B,EAEpC,KAAK,0BAA0B,UAAU,IAAI,YAAY,EACzD,KAAK,yBAAyB,UAAU,OAAO,YAAY,EAE3D,KAAK,aAAe,SACxB,CAEE,SAAS,CAAE,cAAAC,GAAiB,CAC1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