/* PC Liquors — Admin portal: shared icons, mock data, mini-charts.
   Exported to window for the view + shell babel scripts. */

/* ---------- icons (Lucide-style) ---------- */
const A = (p) => <svg width={p.s||18} height={p.s||18} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={p.w||1.8} strokeLinecap="round" strokeLinejoin="round" style={p.style}>{p.children}</svg>;
const Icons = {
  dash:(p)=><A {...p}><path d="M3 13h8V3H3zM13 21h8V3h-8zM3 21h8v-6H3z"/></A>,
  box:(p)=><A {...p}><path d="M21 8l-9-5-9 5 9 5 9-5zM3 8v8l9 5 9-5V8M12 13v8"/></A>,
  users:(p)=><A {...p}><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2M9 11a4 4 0 100-8 4 4 0 000 8zM23 21v-2a4 4 0 00-3-3.9M16 3.1a4 4 0 010 7.8"/></A>,
  receipt:(p)=><A {...p}><path d="M5 2v20l3-2 3 2 3-2 3 2V2l-3 2-3-2-3 2-3-2zM9 8h6M9 12h6"/></A>,
  folder:(p)=><A {...p}><path d="M3 7a2 2 0 012-2h4l2 3h8a2 2 0 012 2v7a2 2 0 01-2 2H5a2 2 0 01-2-2z"/></A>,
  tag:(p)=><A {...p}><path d="M20.6 13.4L13.4 20.6a2 2 0 01-2.8 0l-8-8V3h9.6l8.4 8.4a2 2 0 010 2zM7 7h.01"/></A>,
  settings:(p)=><A {...p}><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.6 1.6 0 00.3 1.8l.1.1a2 2 0 11-2.8 2.8l-.1-.1a1.6 1.6 0 00-2.7.6 1.6 1.6 0 01-3.2 0 1.6 1.6 0 00-2.7-.6l-.1.1a2 2 0 11-2.8-2.8l.1-.1a1.6 1.6 0 00-.6-2.7 1.6 1.6 0 010-3.2 1.6 1.6 0 00.6-2.7l-.1-.1a2 2 0 112.8-2.8l.1.1a1.6 1.6 0 001.8.3H9a1.6 1.6 0 001-1.5 1.6 1.6 0 013.2 0 1.6 1.6 0 001 1.5 1.6 1.6 0 001.8-.3l.1-.1a2 2 0 112.8 2.8l-.1.1a1.6 1.6 0 00-.3 1.8V9a1.6 1.6 0 001.5 1 1.6 1.6 0 010 3.2 1.6 1.6 0 00-1.5 1z"/></A>,
  logout:(p)=><A {...p}><path d="M9 21H5a2 2 0 01-2-2V5a2 2 0 012-2h4M16 17l5-5-5-5M21 12H9"/></A>,
  plus:(p)=><A {...p}><path d="M12 5v14M5 12h14"/></A>,
  search:(p)=><A {...p}><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></A>,
  cal:(p)=><A {...p}><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></A>,
  up:(p)=><A {...p}><path d="M23 6l-9.5 9.5-5-5L1 18M17 6h6v6"/></A>,
  down:(p)=><A {...p}><path d="M23 18l-9.5-9.5-5 5L1 6M17 18h6v-6"/></A>,
  dollar:(p)=><A {...p}><path d="M12 1v22M17 5H9.5a3.5 3.5 0 000 7h5a3.5 3.5 0 010 7H6"/></A>,
  card:(p)=><A {...p}><rect x="1" y="4" width="22" height="16" rx="2"/><path d="M1 10h22"/></A>,
  mail:(p)=><A {...p}><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M22 6l-10 7L2 6"/></A>,
  bank:(p)=><A {...p}><path d="M3 21h18M3 10h18M5 6l7-3 7 3M4 10v11M20 10v11M8 14v3M12 14v3M16 14v3"/></A>,
  edit:(p)=><A {...p}><path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7M18.5 2.5a2.1 2.1 0 013 3L12 15l-4 1 1-4z"/></A>,
  trash:(p)=><A {...p}><path d="M3 6h18M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2m2 0v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6"/></A>,
  download:(p)=><A {...p}><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4M7 10l5 5 5-5M12 15V3"/></A>,
  bell:(p)=><A {...p}><path d="M18 8a6 6 0 00-12 0c0 7-3 9-3 9h18s-3-2-3-9M13.7 21a2 2 0 01-3.4 0"/></A>,
  sync:(p)=><A {...p}><path d="M23 4v6h-6M1 20v-6h6M3.5 9a9 9 0 0114.9-3.4L23 10M1 14l4.6 4.4A9 9 0 0020.5 15"/></A>,
  check:(p)=><A {...p}><path d="M20 6L9 17l-5-5"/></A>,
  doc:(p)=><A {...p}><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8zM14 2v6h6"/></A>,
  google:(p)=><svg width={p.s||18} height={p.s||18} viewBox="0 0 24 24"><path fill="#4285F4" d="M22.5 12.3c0-.8-.1-1.6-.2-2.3H12v4.5h5.9a5 5 0 01-2.2 3.3v2.7h3.6c2.1-2 3.2-4.9 3.2-8.2z"/><path fill="#34A853" d="M12 23c2.9 0 5.4-1 7.2-2.6l-3.6-2.7c-1 .7-2.2 1-3.6 1-2.8 0-5.1-1.9-6-4.4H2.3v2.8A11 11 0 0012 23z"/><path fill="#FBBC05" d="M6 14.3a6.6 6.6 0 010-4.2V7.3H2.3a11 11 0 000 9.8z"/><path fill="#EA4335" d="M12 5.4c1.6 0 3 .5 4.1 1.6l3.1-3.1A11 11 0 002.3 7.3L6 10.1c.9-2.6 3.2-4.5 6-4.5z"/></svg>,
};

