{"version":3,"file":"answer_controller-CQ3xtIj3.js","sources":["../../../app/javascript/controllers/automation/answer_controller.js"],"sourcesContent":["import LineController from \"../journeys/line_controller\"\n\nexport default class extends LineController {\n static targets = [\n 'child',\n 'bodyInput',\n 'description',\n 'queryInput',\n ]\n\n disconnect() {\n this.clear()\n super.disconnect()\n }\n\n onWindowSizeChange() {\n this.instance.repaintEverything()\n }\n\n update({ detail: newValue }) {\n if(!newValue.body) {\n newValue.body = t.automation.answers.answer.any\n }\n\n this.bodyInputTarget.value = newValue.body\n this.queryInputTarget.value = newValue.query\n\n if(newValue.body.toLowerCase() === t.automation.answers.answer.any.toLowerCase() || newValue.query === 'equals') {\n this.descriptionTarget.innerText = newValue.body\n } else {\n this.descriptionTarget.innerText = `${newValue.text} ${newValue.body}`\n }\n\n this.repaint()\n }\n\n repaint() {\n this.instance.repaintEverything()\n }\n\n clear() {\n this.instance.deleteConnection(this.rootToAnswer)\n this.instance.deleteConnection(this.answerToEndRoot)\n }\n\n childTargetConnected() {\n if(this.answerToEndRoot) {\n this.instance.deleteConnection(this.answerToEndRoot)\n }\n\n this.firstChildDrawnTo = this.childTargets[0]\n\n this.answerToEndRoot = this.draw(this.element.querySelector('[data-header]'), this.firstChildDrawnTo, {\n fromOptions: this.blankEndpoint(\"Bottom\"),\n toOptions: this.blankEndpoint(\"Top\"),\n lineOptions: this.lineOptions,\n })\n }\n\n childTargetDisconnected(child) {\n if(this.childTargets.length > 0) {\n return this.childTargetConnected()\n }\n\n this.instance.deleteConnection(this.answerToEndRoot)\n\n this.answerToEndRoot = this.draw(this.element.querySelector('[data-header]'), this.end, {\n fromOptions: this.blankEndpoint(\"Bottom\"),\n toOptions: this.blankEndpoint(),\n lineOptions: this.lineOptions,\n })\n }\n\n make({ detail }) {\n const { root, end, index } = detail\n\n if(this.rootToAnswer) {\n this.instance.deleteConnection(this.rootToAnswer)\n this.instance.deleteConnection(this.answerToEndRoot)\n }\n\n this.end = end\n this.lineOptions = {\n ...this.flowchartConnectorLineOptions,\n options: {\n ...this.flowchartConnectorLineOptions.options,\n cornerRadius: index === 0 ? 10 : 0,\n }\n }\n\n this.rootToAnswer = this.draw(root, this.element, {\n fromOptions: this.blankEndpoint(\"Bottom\"),\n toOptions: this.blankEndpoint(\"Top\"),\n lineOptions: this.lineOptions,\n })\n\n if(this.childTargets.length === 0) {\n this.answerToEndRoot = this.draw(this.element.querySelector('[data-header]'), end, {\n fromOptions: this.blankEndpoint(\"Bottom\"),\n toOptions: this.blankEndpoint(),\n lineOptions: this.lineOptions,\n })\n } else {\n this.childTargetConnected()\n }\n }\n\n remove() {\n this.element.remove()\n\n if (this.hasRemovedInputTarget) {\n this.removedInputTarget.disabled = false\n document.getElementById(\"drawing_container\").appendChild(this.removedInputTarget)\n }\n }\n}\n"],"names":["answer_controller","LineController","newValue","child","detail","root","end","index","__publicField"],"mappings":"sNAEe,MAAKA,UAASC,CAAe,CAQ1C,YAAa,CACX,KAAK,MAAK,EACV,MAAM,WAAU,CACpB,CAEE,oBAAqB,CACnB,KAAK,SAAS,kBAAiB,CACnC,CAEE,OAAO,CAAE,OAAQC,GAAY,CACvBA,EAAS,OACXA,EAAS,KAAO,EAAE,WAAW,QAAQ,OAAO,KAG9C,KAAK,gBAAgB,MAAQA,EAAS,KACtC,KAAK,iBAAiB,MAAQA,EAAS,MAEpCA,EAAS,KAAK,YAAW,IAAO,EAAE,WAAW,QAAQ,OAAO,IAAI,YAAW,GAAMA,EAAS,QAAU,SACrG,KAAK,kBAAkB,UAAYA,EAAS,KAE5C,KAAK,kBAAkB,UAAY,GAAGA,EAAS,IAAI,IAAIA,EAAS,IAAI,GAGtE,KAAK,QAAO,CAChB,CAEE,SAAU,CACR,KAAK,SAAS,kBAAiB,CACnC,CAEE,OAAQ,CACN,KAAK,SAAS,iBAAiB,KAAK,YAAY,EAChD,KAAK,SAAS,iBAAiB,KAAK,eAAe,CACvD,CAEE,sBAAuB,CAClB,KAAK,iBACN,KAAK,SAAS,iBAAiB,KAAK,e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