(this["webpackJsonpfactory_burgers-ui"]=this["webpackJsonpfactory_burgers-ui"]||[]).push([[0],{31:function(e,t,n){},32:function(e,t,n){},33:function(e,t,n){},34:function(e,t,n){},42:function(e,t,n){"use strict";n.r(t);var r=n(0),a=n.n(r),c=n(10),i=n.n(c),o=(n(31),n(32),n(33),n(34),n(1));var s=function(){return Object(o.jsx)("div",{children:"86 on that ... something went wrong."})};var u=function(){return Object(o.jsx)("div",{children:"Coming right up..."})},l=n(11),b=n.n(l),j=n(15),d=n(8),f=n(9),h=n(7),O=n.n(h),m=O.a.shape({name:O.a.string.isRequired}),p=O.a.shape({name:O.a.string.isRequired}),v=(O.a.shape({attributes:O.a.arrayOf(m),name:O.a.string.isRequired,traits:O.a.arrayOf(p)}),n(23)),x=n(6),g=n(26),y=n(13);var w=function(e){return Object(o.jsxs)(x.a.Row,{children:[Object(o.jsxs)(y.a,{children:[Object(o.jsx)(x.a.Label,{children:"Attribute Name"}),Object(o.jsxs)(x.a.Control,{as:"select",disabled:e.disabled,name:"attributes[][name]",className:"form-control",value:e.attribute.name,onChange:function(t){return e.onChangeName(t)},children:[Object(o.jsx)("option",{value:e.attribute.name,children:e.attribute.name}),e.children]})]}),Object(o.jsxs)(y.a,{children:[Object(o.jsx)(x.a.Label,{children:"Value"}),Object(o.jsx)("input",{disabled:e.disabled||!e.attribute.name,name:"attributes[][value]",className:"form-control",value:e.attribute.value,onChange:function(t){return e.onChangeValue(t)}})]})]})};var k=function(e){var t=e.attributes,n=Object(r.useState)([]),a=Object(d.a)(n,2),c=a[0],i=a[1],s=Object(r.useMemo)((function(){return function(e,t){var n=new Set(t.map((function(e){return e.name})));return e.filter((function(e){return!n.has(e.name)}))}(t,c)})).map((function(e){return Object(o.jsx)("option",{value:e.name,children:e.name},e.name)}));function u(e){var t=e.name,n=e.value;i([].concat(Object(g.a)(c),[{name:t,value:n}]))}function l(e,t){var n=c.slice();n.splice(e,1,t),i(n)}return Object(o.jsxs)(x.a.Group,{controlId:"factories.Traits",children:[Object(o.jsx)(x.a.Label,{children:"Pickles or onions?"}),c.map((function(t,n){return Object(o.jsx)(w,{attribute:t,disabled:e.disabled,onChangeName:function(e){return function(e,t){l(e,{name:t.target.value,value:c[e].value})}(n,e)},onChangeValue:function(e){return function(e,t){l(e,{name:c[e].name,value:t.target.value})}(n,e)},children:s},n)})),Object(o.jsx)(w,{attribute:{name:"",value:""},disabled:e.disabled,onChangeName:function(e){return u({name:e.target.value,value:""})},onChangeValue:function(e){return u({name:"",value:e.target.value})},children:s},c.length+1)]})};function C(e,t){return t?"".concat(e.association," (").concat(e.factory.name,", ").concat(e.factory.class_name,")"):"".concat(e.factory.name," (").concat(e.factory.class_name,")")}var S=function(e){var t=e.options,n=e.label,r=e.value,a=e.onChange,c=e.owner;return Object(o.jsxs)(x.a.Group,{controlId:"factories.FactorySelect",children:[Object(o.jsx)(x.a.Label,{children:n}),Object(o.jsx)("input",{name:"factory",list:"factories",autoComplete:"off",className:"form-control",value:r,onChange:a}),Object(o.jsx)("datalist",{id:"factories",children:t.map((function(e){return Object(o.jsx)("option",{value:e.factory.name,children:C(e,c)},C(e,c))}))})]})};var N=function(e){var t=e.association,n=e.owner;return Object(o.jsxs)(o.Fragment,{children:[Object(o.jsx)(x.a.Group,{controlId:"factories.OwnerType",children:Object(o.jsx)(x.a.Control,{type:"hidden",value:n&&n.type||"",name:"owner_type"})}),Object(o.jsx)(x.a.Group,{controlId:"factories.OwnerId",children:Object(o.jsx)(x.a.Control,{type:"hidden",value:n&&n.id||"",name:"owner_id"})}),Object(o.jsx)(x.a.Group,{controlId:"factories.OwnerReflection",children:Object(o.jsx)(x.a.Control,{type:"hidden",value:t||"",name:"owner_association"})})]})};var _=f.a.create({traits:{display:"flex",flexDirection:"column",flexWrap:"wrap",maxHeight:"6em"}}),L=function(e){var t=e.traits;return Object(o.jsxs)(x.a.Group,{controlId:"factories.Traits",children:[Object(o.jsx)(x.a.Label,{children:"How would you like that cooked?"}),Object(o.jsx)("div",{className:Object(f.b)(_.traits),children:t.map((function(t){return Object(o.jsx)(x.a.Check,{type:"checkbox",disabled:e.disabled,id:t.name,name:"traits[".concat(t.name),label:t.name},t.name)}))})]})};function M(){for(var e=arguments.length,t=new Array(e),n=0;n0&&Object(o.jsx)(L,{disabled:e.disabled,traits:h}),j.length>0&&Object(o.jsx)(k,{disabled:e.disabled,attributes:j}),Object(o.jsxs)("div",{className:Object(f.b)(T.buttons),children:[Object(o.jsx)(v.a,{variant:"outline-dark",className:"btn-primary",disabled:e.disabled||!O,type:"submit",children:"Gimme!"}),Object(o.jsx)(v.a,{variant:"outline-dark",className:"btn-danger",disabled:e.disabled,onClick:function(){p.current&&p.current.reset(),u(""),e.startOver()},type:"button",children:"Start Over"})," "]})]})},R=n(25);var F=function(e){var t=e.message||"Something went wrong";return Object(o.jsx)(R.a,{variant:"danger",children:t})};var P=function(){return Object(o.jsx)("svg",{width:"24px",height:"24px",viewBox:"0 0 24 24",style:"cursor:pointer",children:Object(o.jsxs)("g",{"stroke-width":"2.1",stroke:"#666",fill:"none","stroke-linecap":"round","stroke-linejoin":"round",children:[Object(o.jsx)("polyline",{points:"17 13.5 17 19.5 5 19.5 5 7.5 11 7.5"}),Object(o.jsx)("path",{d:"M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5"})]})})};var D=f.a.create({active:{boxShadow:"5px 5px 0px #333"},object:{border:"2px solid #222",borderRadius:"1em",display:"flex",flexDirection:"column",padding:"0.5em",marginRight:"0.5em",position:"relative",cursor:"pointer",transition:"background-color 0.2s"},objectDetails:{flex:1,width:"100%"},objectTitle:{flex:0,width:"100%",borderBottom:"2px solid #222",marginBottom:"3px"}}),G=function(e){var t=e.object,n=void 0===t?{}:t,r=n.attributes||{},a=function(e){var t=e.isNew,n=e.isActive;return t?"created":n?"selected":null}({isNew:e.new,isActive:e.active});return Object(o.jsxs)("div",{className:M(Object(f.b)(D.object,e.active&&D.active),a,"background-mayo hoverable"),onClick:e.activate,children:[Object(o.jsxs)("div",{className:Object(f.b)(D.objectTitle),children:[n.type,n.link&&Object(o.jsx)("a",{href:n.link.url,target:"_blank",rel:"noopener noreferrer",children:Object(o.jsx)(P,{})})]}),Object(o.jsx)("div",{className:Object(f.b)(D.objectDetails),children:["id","name"].map((function(e){return r.hasOwnProperty(e)&&Object(o.jsx)("div",{children:"".concat(e,": ").concat(r[e])},e)}))})]})};var B=function(){return Object(o.jsx)("div",{className:"under-construction",children:Object(o.jsx)(G,{object:{type:"building..."}})})};var E=f.a.create({form:{marginBottom:"2em",transition:"opacity 0.5s ease-out",overflow:"hidden"},objectList:{display:"flex",margin:"0.5em 0 1em"}}),q=function(e){var t,n=e.factories,a=Object(r.useState)(!1),c=Object(d.a)(a,2),i=c[0],s=c[1],u=Object(r.useState)(null),l=Object(d.a)(u,2),h=l[0],O=l[1],m=Object(r.useState)(!1),p=Object(d.a)(m,2),v=p[0],x=p[1],g=Object(r.useState)(null),y=Object(d.a)(g,2),w=y[0],k=y[1],C=Object(r.useState)([].concat([])),S=Object(d.a)(C,2),N=S[0],_=S[1],L=Object(r.useState)(null),M=Object(d.a)(L,2),T=M[0],R=M[1],P=n.map((function(e){return{factory:e}})),D=null!==T&&N.length>0&&N[T],q=Object(r.useMemo)((function(){return D&&D.association_factories?D.association_factories.map((function(e){return function(e,t){return{factory:e.find((function(e){return e.name===t.factory_name})),association:t.association_name}}(n,e)})):[]}),[D]),A=D?q:P,J=D?"Would you like fries with that ".concat(D.type,"?"):null;function V(){return(V=Object(j.a)(b.a.mark((function t(n){var r,a,c;return b.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.submitPath,t.next=3,fetch(r,{method:"POST",body:n});case 3:return a=t.sent,t.next=6,a.json();case 6:c=t.sent,a.ok?H(c):(console.error(JSON.stringify(c)),U(c.error||"Uh oh, something broke."));case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function H(e){e.ok?(console.log(JSON.stringify(e)),function(e){s(!1),O(null),x(!1),_(N.slice().concat([e])),0===N.length&&R(0);k(N.length)}(e.data)):(console.error(e.error),U(e.error||"Uh oh, something went wrong."))}function U(e){s(!1),O(e),x(!1)}return Object(o.jsxs)("div",{className:"container",children:[Object(o.jsx)("h2",{children:"Order Up!"}),(i||N.length>0)&&Object(o.jsxs)(o.Fragment,{children:[i?"Comin' right up!":"Here you go!",N.length>1&&Object(o.jsxs)("span",{children:[" ","P.S. -- select any object to build out its dependencies."]}),Object(o.jsxs)("div",{className:Object(f.b)(E.objectList),children:[N.map((function(e,t){return Object(o.jsx)(G,{object:e,active:T===t,activate:function(){return function(e){k(null),R(e)}(t)},new:w===t},t)})),i&&Object(o.jsx)(B,{})]})]}),h&&Object(o.jsx)(F,{message:h}),Object(o.jsx)("div",{className:Object(f.b)(E.form),children:Object(o.jsx)(I,{owner:D?(t=D,{type:t.type,id:t.attributes.id}):null,blueprints:A,disabled:v,handleSubmit:function(t){t.preventDefault(),s(!0),O(null),x(!0),function(e){V.apply(this,arguments)}(function(t){var n=new FormData(t);return n.append("authenticity_token",e.csrfToken),n}(t.target))},startOver:function(){k(null),k(null),_([]),R(null)},inquiry:J})})]})};function A(){return fetch("./data").then((function(e){return e.json()}))}var J=function(){var e=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=Object(r.useState)(null),a=Object(d.a)(n,2),c=a[0],i=a[1],o=Object(r.useState)(0===t.length),s=Object(d.a)(o,2),u=s[0],l=s[1],f=Object(r.useState)(null),h=Object(d.a)(f,2),O=h[0],m=h[1];function p(){return v.apply(this,arguments)}function v(){return(v=Object(j.a)(b.a.mark((function t(){return b.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e());case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function x(){l(!1)}return Object(r.useEffect)((function(){l(!0),p().then(m).catch(i).then(x)}),t),Object(r.useMemo)((function(){return{error:c,fetching:u,response:O}}),[c,u,O])}(A);return Object(r.useEffect)((function(){console.log(e)}),[e]),Object(o.jsxs)("div",{className:"App",children:[Object(o.jsx)("header",{children:Object(o.jsx)("div",{class:"header-text",children:"testing"})}),Object(o.jsxs)("main",{children:[e.fetching&&Object(o.jsx)(u,{}),e.error&&Object(o.jsx)(s,{}),e.response&&Object(o.jsx)(q,{csrfToken:"",submitPath:"./build",factories:e.response})]})]})},V=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,44)).then((function(t){var n=t.getCLS,r=t.getFID,a=t.getFCP,c=t.getLCP,i=t.getTTFB;n(e),r(e),a(e),c(e),i(e)}))};i.a.render(Object(o.jsx)(a.a.StrictMode,{children:Object(o.jsx)(J,{})}),document.getElementById("root")),V()}},[[42,1,2]]]); //# sourceMappingURL=main.b7479be0.chunk.js.map