/* ---------- mock data ---------- */
const SALES_14 = [3120,2890,3340,4010,3760,5210,6040,3480,3110,3920,4280,0,0,0]; // last 3 are prediction
const PRED_14 = [0,0,0,0,0,0,0,0,0,0,4280,4520,4980,6300];
const DAYS_14 = ["Jun 17","18","19","20","21","22","23","24","25","26","27","28","29","30"];

const TOP_PRODUCTS = [
  { name:"Buffalo Trace 750ml", sku:"BT-750-001", units:42, revenue:"1,217.58" },
  { name:"Tito's Vodka 1L", sku:"TV-1000-008", units:38, revenue:"1,063.62" },
  { name:"Josh Cabernet", sku:"JC-750-021", units:31, revenue:"433.69" },
  { name:"Corona 12pk", sku:"CR-12-114", units:29, revenue:"492.71" },
  { name:"Hennessy VS 750ml", sku:"HN-750-003", units:24, revenue:"1,079.76" },
];

const INVENTORY = [
  { name:"Buffalo Trace", sku:"BT-750-001", cat:"Whiskey", price:"28.99", stock:48, status:"In stock" },
  { name:"Macallan 12 Double Cask", sku:"MC-750-002", cat:"Whiskey", price:"74.99", stock:6, status:"Low" },
  { name:"Hennessy VS", sku:"HN-750-003", cat:"Cognac", price:"44.99", stock:22, status:"In stock" },
  { name:"Grey Goose 750ml", sku:"GG-750-004", cat:"Vodka", price:"34.49", stock:0, status:"Out" },
  { name:"Caymus Cabernet 2021", sku:"CY-750-005", cat:"Wine", price:"89.00", stock:14, status:"In stock" },
  { name:"Don Julio 1942", sku:"DJ-750-006", cat:"Tequila", price:"159.99", stock:3, status:"Low" },
  { name:"Hendrick's Gin", sku:"HG-750-007", cat:"Gin", price:"36.99", stock:19, status:"In stock" },
  { name:"Tito's Handmade 1L", sku:"TV-1000-008", cat:"Vodka", price:"27.99", stock:61, status:"In stock" },
];

const EMPLOYEES = [
  { name:"Marcus Reed", email:"marcus@pcliquors.com", role:"Store Manager", hours:168, rate:"26.00" },
  { name:"Elena Vargas", email:"elena@pcliquors.com", role:"Sales Associate", hours:152, rate:"19.50" },
  { name:"Devon Clarke", email:"devon@pcliquors.com", role:"Stock & Delivery", hours:140, rate:"18.00" },
  { name:"Aisha Khan", email:"aisha@pcliquors.com", role:"Cashier", hours:96, rate:"17.25" },
];

