{"version":3,"file":"components/Alert/change.mjs","sources":["../../../src/components/Alert/change.tsx"],"sourcesContent":["import { CheckOutlined, InfoCircleOutlined } from '@ant-design/icons';\nimport { SDK } from '@rsdoctor/types';\nimport {\n  Alert,\n  Button,\n  Col,\n  Divider,\n  Popconfirm,\n  Row,\n  Space,\n  Typography,\n} from 'antd';\nimport React, { useState } from 'react';\nimport { postServerAPI, useRuleIndexNavigate } from '../../utils';\nimport { DiffViewer } from '../base';\nimport { CodeOpener } from '../Opener';\nimport { TextDrawer } from '../TextDrawer';\nimport { Title } from '../Title';\nimport { CodeChangeAlertProps } from './types';\n\ninterface FixedProps {\n  setIsFixed(val: boolean): void;\n}\n\nconst CodeChangeDrawerContent: React.FC<CodeChangeAlertProps & FixedProps> = ({\n  data,\n  setIsFixed,\n  cwd,\n}) => {\n  const { file, id } = data;\n  const { path, line, isFixed, actual, expected } = file;\n  // const [isFixed, setIsFixed] = useState(file.isFixed ?? false);\n  const applyFix = async () => {\n    await postServerAPI(SDK.ServerAPI.API.ApplyErrorFix, { id: Number(id) });\n    setIsFixed(true);\n  };\n\n  const FixButton = () => {\n    return (\n      <Popconfirm\n        title={`Did you confirm to apply the change i the area below ?`}\n        onConfirm={applyFix}\n        okText=\"Yes\"\n        cancelText=\"Cancel\"\n        zIndex={99999}\n        disabled={isFixed}\n        placement=\"bottom\"\n      >\n        <Button\n          type=\"primary\"\n          size=\"small\"\n          icon={isFixed ? <CheckOutlined /> : undefined}\n          disabled={isFixed}\n        >\n          {isFixed ? 'Fix Applied' : 'Apply Fix'}\n        </Button>\n      </Popconfirm>\n    );\n  };\n\n  return (\n    <Space direction=\"vertical\" className=\"alert-space\">\n      <div>\n        <Title text={isFixed ? 'Fix History' : 'Suggest Fix'} />\n        <span className=\"code-change-tag-list\">\n          <FixButton />\n        </span>\n      </div>\n      <CodeOpener cwd={cwd} url={path} loc={String(line)} code disabled />\n      <Row>\n        <Col span={12}>\n          <Typography.Text strong>Before</Typography.Text>\n        </Col>\n        <Col span={12}>\n          <Typography.Text strong>After</Typography.Text>\n        </Col>\n      </Row>\n      <DiffViewer\n        className=\"full-space\"\n        originalFilePath={path}\n        modifiedFilePath={path}\n        original={actual}\n        modified={expected}\n      />\n    </Space>\n  );\n};\n\n///REVIEW - It's still useful? can't find usage\nexport const CodeChangeAlert: React.FC<CodeChangeAlertProps> = ({\n  data,\n  cwd,\n}) => {\n  const { title, description = '', level, code, file } = data;\n  const [isFixed, setIsFixed] = useState(file.isFixed ?? false);\n  const navigate = useRuleIndexNavigate(code, data.link);\n  const fixFile = (val: boolean) => {\n    setIsFixed(val);\n    file.isFixed = val;\n  };\n  const Description = (\n    <Space direction=\"vertical\">\n      <Typography.Text>{description}</Typography.Text>\n      <Space>\n        <Typography.Text>File:</Typography.Text>\n        <Typography.Text strong code>\n          {file.path}\n        </Typography.Text>\n        <Typography.Text>in line</Typography.Text>\n        <Typography.Text strong code>\n          {file.line}\n        </Typography.Text>\n      </Space>\n    </Space>\n  );\n\n  return (\n    <Alert\n      showIcon\n      message={\n        <Space>\n          <Typography.Text\n            code\n            strong\n            onClick={navigate}\n            style={{ cursor: 'pointer' }}\n          >\n            <a>{code}</a>\n          </Typography.Text>\n          <Typography.Text strong>{title}</Typography.Text>\n        </Space>\n      }\n      description={Description}\n      type={isFixed ? 'success' : level === 'warn' ? 'info' : level}\n      action={\n        <Space>\n          <TextDrawer\n            text={isFixed ? 'Fixed | Show Fix History' : 'Show Fix Suggestion'}\n            buttonProps={{ size: 'small' }}\n          >\n            <CodeChangeDrawerContent\n              data={data}\n              setIsFixed={fixFile}\n              cwd={cwd}\n            />\n          </TextDrawer>\n          <Divider type=\"vertical\" />\n          <Button type=\"link\" onClick={navigate} size=\"small\">\n            <InfoCircleOutlined />\n          </Button>\n        </Space>\n      }\n    />\n  );\n};\n"],"names":["CodeChangeDrawerContent","data","setIsFixed","cwd","file","id","path","line","isFixed","actual","expected","applyFix","postServerAPI","SDK","Number","FixButton","Popconfirm","Button","CheckOutlined","undefined","Space","Title","CodeOpener","String","Row","Col","Typography","DiffViewer","CodeChangeAlert","title","description","level","code","useState","navigate","useRuleIndexNavigate","fixFile","val","Description","Alert","TextDrawer","Divider","InfoCircleOutlined"],"mappings":";;;;;;;;;;AAwBA,MAAMA,0BAAuE,CAAC,EAC5EC,IAAI,EACJC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,IAAI,EAAEC,EAAE,EAAE,GAAGJ;IACrB,MAAM,EAAEK,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,EAAE,GAAGN;IAElD,MAAMO,WAAW;QACf,MAAMC,cAAcC,IAAI,SAAS,CAAC,GAAG,CAAC,aAAa,EAAE;YAAE,IAAIC,OAAOT;QAAI;QACtEH,WAAW;IACb;IAEA,MAAMa,YAAY,IACT,WAAP,GACE,IAACC,YAAUA;YACT,OAAO;YACP,WAAWL;YACX,QAAO;YACP,YAAW;YACX,QAAQ;YACR,UAAUH;YACV,WAAU;sBAEV,kBAACS,QAAMA;gBACL,MAAK;gBACL,MAAK;gBACL,MAAMT,UAAU,WAAVA,GAAU,IAACU,eAAaA,CAAAA,KAAMC;gBACpC,UAAUX;0BAETA,UAAU,gBAAgB;;;IAMnC,OAAO,WAAP,GACE,KAACY,OAAKA;QAAC,WAAU;QAAW,WAAU;;0BACpC,KAAC;;kCACC,IAACC,OAAKA;wBAAC,MAAMb,UAAU,gBAAgB;;kCACvC,IAAC;wBAAK,WAAU;kCACd,kBAACO,WAAAA,CAAAA;;;;0BAGL,IAACO,YAAUA;gBAAC,KAAKnB;gBAAK,KAAKG;gBAAM,KAAKiB,OAAOhB;gBAAO,MAAI;gBAAC,UAAQ;;0BACjE,KAACiB,KAAGA;;kCACF,IAACC,KAAGA;wBAAC,MAAM;kCACT,kBAACC,WAAW,IAAI;4BAAC,QAAM;sCAAC;;;kCAE1B,IAACD,KAAGA;wBAAC,MAAM;kCACT,kBAACC,WAAW,IAAI;4BAAC,QAAM;sCAAC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