"use strict";var e=require("react"),n=require("prop-types"),t=require("lodash"),i=require("@material-ui/core"),l=require("./constants.js"),r=require("../../../utils/index.js"),a=require("react/jsx-runtime");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=s(n),c=i.makeStyles({header:{marginBottom:"10px",borderBottom:"1px solid #888"},title:{fontWeight:"bold",fontSize:"2rem",marginTop:"0px"},done_button:{float:"right"},field_label:{color:"#ccc",fontSize:"0.8rem"},field_value:{fontSize:"1.2rem",lineHeight:"2rem",fontWeight:"bold"},thead:{borderBottom:"0px"},th:{color:"#ccc",fontSize:"0.8rem",padding:"0px"},td:{fontSize:"1.2rem",padding:"0px"},col:{padding:"0 0.75rem"},row:{marginBottom:"20px"},sub_title:{fontWeight:"bold",fontSize:"1.5rem",marginTop:"10px",padding:"0 0.75rem"}});function d(e){var n=e.component,s=e.onDone,o=e.currentUser,d=c(),u=n&&t.get(n,"family"),m=o?t.get(o,["preference","segment"],[]):[],f=o&&t.get(o,"current_segment"),_=-1===m.indexOf(f)?m[0]:f,g=l.BHA_COMPONENT_TYPES.filter((function(e){return e.family===u})),h=g&&g[0],p=h&&h.data,x=function(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,c=arguments.length>3?arguments[3]:void 0,u=arguments.length>4&&void 0!==arguments[4]&&arguments[4],m=t.get(n,e)||"",f=u?l.FLOW_RATE_UNIT[_].unitType:c,g=f?"(".concat(r.getUnitDisplay(f),")"):"";return a.jsxs(i.Grid,{item:!0,md:o,xs:12,className:d.col,children:[a.jsx("span",{className:d.field_label,children:"".concat(s," ").concat(g)}),a.jsx("br",{}),a.jsx("span",{className:d.field_value,children:m.fixFloat?m.fixFloat(3):m||"n/a"})]},s)},b=function(e,i){return i?t.map(l.BHA_GENERAL_FIELD_TYPES,(function(l){return t.includes(i,l.name)&&(!l.cond||l.cond&&t.get(n,l.cond,!1))&&(!l.family||l.family===u)&&(l.unit?x([l.name],l.label,l.col_size||e,l.unit):x([l.name],l.label,l.col_size||e))})):null},j=function(e){return e?a.jsx(i.Grid,{item:!0,xs:12,className:d.sub_title,children:e},"subTitle"):null},N=function(e,l,r){return a.jsx(i.Grid,{item:!0,xs:12,className:d.col,children:t.get(n,e,[]).length>0&&a.jsxs("table",{children:[a.jsx("thead",{className:d.thead,children:a.jsx("tr",{children:t.map(l,(function(e,n){return a.jsx("th",{className:d.th,children:e},n)}))})}),a.jsx("tbody",{children:t.map(t.get(n,e,[]),(function(e,n){return a.jsx("tr",{children:t.map(r,(function(n,i){return a.jsx("td",{className:d.td,children:n.isNumber?t.get(e,n.field)&&t.get(e,n.field).fixFloat(3):t.get(e,n.field)},i)}))},n)}))})]})},"tbField")},T=function(e,r,s,o,c){return r?a.jsxs(i.Grid,{container:!0,children:[s&&t.map(l.BHA_TABLE_FIELD_TYPES,(function(i){return t.includes(s,i.name)&&(!i.cond||i.cond&&t.get(n,i.cond,!1))&&(i.unit||i.unit_from_segment?x([i.name],i.label,i.col_size||e,i.unit,i.unit_from_segment):x([i.name],i.label,i.col_size||e))})),a.jsxs(i.Grid,{item:!0,md:4,xs:12,className:d.col,children:[a.jsx("span",{className:d.field_label,children:"Activation Logic"}),a.jsx("br",{}),a.jsx("span",{className:d.field_value,children:(u=o,(l.UR_ACTIVATION_LOGIC_TYPES.find((function(e){return e.type===u}))||{}).name||"n/a")})]}),c&&t.includes(s,"ur_opened_depth")&&x(["ur_opened_depth"],"Activation Depth",e,"length")]},r):null;var u},y=function(e,i){return i?t.map(l.BHA_ALTERNATIVE_FIELD_TYPES,(function(l){return t.includes(i,l.name)&&(!l.cond||l.cond&&t.get(n,l.cond,!1))&&(!l.family||l.family===u)&&(l.unit?x([l.name],l.label,l.col_size||e,l.unit):x([l.name],l.label,l.col_size||e))})):null},E=function(e,i){return i&&t.get(n,"has_stabilizer")?t.map(l.BHA_STABILIZER_FIELD_TYPES,(function(l){return t.includes(i,l.name)&&(!l.cond||l.cond&&t.get(n,l.cond,!1))&&(!l.family||l.family===u)&&(l.unit?x(["stabilizer",l.name],l.label,l.col_size||e,l.unit):x(["stabilizer",l.name],l.label,l.col_size||e))})):null};return a.jsxs("div",{children:[a.jsxs("header",{className:d.header,children:[a.jsx(i.Button,{variant:"contained",className:d.done_button,onClick:s,children:"Close"}),a.jsxs("h4",{className:d.title,children:[t.get(n,"name")," ( ",t.get(n,"family")," )"]})]}),a.jsx(i.Grid,{container:!0,children:a.jsx(i.Grid,{item:!0,xs:12,className:d.col,children:t.map(p,(function(e){return function(e){var r=e&&+t.get(e,"col_size"),s=e&&t.get(e,"fields"),o=e&&t.get(e,"stablizer_fields"),c=e&&t.get(e,"sub_title"),u=e&&t.get(e,"sub_key"),m=e&&t.get(e,"sub_fields"),f=e&&t.get(e,"tb_field"),_=e&&t.get(e,"tb_head"),g=e&&t.get(e,"tb_body"),h=t.get(n,"activation_logic"),p=h===l.UR_ACTIVATION_LOGIC_KEYS.DEPTH_ACTIVATION;return a.jsxs(i.Grid,{container:!0,className:d.row,children:[b(r,s),j(c),N(f,_,g),T(r,u,m,h,p),y(r,s),E(r,o)]},e.key)}(e)}))})})]})}d.propTypes={component:o.default.shape({}).isRequired,onDone:o.default.func.isRequired,currentUser:o.default.shape({}).isRequired};var u=e.memo(d);module.exports=u;