const EXPENSES = [
  { date:"Jun 28", desc:"Southern Glazer's — restock", channel:"Bank ACH", type:"out", amount:"4,820.00", src:"bank" },
  { date:"Jun 28", desc:"Clover POS — daily sales", channel:"Clover deposit", type:"in", amount:"4,280.00", src:"pos" },
  { date:"Jun 27", desc:"Con Edison — electricity", channel:"Credit card", type:"out", amount:"612.40", src:"card" },
  { date:"Jun 27", desc:"Clover POS — daily sales", channel:"Clover deposit", type:"in", amount:"3,920.00", src:"pos" },
  { date:"Jun 26", desc:"Republic National — wine order", channel:"Invoice (email)", type:"out", amount:"2,140.75", src:"mail" },
  { date:"Jun 26", desc:"Square — delivery payouts", channel:"Bank ACH", type:"in", amount:"880.00", src:"bank" },
  { date:"Jun 25", desc:"NYC SLA — license renewal", channel:"Credit card", type:"out", amount:"360.00", src:"card" },
];

const DOCS = [
  { folder:"Licenses & Permits", count:6, items:["NY Liquor License 2026.pdf","Cigarette License.pdf","Cert. of Authority.pdf"], tone:"gold" },
  { folder:"Tax & EIN", count:9, items:["EIN Letter (CP-575).pdf","2025 Form 1120.pdf","Sales Tax ST-100 Q1.pdf"], tone:"green" },
  { folder:"Insurance", count:4, items:["Liquor Liability Policy.pdf","Property & GL.pdf"], tone:"wine" },
  { folder:"Lease & Property", count:5, items:["Storefront Lease 2024.pdf","Cert. of Occupancy.pdf"], tone:"info" },
  { folder:"Vendor Contracts", count:12, items:["Southern Glazer's Terms.pdf","Republic National MSA.pdf"], tone:"gold" },
  { folder:"Payroll & HR", count:8, items:["W-9 — Marcus Reed.pdf","Employee Handbook.pdf"], tone:"green" },
];

/* ---------- mini sales chart (past bars + prediction) ---------- */
function SalesChart() {
  const all = SALES_14.map((v,i)=> v || PRED_14[i]);
  const max = Math.max(...all);
  const W = 720, H = 240, pad = 28, n = all.length;
  const bw = (W - pad*2) / n;
  return (
    <svg viewBox={`0 0 ${W} ${H}`} className="achart" preserveAspectRatio="none">
      {[0.25,0.5,0.75,1].map((g,i)=>(
        <line key={i} x1={pad} x2={W-pad} y1={pad + (H-pad*2)*(1-g)} y2={pad + (H-pad*2)*(1-g)} stroke="var(--border-subtle)" strokeWidth="1" strokeDasharray="2 4"/>
      ))}
      {all.map((v,i)=>{
        const h = (v/max)*(H-pad*2);
        const x = pad + i*bw + bw*0.18;
        const w = bw*0.64;
        const y = H-pad-h;
        const pred = !SALES_14[i];
        return <rect key={i} x={x} y={y} width={w} height={h} rx="3"
          fill={pred ? "transparent" : "var(--gold-500)"} stroke={pred ? "var(--gold-500)" : "none"}
          strokeDasharray={pred ? "3 3" : "0"} strokeWidth={pred?1.4:0} opacity={pred?0.85:1}/>;
      })}
      {DAYS_14.map((d,i)=> i%2===0 ? (
        <text key={i} x={pad + i*bw + bw/2} y={H-8} textAnchor="middle" fontSize="10" fontFamily="var(--font-mono)" fill="var(--text-subtle)">{d}</text>
      ) : null)}
    </svg>
  );
}

window.PCAdmin = { Icons, SALES_14, PRED_14, DAYS_14, TOP_PRODUCTS, INVENTORY, EMPLOYEES, EXPENSES, DOCS, SalesChart };
